1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-11 22:08:05 +08:00

fix: #172 Reload a window with a record, loses the display column. (#173)

This commit is contained in:
EdwinBetanc0urt 2019-11-22 12:01:15 -04:00 committed by Yamel Senih
parent 553b07c2bd
commit 7b0354fa34
2 changed files with 63 additions and 102 deletions

View File

@ -30,32 +30,21 @@ export default {
mixins: [fieldMixin], mixins: [fieldMixin],
data() { data() {
return { return {
value: this.metadata.displayColumn,
isLoading: false, isLoading: false,
baseNumber: 10,
options: [{ options: [{
label: ' ', label: ' ',
key: undefined key: undefined
}], }],
othersOptions: [],
blanckOption: { blanckOption: {
label: ' ', label: ' ',
key: undefined key: undefined
}, }
blancksValues: [null, -1, '', undefined]
} }
}, },
computed: { computed: {
isPanelWindow() { isPanelWindow() {
return this.metadata.panelType === 'window' return this.metadata.panelType === 'window'
}, },
getterValueSelec() {
var field = this.$store.getters.getFieldFromColumnName(this.metadata.containerUuid, this.metadata.columnName)
if (field) {
return this.validateValue(field.displayColumn)
}
return undefined
},
isMobile() { isMobile() {
return this.$store.state.app.device === 'mobile' return this.$store.state.app.device === 'mobile'
}, },
@ -65,7 +54,7 @@ export default {
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
directQuery: this.metadata.reference.directQuery, directQuery: this.metadata.reference.directQuery,
tableName: this.metadata.reference.tableName, tableName: this.metadata.reference.tableName,
value: this.metadata.value value: this.value
}) })
}, },
getterLookupList() { getterLookupList() {
@ -83,7 +72,7 @@ export default {
query: this.metadata.reference.query, query: this.metadata.reference.query,
directQuery: this.metadata.reference.directQuery, directQuery: this.metadata.reference.directQuery,
tableName: this.metadata.reference.tableName, tableName: this.metadata.reference.tableName,
value: this.metadata.value value: this.value
}) })
if (allOptions.length && !allOptions[0].key) { if (allOptions.length && !allOptions[0].key) {
allOptions.unshift(this.blanckOption) allOptions.unshift(this.blanckOption)
@ -92,56 +81,47 @@ export default {
} }
}, },
watch: { watch: {
'metadata.optionCRUD'(value) { valueModel(value) {
if (value === 'create-new') { if (this.metadata.inTable) {
this.value = this.metadata.value this.value = value
this.getDataLookupItem() }
} else { },
if (this.isEmptyValue(this.metadata.displayColumn)) { 'metadata.value'(value) {
this.value = this.getterValueSelec if (!this.metadata.inTable) {
} else { this.value = value
this.value = this.validateValue(this.metadata.displayColumn) }
},
'metadata.displayColumn'(value) {
if (!this.isEmptyValue(this.value)) {
// console.log('display wacth')
if (!this.isEmptyValue(value)) {
// verify if exists to add
if (!this.findLabel(this.value)) {
this.options.push({
key: this.value,
label: value
})
}
} }
} }
} }
}, },
beforeMount() { beforeMount() {
this.options = this.getterLookupAll this.options = this.getterLookupAll
if (this.isEmptyValue(this.metadata.displayColumn)) { if (!this.isEmptyValue(this.value) && this.metadata.panelType !== 'table') {
this.value = this.getterValueSelec if (!this.findLabel(this.value)) {
} else {
this.value = this.validateValue(this.metadata.displayColumn)
}
// enable to dataTable records
// Evaluate values of the displayColumn with empty string or number at 0
if (!this.isEmptyValue(this.metadata.displayColumn)) { if (!this.isEmptyValue(this.metadata.displayColumn)) {
var key = this.validateValue(this.metadata.value)
if (this.valueModel !== undefined && this.validateValue !== null) {
key = this.metadata.displayColumn
}
// verify if exists to add // verify if exists to add
if (!this.findLabel(key)) { this.options.push({
this.othersOptions.push({ key: this.value,
key: key,
label: this.metadata.displayColumn label: this.metadata.displayColumn
}) })
}
// join options in store with pased from props
// validate empty or duplicate data
const optionList = this.getterLookupAll.filter(lookup => {
if (lookup.key !== null) {
return lookup
}
})
this.options = optionList
this.value = key
} else if (!this.findLabel(this.value) && this.metadata.displayed) {
if (this.isPanelWindow) {
if (this.metadata.optionCRUD === 'create-new') {
this.value = this.metadata.value
}
} else { } else {
this.value = this.validateValue(this.metadata.displayColumn) if (!this.isPanelWindow || (this.isPanelWindow &&
(this.isEmptyValue(this.metadata.optionCRUD) || this.metadata.optionCRUD === 'create-new'))) {
this.getDataLookupItem()
}
}
} }
} }
}, },
@ -150,27 +130,8 @@ export default {
const label = this.findLabel(this.value) const label = this.findLabel(this.value)
this.handleChange(value, undefined, label) this.handleChange(value, undefined, label)
}, },
validateValue(value) {
if (this.isEmptyValue(value)) {
return undefined
}
// if (['TableDirect'].includes(this.metadata.referenceType)) {
// return parseInt(value, 10)
// }
return value
},
validateBlanckOption() {
// TODO: Evaluate -1 when list is string key
if (this.options.length <= 0 || (this.options.length && this.isEmptyValue(this.options[0].key))) {
this.options.unshift(this.blanckOption)
}
},
findLabel(value) { findLabel(value) {
var selected = this.options.find(item => item.key === value) const selected = this.options.find(item => item.key === value)
if (selected) {
return selected.label
}
selected = this.othersOptions.find(item => item.key === value)
if (selected) { if (selected) {
return selected.label return selected.label
} }
@ -178,7 +139,6 @@ export default {
}, },
async getDataLookupItem() { async getDataLookupItem() {
this.isLoading = true this.isLoading = true
if (!this.isEmptyValue(this.value)) {
this.$store.dispatch('getLookupItemFromServer', { this.$store.dispatch('getLookupItemFromServer', {
parentUuid: this.metadata.parentUuid, parentUuid: this.metadata.parentUuid,
containerUuid: this.metadata.containerUuid, containerUuid: this.metadata.containerUuid,
@ -202,7 +162,6 @@ export default {
.finally(() => { .finally(() => {
this.isLoading = false this.isLoading = false
}) })
}
}, },
/** /**
* @param {boolean} show triggers when the pull-down menu appears or disappears * @param {boolean} show triggers when the pull-down menu appears or disappears

View File

@ -481,9 +481,10 @@ const panel = {
} }
// the field has not changed, then the action is broken // the field has not changed, then the action is broken
if (params.newValue === field.value) { if (params.newValue === field.value && isEmptyValue(displayColumn)) {
return return
} }
commit('changeFieldValue', { commit('changeFieldValue', {
field: field, field: field,
newValue: params.newValue, newValue: params.newValue,
@ -491,6 +492,7 @@ const panel = {
displayColumn: displayColumn, displayColumn: displayColumn,
isChangedOldValue: params.isChangedOldValue isChangedOldValue: params.isChangedOldValue
}) })
// Change Dependents // Change Dependents
var dependents = fieldList.filter(fieldItem => { var dependents = fieldList.filter(fieldItem => {
return field.dependentFieldsList.includes(fieldItem.columnName) return field.dependentFieldsList.includes(fieldItem.columnName)