1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

fix: Values in fields lookup (#407)

This commit is contained in:
Edwin Betancourt 2020-03-16 19:08:25 -04:00 committed by GitHub
parent b45740e3a3
commit 9dbf57a877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 36 deletions

View File

@ -49,7 +49,7 @@ export default {
label: ' ',
key: undefined
}],
blanckOption: {
blankOption: {
// label with '' value is assumed to be undefined non-existent
label: ' ',
key: undefined || -1
@ -75,7 +75,7 @@ export default {
},
getterLookupItem() {
if (this.isEmptyValue(this.metadata.reference.directQuery)) {
return this.blanckOption
return this.blankOption
}
return this.$store.getters.getLookupItem({
parentUuid: this.metadata.parentUuid,
@ -87,7 +87,7 @@ export default {
},
getterLookupList() {
if (this.isEmptyValue(this.metadata.reference.query)) {
return this.blanckOption
return this.blankOption
}
return this.$store.getters.getLookupList({
parentUuid: this.metadata.parentUuid,
@ -105,10 +105,18 @@ export default {
tableName: this.metadata.reference.tableName,
value: this.value
})
if (allOptions && ((allOptions.length && allOptions[0].key !== this.blanckOption.key) || !allOptions.length)) {
allOptions.unshift(this.blanckOption)
if (this.isEmptyValue(allOptions) || !this.blankOptionInfo.hasBlankOption) {
allOptions.unshift(this.blankOption)
}
return allOptions
},
blankOptionInfo() {
return {
hasBlankOption: this.options.some(option => option.label === ' '),
index: this.options.findIndex(option => option.label === ' '),
option: this.options.find(option => option.label === ' ')
}
}
},
watch: {
@ -140,15 +148,20 @@ export default {
value = value ? 'Y' : 'N'
}
if (this.metadata.displayed) {
if (!this.options.some(option => option.key === value)) {
const label = this.findLabel(value)
if (!this.options.some(option => option.key === value) &&
!this.isEmptyValue(this.metadata.displayColumn)) {
this.options.push({
key: value,
label: this.isEmptyValue(label) ? ' ' : label
label: this.metadata.displayColumn
})
this.value = value
}
}
if (!this.findLabel(value) &&
this.metadata.displayed &&
this.metadata.optionCRUD !== 'create-new' &&
this.isEmptyValue(this.metadata.displayColumn)) {
value = undefined
}
this.value = value
}
},
@ -226,7 +239,7 @@ export default {
}
this.options = this.getterLookupAll
if (this.options.length && !this.options[0].key) {
this.options.unshift(this.blanckOption)
this.options.unshift(this.blankOption)
}
})
.finally(() => {
@ -238,7 +251,7 @@ export default {
*/
getDataLookupList(isShowList) {
if (isShowList) {
// TODO: Evaluate if length = 1 and this element key = blanckOption
// TODO: Evaluate if length = 1 and this element key = blankOption
if (this.getterLookupList.length === 0) {
this.remoteMethod()
}
@ -273,7 +286,7 @@ export default {
})
// TODO: Evaluate if is number -1 or string '' (or default value)
this.options = this.getterLookupAll
this.value = this.blanckOption.key
this.value = this.blankOption.key
}
}
}

View File

@ -108,8 +108,8 @@ export default {
},
documentActionChange(value) {
this.$store.dispatch('notifyFieldChange', {
parentUuid: this.parentUuid,
containerUuid: this.containerUuid,
parentUuid: this.field.parentUuid,
containerUuid: this.field.containerUuid,
columnName: 'DocAction',
isSendToServer: true,
newValue: value
@ -126,13 +126,13 @@ export default {
recordId: this.$route.params.recordId,
recordUuid: this.$route.query.action,
parametersList: [{
columnName: 'DocStatus',
columnName: this.field.columnName,
value: this.valueActionDocument
}],
isActionDocument: true,
parentUuid: this.parentUuid,
panelType: this.panelType,
containerUuid: this.containerUuid// determinate if get table name and record id (window) or selection (browser)
parentUuid: this.field.parentUuid,
panelType: this.field.panelType,
containerUuid: this.field.containerUuid // determinate if get table name and record id (window) or selection (browser)
})
this.valueActionDocument = ''
}

View File

@ -363,19 +363,22 @@ export default {
fieldItem.value = parsedValueComponent({
fieldType: fieldItem.componentPath,
value: route.query[fieldItem.columnName],
referenceType: fieldItem.referenceType
referenceType: fieldItem.referenceType,
isIdentifier: fieldItem.columnName.includes('_ID')
})
if (String(route.query.isAdvancedQuery) === String(fieldItem.isAdvancedQuery)) {
fieldItem.value = parsedValueComponent({
fieldType: fieldItem.componentPath,
value: route.query[fieldItem.columnName],
referenceType: fieldItem.referenceType
referenceType: fieldItem.referenceType,
isIdentifier: fieldItem.columnName.includes('_ID')
})
if (fieldItem.isRange && this.$route.query[`${fieldItem.columnName}_To`]) {
fieldItem.valueTo = parsedValueComponent({
fieldType: fieldItem.componentPath,
value: route.query[`${fieldItem.columnName}_To`],
referenceType: fieldItem.referenceType
referenceType: fieldItem.referenceType,
isIdentifier: fieldItem.columnName.includes('_ID')
})
}
}
@ -428,12 +431,14 @@ export default {
if (route.query.action === 'advancedQuery' && fieldItem.isAdvancedQuery) {
this.dataRecords[fieldItem.columnName] = parsedValueComponent({
fieldType: fieldItem.componentPath,
value: route.query[fieldItem.columnName]
value: route.query[fieldItem.columnName],
isIdentifier: fieldItem.columnName.includes('_ID')
})
if (fieldItem.isRange && route.query[`${fieldItem.columnName}_To`]) {
this.dataRecords[fieldItem.columnName] = parsedValueComponent({
fieldType: fieldItem.componentPath,
value: route.query[`${fieldItem.columnName}_To`]
value: route.query[`${fieldItem.columnName}_To`],
isIdentifier: fieldItem.columnName.includes('_ID')
})
}
}

View File

@ -323,11 +323,13 @@ const panel = {
type: 'info'
})
panel.fieldList.forEach(fieldToBlanck => {
commit('changeFieldValueToNull', {
field: fieldToBlanck,
value: undefined
})
panel.fieldList.forEach(fieldToBlank => {
if (isEmptyValue(fieldToBlank.parsedDefaultValue)) {
commit('changeFieldValueToNull', {
field: fieldToBlank,
value: undefined
})
}
})
if (panel.isTabsChildren) {
@ -511,13 +513,15 @@ const panel = {
newValue = parsedValueComponent({
fieldType: field.componentPath,
referenceType: field.referenceType,
value: newValue
value: newValue,
isIdentifier: field.columnName.includes('_ID')
})
if (field.isRange) {
valueTo = parsedValueComponent({
fieldType: field.componentPath,
referenceType: field.referenceType,
value: valueTo
value: valueTo,
isIdentifier: field.columnName.includes('_ID')
})
}
}
@ -1170,7 +1174,8 @@ const panel = {
fieldType: fieldItem.componentPath,
referenceType: fieldItem.referenceType,
isMandatory: fieldItem.isMandatory,
value: String(valueToReturn) === '[object Object]' && valueToReturn.isSQL ? valueToReturn : String(valueToReturn) === '[object Object]' ? valueToReturn.value : valueToReturn
value: String(valueToReturn) === '[object Object]' && valueToReturn.isSQL ? valueToReturn : String(valueToReturn) === '[object Object]' ? valueToReturn.value : valueToReturn,
isIdentifier: fieldItem.columnName.includes('_ID')
})
attributesObject[fieldItem.columnName] = valueToReturn
@ -1336,7 +1341,8 @@ const panel = {
fieldType: parameterItem.componentPath,
value: itemValue,
referenceType: parameterItem.referenceType,
isMandatory
isMandatory,
isIdentifier: parameterItem.columnName.includes('_ID')
})
})
} else {

View File

@ -75,7 +75,8 @@ export function generateField({
fieldType: componentReference.type,
value: parsedDefaultValue,
referenceType,
isMandatory: fieldToGenerate.isMandatory
isMandatory: fieldToGenerate.isMandatory,
isIdentifier: fieldToGenerate.columnName.includes('_ID')
})
if (String(fieldToGenerate.defaultValue).includes('@SQL=')) {
@ -117,7 +118,8 @@ export function generateField({
fieldType: componentReference.type,
value: parsedDefaultValueTo,
referenceType,
isMandatory: fieldToGenerate.isMandatory
isMandatory: fieldToGenerate.isMandatory,
isIdentifier: fieldToGenerate.columnName.includes('_ID')
})
parentFieldsList = getParentFields(fieldToGenerate)

View File

@ -245,8 +245,15 @@ export const recursiveTreeSearch = ({
* @param {string} fieldType, or componentPath
* @param {string} referenceType, reference in ADempiere
* @param {boolean} isMandatory, field is mandatory
* @param {boolean} isIdentifier, field is ID
*/
export function parsedValueComponent({ fieldType, value, referenceType, isMandatory = false }) {
export function parsedValueComponent({
fieldType,
value,
referenceType,
isMandatory = false,
isIdentifier = false
}) {
if ((value === undefined || value === null) && !isMandatory) {
if (fieldType === 'FieldYesNo') {
return Boolean(value)
@ -318,7 +325,7 @@ export function parsedValueComponent({ fieldType, value, referenceType, isMandat
if (typeof value === 'boolean') {
value = value ? 'Y' : 'N'
}
if (referenceType === 'TableDirect') {
if (referenceType === 'TableDirect' || (referenceType === 'Table' && isIdentifier)) {
if (value !== '' && value !== null && value !== undefined) {
value = Number(value)
}