1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-13 23:20:12 +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: ' ', label: ' ',
key: undefined key: undefined
}], }],
blanckOption: { blankOption: {
// label with '' value is assumed to be undefined non-existent // label with '' value is assumed to be undefined non-existent
label: ' ', label: ' ',
key: undefined || -1 key: undefined || -1
@ -75,7 +75,7 @@ export default {
}, },
getterLookupItem() { getterLookupItem() {
if (this.isEmptyValue(this.metadata.reference.directQuery)) { if (this.isEmptyValue(this.metadata.reference.directQuery)) {
return this.blanckOption return this.blankOption
} }
return this.$store.getters.getLookupItem({ return this.$store.getters.getLookupItem({
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
@ -87,7 +87,7 @@ export default {
}, },
getterLookupList() { getterLookupList() {
if (this.isEmptyValue(this.metadata.reference.query)) { if (this.isEmptyValue(this.metadata.reference.query)) {
return this.blanckOption return this.blankOption
} }
return this.$store.getters.getLookupList({ return this.$store.getters.getLookupList({
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
@ -105,10 +105,18 @@ export default {
tableName: this.metadata.reference.tableName, tableName: this.metadata.reference.tableName,
value: this.value 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 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: { watch: {
@ -140,15 +148,20 @@ export default {
value = value ? 'Y' : 'N' value = value ? 'Y' : 'N'
} }
if (this.metadata.displayed) { if (this.metadata.displayed) {
if (!this.options.some(option => option.key === value)) { if (!this.options.some(option => option.key === value) &&
const label = this.findLabel(value) !this.isEmptyValue(this.metadata.displayColumn)) {
this.options.push({ this.options.push({
key: value, 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 this.value = value
} }
}, },
@ -226,7 +239,7 @@ export default {
} }
this.options = this.getterLookupAll this.options = this.getterLookupAll
if (this.options.length && !this.options[0].key) { if (this.options.length && !this.options[0].key) {
this.options.unshift(this.blanckOption) this.options.unshift(this.blankOption)
} }
}) })
.finally(() => { .finally(() => {
@ -238,7 +251,7 @@ export default {
*/ */
getDataLookupList(isShowList) { getDataLookupList(isShowList) {
if (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) { if (this.getterLookupList.length === 0) {
this.remoteMethod() this.remoteMethod()
} }
@ -273,7 +286,7 @@ export default {
}) })
// TODO: Evaluate if is number -1 or string '' (or default value) // TODO: Evaluate if is number -1 or string '' (or default value)
this.options = this.getterLookupAll this.options = this.getterLookupAll
this.value = this.blanckOption.key this.value = this.blankOption.key
} }
} }
} }

View File

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

View File

@ -363,19 +363,22 @@ export default {
fieldItem.value = parsedValueComponent({ fieldItem.value = parsedValueComponent({
fieldType: fieldItem.componentPath, fieldType: fieldItem.componentPath,
value: route.query[fieldItem.columnName], value: route.query[fieldItem.columnName],
referenceType: fieldItem.referenceType referenceType: fieldItem.referenceType,
isIdentifier: fieldItem.columnName.includes('_ID')
}) })
if (String(route.query.isAdvancedQuery) === String(fieldItem.isAdvancedQuery)) { if (String(route.query.isAdvancedQuery) === String(fieldItem.isAdvancedQuery)) {
fieldItem.value = parsedValueComponent({ fieldItem.value = parsedValueComponent({
fieldType: fieldItem.componentPath, fieldType: fieldItem.componentPath,
value: route.query[fieldItem.columnName], 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`]) { if (fieldItem.isRange && this.$route.query[`${fieldItem.columnName}_To`]) {
fieldItem.valueTo = parsedValueComponent({ fieldItem.valueTo = parsedValueComponent({
fieldType: fieldItem.componentPath, fieldType: fieldItem.componentPath,
value: route.query[`${fieldItem.columnName}_To`], 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) { if (route.query.action === 'advancedQuery' && fieldItem.isAdvancedQuery) {
this.dataRecords[fieldItem.columnName] = parsedValueComponent({ this.dataRecords[fieldItem.columnName] = parsedValueComponent({
fieldType: fieldItem.componentPath, 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`]) { if (fieldItem.isRange && route.query[`${fieldItem.columnName}_To`]) {
this.dataRecords[fieldItem.columnName] = parsedValueComponent({ this.dataRecords[fieldItem.columnName] = parsedValueComponent({
fieldType: fieldItem.componentPath, 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' type: 'info'
}) })
panel.fieldList.forEach(fieldToBlanck => { panel.fieldList.forEach(fieldToBlank => {
commit('changeFieldValueToNull', { if (isEmptyValue(fieldToBlank.parsedDefaultValue)) {
field: fieldToBlanck, commit('changeFieldValueToNull', {
value: undefined field: fieldToBlank,
}) value: undefined
})
}
}) })
if (panel.isTabsChildren) { if (panel.isTabsChildren) {
@ -511,13 +513,15 @@ const panel = {
newValue = parsedValueComponent({ newValue = parsedValueComponent({
fieldType: field.componentPath, fieldType: field.componentPath,
referenceType: field.referenceType, referenceType: field.referenceType,
value: newValue value: newValue,
isIdentifier: field.columnName.includes('_ID')
}) })
if (field.isRange) { if (field.isRange) {
valueTo = parsedValueComponent({ valueTo = parsedValueComponent({
fieldType: field.componentPath, fieldType: field.componentPath,
referenceType: field.referenceType, referenceType: field.referenceType,
value: valueTo value: valueTo,
isIdentifier: field.columnName.includes('_ID')
}) })
} }
} }
@ -1170,7 +1174,8 @@ const panel = {
fieldType: fieldItem.componentPath, fieldType: fieldItem.componentPath,
referenceType: fieldItem.referenceType, referenceType: fieldItem.referenceType,
isMandatory: fieldItem.isMandatory, 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 attributesObject[fieldItem.columnName] = valueToReturn
@ -1336,7 +1341,8 @@ const panel = {
fieldType: parameterItem.componentPath, fieldType: parameterItem.componentPath,
value: itemValue, value: itemValue,
referenceType: parameterItem.referenceType, referenceType: parameterItem.referenceType,
isMandatory isMandatory,
isIdentifier: parameterItem.columnName.includes('_ID')
}) })
}) })
} else { } else {

View File

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

View File

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