fixed: Fixed an issue with Select2 component and table in user list

This commit is contained in:
zhaojisen 2024-07-01 19:28:00 +08:00
parent 7c3effe1d9
commit cccec1aa1b
3 changed files with 27 additions and 13 deletions

View File

@ -117,12 +117,14 @@ export default {
// hasObjects object // hasObjects object
const theRemoveIndex = that.iHasObjects.findIndex((v) => v.value === obj.value) const theRemoveIndex = that.iHasObjects.findIndex((v) => v.value === obj.value)
that.iHasObjects.splice(theRemoveIndex, 1) that.iHasObjects.splice(theRemoveIndex, 1)
// disabled values value // disabled values value
while (that.select2.disabledValues.indexOf(obj.value) !== -1) { while (that.select2.disabledValues.indexOf(obj.value) !== -1) {
const i = that.select2.disabledValues.indexOf(obj.value) const i = that.select2.disabledValues.indexOf(obj.value)
this.$log.debug('disabled values remove index: ', i) that.$log.debug('disabled values remove index: ', i)
that.select2.disabledValues.splice(i, 1) that.select2.disabledValues.splice(i, 1)
} }
that.$message.success(that.$t('RemoveSuccessMsg')) that.$message.success(that.$t('RemoveSuccessMsg'))
} }
}, },
@ -157,6 +159,8 @@ export default {
that.iHasObjects = [...that.iHasObjects, ...objects] that.iHasObjects = [...that.iHasObjects, ...objects]
that.$refs.select2.clearSelected() that.$refs.select2.clearSelected()
that.$message.success(that.$t('AddSuccessMsg')) that.$message.success(that.$t('AddSuccessMsg'))
this.$refs.select2.refresh()
this.$emit('addSuccess')
} }
}, },
getHasObjects: { getHasObjects: {
@ -291,9 +295,9 @@ export default {
} }
}, },
removeObject(obj) { removeObject(obj) {
this.performDelete(obj, this).then( this.performDelete(obj, this).then(() => {
() => this.onDeleteSuccess(obj, this) this.onDeleteSuccess(obj, this)
).catch(error => { }).catch(error => {
this.onDeleteFail(error, this) this.onDeleteFail(error, this)
}) })
}, },
@ -303,7 +307,9 @@ export default {
return return
} }
this.performAdd(objects, this).then( this.performAdd(objects, this).then(
() => this.onAddSuccess(objects, this) () => {
this.onAddSuccess(objects, this)
}
) )
}, },
async selectAll() { async selectAll() {

View File

@ -51,7 +51,7 @@ export default {
props: { props: {
icon: { icon: {
type: String, type: String,
required: true default: ''
}, },
title: { title: {
type: String, type: String,

View File

@ -5,7 +5,7 @@
<GenericListTable ref="listTable" :header-actions="headerActions" :table-config="tableConfig" /> <GenericListTable ref="listTable" :header-actions="headerActions" :table-config="tableConfig" />
</el-col> </el-col>
<el-col :md="9" :sm="24"> <el-col :md="9" :sm="24">
<RelationCard v-bind="relationConfig" /> <RelationCard ref="relationCard" v-bind="relationConfig" @addSuccess="addSuccess" />
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
@ -95,6 +95,11 @@ export default {
} }
).then(res => { ).then(res => {
this.$message.success(this.$tc('DeleteSuccessMsg')) this.$message.success(this.$tc('DeleteSuccessMsg'))
setTimeout(() => {
this.$refs.relationCard.$refs.select2.refresh()
}, 300)
reload() reload()
}).catch(error => { }).catch(error => {
this.$message.error(this.$tc('DeleteErrorMsg') + ' ' + error) this.$message.error(this.$tc('DeleteErrorMsg') + ' ' + error)
@ -143,14 +148,17 @@ export default {
usergroup: groupId usergroup: groupId
} }
}) })
this.$axios.post(relationUrl, data)
this.$message.success(this.$tc('AddSuccessMsg')) this.$message.success(this.$tc('AddSuccessMsg'))
setTimeout(() => { return this.$axios.post(relationUrl, data)
window.location.reload()
}, 1000)
} }
} }
} }
},
methods: {
addSuccess() {
this.$refs.listTable.reloadTable()
}
} }
} }
</script> </script>