refactor: 勾选批量操作提示
This commit is contained in:
parent
822a1cf639
commit
8d4d6f0238
|
@ -29,12 +29,16 @@
|
||||||
:resizable="false" align="center">
|
:resizable="false" align="center">
|
||||||
<template v-slot:default="scope">
|
<template v-slot:default="scope">
|
||||||
<!-- 选中记录后浮现的按钮,提供对记录的批量操作 -->
|
<!-- 选中记录后浮现的按钮,提供对记录的批量操作 -->
|
||||||
<show-more-btn :is-show-tool="scope.row.showTool" :is-show="scope.row.showMore" :buttons="batchOperators"
|
<show-more-btn :has-showed="hasBatchTipShow" :is-show="scope.row.showMore" :buttons="batchOperators"
|
||||||
:size="selectDataCounts"/>
|
:size="selectDataCounts"/>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
<el-table-column width="1"/>
|
<el-table-column width="1">
|
||||||
|
<template v-slot:header>
|
||||||
|
<span class="table-column-mark"> </span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
|
|
||||||
<el-table-column
|
<el-table-column
|
||||||
|
@ -109,7 +113,8 @@ export default {
|
||||||
selectDataCounts: 0,
|
selectDataCounts: 0,
|
||||||
selectRows: new Set(),
|
selectRows: new Set(),
|
||||||
selectIds: [],
|
selectIds: [],
|
||||||
tableActive: true
|
tableActive: true,
|
||||||
|
hasBatchTipShow: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
@ -200,6 +205,36 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// 批量操作提示, 第一次勾选提示, 之后不提示
|
||||||
|
// 先添加 batch-popper 样式, 全选后再移除样式, 只保留可见框内第一条数据的提示
|
||||||
|
removeBatchPopper() {
|
||||||
|
let elements = window.document.getElementsByClassName('batch-popper');
|
||||||
|
let tableHeader = window.document.getElementsByClassName('table-column-mark');
|
||||||
|
let columns = window.document.getElementsByClassName('table-more-icon');
|
||||||
|
let tableTop = tableHeader[0].getBoundingClientRect().top;
|
||||||
|
let index = 0;
|
||||||
|
for (let i = 0; i < columns.length; i++) {
|
||||||
|
let column = columns[i];
|
||||||
|
if (this.isScrollShow(column, tableTop)) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (elements) {
|
||||||
|
for (let i = 0; i < elements.length; i++) {
|
||||||
|
if (i == index) {
|
||||||
|
elements[i].classList.remove('batch-popper');
|
||||||
|
setTimeout(() => {
|
||||||
|
this.hasBatchTipShow = true;
|
||||||
|
}, 1500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isScrollShow(column, tableTop){ //判断元素是否因为超过表头
|
||||||
|
let columnTop = column.getBoundingClientRect().top;
|
||||||
|
return columnTop - tableTop > 30;
|
||||||
|
},
|
||||||
handleSelectAll(selection) {
|
handleSelectAll(selection) {
|
||||||
_handleSelectAll(this, selection, this.data, this.selectRows, this.condition);
|
_handleSelectAll(this, selection, this.data, this.selectRows, this.condition);
|
||||||
setUnSelectIds(this.data, this.condition, this.selectRows);
|
setUnSelectIds(this.data, this.condition, this.selectRows);
|
||||||
|
@ -207,6 +242,9 @@ export default {
|
||||||
this.selectIds = Array.from(this.selectRows).map(o => o.id);
|
this.selectIds = Array.from(this.selectRows).map(o => o.id);
|
||||||
//有的组件需要回调父组件的函数,做下一步处理
|
//有的组件需要回调父组件的函数,做下一步处理
|
||||||
this.$emit('callBackSelectAll',selection);
|
this.$emit('callBackSelectAll',selection);
|
||||||
|
this.$nextTick(function () {
|
||||||
|
setTimeout(this.removeBatchPopper, 1);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
handleSelect(selection, row) {
|
handleSelect(selection, row) {
|
||||||
_handleSelect(this, selection, row, this.selectRows);
|
_handleSelect(this, selection, row, this.selectRows);
|
||||||
|
@ -215,6 +253,9 @@ export default {
|
||||||
this.selectIds = Array.from(this.selectRows).map(o => o.id);
|
this.selectIds = Array.from(this.selectRows).map(o => o.id);
|
||||||
//有的组件需要回调父组件的函数,做下一步处理
|
//有的组件需要回调父组件的函数,做下一步处理
|
||||||
this.$emit('callBackSelect',selection);
|
this.$emit('callBackSelect',selection);
|
||||||
|
this.$nextTick(function () {
|
||||||
|
setTimeout(this.removeBatchPopper, 1);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
isSelectDataAll(data) {
|
isSelectDataAll(data) {
|
||||||
this.condition.selectAll = data;
|
this.condition.selectAll = data;
|
||||||
|
@ -322,5 +363,8 @@ export default {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.batch-popper {
|
||||||
|
top: 300px;
|
||||||
|
color: #1FDD02;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
<div v-if="isShow">
|
<div v-if="isShow">
|
||||||
<el-dropdown placement="bottom" trigger="click" size="medium">
|
<el-dropdown placement="bottom" trigger="click" size="medium">
|
||||||
<div @click.stop class="show-more-btn">
|
<div @click.stop class="show-more-btn">
|
||||||
<i class="el-icon-more ms-icon-more"/>
|
<el-tooltip popper-class="batch-popper" :value="true && !hasShowed" effect="dark" :content="$t('test_track.case.batch_operate')"
|
||||||
|
placement="top-start">
|
||||||
|
<i class="el-icon-more ms-icon-more table-more-icon"/>
|
||||||
|
</el-tooltip>
|
||||||
</div>
|
</div>
|
||||||
<el-dropdown-menu slot="dropdown" class="dropdown-menu-class">
|
<el-dropdown-menu slot="dropdown" class="dropdown-menu-class">
|
||||||
<div class="show-more-btn-title">{{$t('test_track.case.batch_handle', [size])}}</div>
|
<div class="show-more-btn-title">{{$t('test_track.case.batch_handle', [size])}}</div>
|
||||||
|
@ -22,7 +25,6 @@
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
showTool: false
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
@ -30,23 +32,10 @@
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
},
|
},
|
||||||
isShowTool: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
buttons: Array,
|
buttons: Array,
|
||||||
row: Object,
|
row: Object,
|
||||||
size: Number
|
size: Number,
|
||||||
},
|
hasShowed: Object
|
||||||
watch: {
|
|
||||||
isShowTool(val) {
|
|
||||||
if (val) {
|
|
||||||
this.showTool = val;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.showTool = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (this.trashEnable) {
|
if (this.trashEnable) {
|
||||||
|
@ -91,3 +80,8 @@
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<style>
|
||||||
|
.batch-popper {
|
||||||
|
top: -10000px !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -7,19 +7,13 @@ export function _handleSelectAll(component, selection, tableData, selectRows, co
|
||||||
if (selection.length > 0) {
|
if (selection.length > 0) {
|
||||||
if (selection.length === 1) {
|
if (selection.length === 1) {
|
||||||
selection.hashTree = [];
|
selection.hashTree = [];
|
||||||
tableData.forEach((item, index) => {
|
tableData.forEach((item) => {
|
||||||
if (index === 0) {
|
|
||||||
component.$set(item, "showTool", true);
|
|
||||||
}
|
|
||||||
component.$set(item, "showMore", true);
|
component.$set(item, "showMore", true);
|
||||||
selectRows.add(item);
|
selectRows.add(item);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
tableData.forEach((item, index) => {
|
tableData.forEach((item) => {
|
||||||
item.hashTree = [];
|
item.hashTree = [];
|
||||||
if (index === 0) {
|
|
||||||
component.$set(item, "showTool", true);
|
|
||||||
}
|
|
||||||
component.$set(item, "showMore", true);
|
component.$set(item, "showMore", true);
|
||||||
selectRows.add(item);
|
selectRows.add(item);
|
||||||
});
|
});
|
||||||
|
@ -27,7 +21,6 @@ export function _handleSelectAll(component, selection, tableData, selectRows, co
|
||||||
} else {
|
} else {
|
||||||
selectRows.clear();
|
selectRows.clear();
|
||||||
tableData.forEach(item => {
|
tableData.forEach(item => {
|
||||||
component.$set(item, "showTool", false);
|
|
||||||
component.$set(item, "showMore", false);
|
component.$set(item, "showMore", false);
|
||||||
});
|
});
|
||||||
if (condition) {
|
if (condition) {
|
||||||
|
@ -39,17 +32,14 @@ export function _handleSelectAll(component, selection, tableData, selectRows, co
|
||||||
export function _handleSelect(component, selection, row, selectRows) {
|
export function _handleSelect(component, selection, row, selectRows) {
|
||||||
row.hashTree = [];
|
row.hashTree = [];
|
||||||
if (selectRows.has(row)) {
|
if (selectRows.has(row)) {
|
||||||
component.$set(row, "showTool", false);
|
|
||||||
component.$set(row, "showMore", false);
|
component.$set(row, "showMore", false);
|
||||||
selectRows.delete(row);
|
selectRows.delete(row);
|
||||||
} else {
|
} else {
|
||||||
component.$set(row, "showTool", true);
|
|
||||||
component.$set(row, "showMore", true);
|
component.$set(row, "showMore", true);
|
||||||
selectRows.add(row);
|
selectRows.add(row);
|
||||||
}
|
}
|
||||||
let arr = Array.from(selectRows);
|
let arr = Array.from(selectRows);
|
||||||
arr.forEach(row => {
|
arr.forEach(row => {
|
||||||
component.$set(row, "showTool", true);
|
|
||||||
component.$set(row, "showMore", true);
|
component.$set(row, "showMore", true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue