功能变化: 优化selector-table.vue

dev
李强 2023-11-07 00:33:28 +08:00
parent 01585e1e78
commit fc47ebeb88
1 changed files with 27 additions and 6 deletions

View File

@ -64,8 +64,9 @@
/> />
</div> </div>
<div slot="reference" ref="divRef" :style="{'pointerEvents': disabled?'none':''}"> <div slot="reference" ref="divRef" :style="{'pointerEvents': disabled?'none':''}">
<div v-if="currentValue.length>0" class="div-input el-input__inner" :class="disabled?'div-disabled':''"> <div v-if="currentValue.length>0" ref="tagDiv" class="div-input el-input__inner" :class="disabled?'div-disabled':''">
<div v-if="currentValue instanceof Array"> <div v-if="currentValue instanceof Array" ref="elTags">
<transition-group @after-leave="resetInputHeight" >
<el-tag <el-tag
style="margin-right: 5px" style="margin-right: 5px"
v-for="(item,index) in currentValue" v-for="(item,index) in currentValue"
@ -79,6 +80,7 @@
> >
<span>{{ item[dict.label] }}</span> <span>{{ item[dict.label] }}</span>
</el-tag> </el-tag>
</transition-group>
</div> </div>
</div> </div>
<el-input v-else placeholder="请选择" slot:reference clearable :disabled="disabled" :size="size"></el-input> <el-input v-else placeholder="请选择" slot:reference clearable :disabled="disabled" :size="size"></el-input>
@ -203,13 +205,17 @@ export default {
// //
setCurrentValue (val) { setCurrentValue (val) {
const params = {} const params = {}
let { url, value, label } = this.dict
if (this._elProps.tableConfig.pagination) { if (this._elProps.tableConfig.pagination) {
params.page = this.pageConfig.page if (url.indexOf('page') === -1) {
params.limit = this.pageConfig.limit params.page = this._elProps.tableConfig.page || this.pageConfig.page
}
if (url.indexOf('limit') === -1) {
params.limit = this._elProps.tableConfig.limit || this.pageConfig.limit
}
} }
if (val && val.toString().length > 0) { if (val && val.toString().length > 0) {
// value // value
let { url, value, label } = this.dict
params[value] = val params[value] = val
const queryList = ['id', label, value] const queryList = ['id', label, value]
this._elProps.tableConfig.columns.map(res => { this._elProps.tableConfig.columns.map(res => {
@ -230,8 +236,8 @@ export default {
this.pageConfig.limit = limit this.pageConfig.limit = limit
this.pageConfig.total = total this.pageConfig.total = total
if (data.data && data.data.length > 0) { if (data.data && data.data.length > 0) {
console.log(data.data)
this.currentValue = data.data this.currentValue = data.data
this.resetInputHeight()
} else { } else {
this.currentValue = [] this.currentValue = []
} }
@ -327,6 +333,7 @@ export default {
} }
this.$emit('input', result) this.$emit('input', result)
this.$emit('change', result) this.$emit('change', result)
this.resetInputHeight()
}, },
/** /**
* 表格单选 * 表格单选
@ -378,6 +385,20 @@ export default {
// this.$emit('input', result) // this.$emit('input', result)
// this.$emit('change', result) // this.$emit('change', result)
} }
},
resetInputHeight () {
this.$nextTick(() => {
const tagDiv = this.$refs.tagDiv
const elTags = this.$refs.elTags
const sizeInMap = this.initialInputHeight || 40
const height = this.currentValue.length === 0
? sizeInMap + 'px'
: Math.max(
elTags ? (elTags.clientHeight + (elTags.clientHeight > sizeInMap ? 4 : 0)) : 0,
sizeInMap
) + 'px'
tagDiv.style.height = height
})
} }
} }
} }