[Update] 继续优化select2组件

This commit is contained in:
ibuler
2020-05-22 15:59:23 +08:00
parent ae00c1c71c
commit b32bb59c70
3 changed files with 40 additions and 33 deletions

View File

@@ -133,7 +133,6 @@ export default {
field = this.generateFieldByName(name, field)
field = this.generateFieldByOther(field, fieldMeta)
field = Object.assign(field, this.fieldsMeta[name] || {})
console.log(field)
_.set(field, 'attrs.error', '')
return field
},

View File

@@ -88,6 +88,22 @@ export default {
hasMore: true,
pageSize: defaultPageSize
}
return {
loading: false,
initialized: false,
iValue: this.value ? this.value : [],
defaultParams: _.cloneDeep(defaultParams),
params: _.cloneDeep(defaultParams),
iOptions: this.options || [],
initialOptions: []
}
},
computed: {
optionsValues() {
return this.iOptions.map((v) => v.value)
},
iAjax() {
const defaultPageSize = 10
const defaultMakeParams = (params) => {
const page = params.page || 1
const offset = (page - 1) * params.pageSize
@@ -115,27 +131,17 @@ export default {
makeParams: defaultMakeParams,
processResults: defaultProcessResults
}
const iAjax = Object.assign(defaultAjax, this.ajax, this.url ? { url: this.url } : {})
return {
loading: false,
initialized: false,
iAjax: iAjax,
iValue: this.value ? this.value : [],
defaultParams: _.cloneDeep(defaultParams),
params: _.cloneDeep(defaultParams),
iOptions: this.options || [],
initialOptions: []
}
},
computed: {
optionsValues() {
return this.iOptions.map((v) => v.value)
return Object.assign(defaultAjax, this.ajax, this.url ? { url: this.url } : {})
}
},
watch: {
url(newValue, oldValue) {
// url(newValue, oldValue) {
// this.$log.debug('Select url changed: ', oldValue, ' => ', newValue)
// this.iAjax.url = newValue
// this.refresh()
// },
iAjax(newValue, oldValue) {
this.$log.debug('Select url changed: ', oldValue, ' => ', newValue)
this.iAjax.url = newValue
this.refresh()
}
},

View File

@@ -46,7 +46,9 @@ export default {
groups: {
el: {
multiple: true,
url: '/api/v1/users/groups/',
ajax: {
url: '/api/v1/users/groups/'
},
value: []
}
}