mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-11 21:53:24 +08:00
This commit is contained in:
parent
553b07c2bd
commit
7b0354fa34
@ -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 {
|
if (!this.isEmptyValue(this.metadata.displayColumn)) {
|
||||||
this.value = this.validateValue(this.metadata.displayColumn)
|
// verify if exists to add
|
||||||
}
|
this.options.push({
|
||||||
// enable to dataTable records
|
key: this.value,
|
||||||
// Evaluate values of the displayColumn with empty string or number at 0
|
label: this.metadata.displayColumn
|
||||||
if (!this.isEmptyValue(this.metadata.displayColumn)) {
|
})
|
||||||
var key = this.validateValue(this.metadata.value)
|
} else {
|
||||||
if (this.valueModel !== undefined && this.validateValue !== null) {
|
if (!this.isPanelWindow || (this.isPanelWindow &&
|
||||||
key = this.metadata.displayColumn
|
(this.isEmptyValue(this.metadata.optionCRUD) || this.metadata.optionCRUD === 'create-new'))) {
|
||||||
}
|
this.getDataLookupItem()
|
||||||
// verify if exists to add
|
}
|
||||||
if (!this.findLabel(key)) {
|
|
||||||
this.othersOptions.push({
|
|
||||||
key: key,
|
|
||||||
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 {
|
|
||||||
this.value = this.validateValue(this.metadata.displayColumn)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -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,31 +139,29 @@ 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,
|
tableName: this.metadata.reference.tableName,
|
||||||
tableName: this.metadata.reference.tableName,
|
directQuery: this.metadata.reference.directQuery,
|
||||||
directQuery: this.metadata.reference.directQuery,
|
value: this.metadata.value
|
||||||
value: this.metadata.value
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (this.isPanelWindow) {
|
||||||
|
this.$store.dispatch('notifyFieldChangeDisplayColumn', {
|
||||||
|
containerUuid: this.metadata.containerUuid,
|
||||||
|
columnName: this.metadata.columnName,
|
||||||
|
displayColumn: response.label
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.options = this.getterLookupAll
|
||||||
|
if (this.options.length && !this.options[0].key) {
|
||||||
|
this.options.unshift(this.blanckOption)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.isLoading = false
|
||||||
})
|
})
|
||||||
.then(response => {
|
|
||||||
if (this.isPanelWindow) {
|
|
||||||
this.$store.dispatch('notifyFieldChangeDisplayColumn', {
|
|
||||||
containerUuid: this.metadata.containerUuid,
|
|
||||||
columnName: this.metadata.columnName,
|
|
||||||
displayColumn: response.label
|
|
||||||
})
|
|
||||||
}
|
|
||||||
this.options = this.getterLookupAll
|
|
||||||
if (this.options.length && !this.options[0].key) {
|
|
||||||
this.options.unshift(this.blanckOption)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
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
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user