no message
This commit is contained in:
parent
ffd3b2325d
commit
4ccef9dc20
@ -10,9 +10,6 @@
|
|||||||
</div>
|
</div>
|
||||||
<el-table ref="table" :data="tableData" :height="245" :highlight-current-row="!multiple" @row-click="click" @select="select" @select-all="selectAll">
|
<el-table ref="table" :data="tableData" :height="245" :highlight-current-row="!multiple" @row-click="click" @select="select" @select-all="selectAll">
|
||||||
<el-table-column v-if="multiple" type="selection" width="55"></el-table-column>
|
<el-table-column v-if="multiple" type="selection" width="55"></el-table-column>
|
||||||
<el-table-column v-else type="index" width="55">
|
|
||||||
<template #default="scope"><span>{{scope.$index+(currentPage - 1) * limit + 1}}</span></template>
|
|
||||||
</el-table-column>
|
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</el-table>
|
</el-table>
|
||||||
<div class="x-table-select__page">
|
<div class="x-table-select__page">
|
||||||
@ -57,9 +54,12 @@
|
|||||||
value: config.props.value,
|
value: config.props.value,
|
||||||
page: config.request.page,
|
page: config.request.page,
|
||||||
limit: config.request.limit,
|
limit: config.request.limit,
|
||||||
keyword: config.request.keyword
|
keyword: config.request.keyword,
|
||||||
|
field: {}
|
||||||
},
|
},
|
||||||
formData: {}
|
formData: {},
|
||||||
|
skey: '',
|
||||||
|
dkey: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -77,6 +77,21 @@
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.defaultProps = Object.assign(this.defaultProps, this.props);
|
this.defaultProps = Object.assign(this.defaultProps, this.props);
|
||||||
this.defaultValue = this.modelValue
|
this.defaultValue = this.modelValue
|
||||||
|
this.skey = this.defaultProps.value;
|
||||||
|
|
||||||
|
if (Object.keys(this.defaultProps.field).length === 0) {
|
||||||
|
this.defaultProps.field = {
|
||||||
|
[this.defaultProps.value]: this.defaultProps.value,
|
||||||
|
[this.defaultProps.label]: this.defaultProps.label,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key in this.defaultProps.field) {
|
||||||
|
if (key == this.skey) {
|
||||||
|
this.dkey = this.defaultProps.field[key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.autoCurrentLabel()
|
this.autoCurrentLabel()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -114,13 +129,13 @@
|
|||||||
|
|
||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
this.defaultValue.forEach(row => {
|
this.defaultValue.forEach(row => {
|
||||||
var setrow = this.tableData.filter(item => item[this.defaultProps.value]===row[this.defaultProps.value] )
|
var setrow = this.tableData.filter(item => item[this.dkey] === row[this.skey])
|
||||||
if (setrow.length > 0) {
|
if (setrow.length > 0) {
|
||||||
this.$refs.table.toggleRowSelection(setrow[0], true);
|
this.$refs.table.toggleRowSelection(setrow[0], true);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var setrow = this.tableData.filter(item => item[this.defaultProps.value]===this.defaultValue[this.defaultProps.value] )
|
var setrow = this.tableData.filter(item => item[this.dkey] === this.defaultValue[this.skey])
|
||||||
this.$refs.table.setCurrentRow(setrow[0]);
|
this.$refs.table.setCurrentRow(setrow[0]);
|
||||||
}
|
}
|
||||||
this.$refs.table.setScrollTop(0)
|
this.$refs.table.setScrollTop(0)
|
||||||
@ -153,15 +168,15 @@
|
|||||||
var isSelect = rows.length && rows.indexOf(row) !== -1
|
var isSelect = rows.length && rows.indexOf(row) !== -1
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
var data = {};
|
var data = {};
|
||||||
for (const key in this.defaultProps) {
|
for (let key in this.defaultProps.field) {
|
||||||
if (Object.prototype.hasOwnProperty.call(row, this.defaultProps[key])) {
|
if (Object.prototype.hasOwnProperty.call(row, this.defaultProps.field[key])) {
|
||||||
data[this.defaultProps[key]] = row[this.defaultProps[key]]
|
data[key] = row[this.defaultProps.field[key]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.defaultValue.push(data)
|
this.defaultValue.push(data)
|
||||||
} else {
|
} else {
|
||||||
this.defaultValue.splice(
|
this.defaultValue.splice(
|
||||||
this.defaultValue.findIndex(item => item[this.defaultProps.value] == row[this.defaultProps.value]),
|
this.defaultValue.findIndex(item => item[this.dkey] == row[this.skey]),
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -174,17 +189,17 @@
|
|||||||
var isAllSelect = rows.length > 0
|
var isAllSelect = rows.length > 0
|
||||||
if (isAllSelect) {
|
if (isAllSelect) {
|
||||||
rows.forEach(row => {
|
rows.forEach(row => {
|
||||||
var isHas = this.defaultValue.find(item => item[this.defaultProps.value] == row[this.defaultProps.value])
|
var isHas = this.defaultValue.find(item => item[this.skey] == row[this.dkey])
|
||||||
if (!isHas) {
|
if (!isHas) {
|
||||||
this.defaultValue.push(row)
|
this.defaultValue.push(row)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.tableData.forEach(row => {
|
this.tableData.forEach(row => {
|
||||||
var isHas = this.defaultValue.find(item => item[this.defaultProps.value] == row[this.defaultProps.value])
|
var isHas = this.defaultValue.find(item => item[this.skey] == row[this.dkey])
|
||||||
if (isHas) {
|
if (isHas) {
|
||||||
this.defaultValue.splice(
|
this.defaultValue.splice(
|
||||||
this.defaultValue.findIndex(item => item[this.defaultProps.value] == row[this.defaultProps.value]),
|
this.defaultValue.findIndex(item => item[this.skey] == row[this.dkey]),
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -198,11 +213,21 @@
|
|||||||
if (this.multiple) {
|
if (this.multiple) {
|
||||||
//处理多选点击行
|
//处理多选点击行
|
||||||
} else {
|
} else {
|
||||||
for (const key in this.defaultProps) {
|
|
||||||
if (Object.prototype.hasOwnProperty.call(row, this.defaultProps[key])) {
|
if (this.defaultProps.field) {
|
||||||
this.defaultValue[this.defaultProps[key]] = row[this.defaultProps[key]]
|
if (typeof this.defaultValue === 'object') {
|
||||||
|
for (let key in this.defaultProps.field) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(row, this.defaultProps.field[key])) {
|
||||||
|
this.defaultValue[key] = row[this.defaultProps.field[key]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.defaultValue = row[this.dkey];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.defaultValue = row;
|
||||||
|
}
|
||||||
|
|
||||||
this.$refs.select.blur()
|
this.$refs.select.blur()
|
||||||
this.autoCurrentLabel()
|
this.autoCurrentLabel()
|
||||||
this.$emit('update:modelValue', this.defaultValue);
|
this.$emit('update:modelValue', this.defaultValue);
|
||||||
@ -244,6 +269,11 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.x-table-select__table {padding:12px;}
|
.x-table-select__table {
|
||||||
.x-table-select__page {padding-top: 12px;}
|
padding: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.x-table-select__page {
|
||||||
|
padding-top: 12px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -16,7 +16,11 @@ export default {
|
|||||||
keyword: 'keyword' //规定搜索字段
|
keyword: 'keyword' //规定搜索字段
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
label: 'label', // 映射label显示字段
|
key: null,
|
||||||
value: 'value', // 映射value值字段
|
label: 'id', // 映射label显示字段
|
||||||
|
value: 'name', // 映射value值字段
|
||||||
|
field: {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user