Files
ss-crm-manage-web/src/components/SSTable/index.vue

145 lines
3.6 KiB
Vue
Raw Normal View History

2024-04-28 16:20:45 +08:00
<template>
<div>
<div class="flex">
2024-08-02 18:03:21 +08:00
<el-table
:data="tableObject.tableList"
border
style="flex: 1"
@selection-change="handleSelectionChange"
>
2024-04-28 16:20:45 +08:00
<slot></slot>
</el-table>
<el-button
ref="ColumnSetting"
plain
style="writing-mode: vertical-lr; height: 100px; letter-spacing: 2px"
@click="clickSetting"
>表格列控制</el-button
>
<el-popover
ref="TableColumnPop"
:virtual-ref="ColumnSetting"
placement="left"
width="120px"
trigger="click"
virtual-triggering
>
2024-05-10 16:21:07 +08:00
<el-checkbox-group v-model="checkedColumns" @change="confirm">
<draggable
v-model="allColumns"
item-key="field"
ghost-class="draggable-ghost"
:animation="400"
@end="onDragEnd"
>
<template #item="{ element: item }">
2024-06-11 20:29:30 +08:00
<el-checkbox :key="item.id" :label="item.id">
2024-05-10 16:21:07 +08:00
{{ item.label }}
</el-checkbox>
</template>
</draggable>
2024-04-28 16:20:45 +08:00
</el-checkbox-group>
</el-popover>
</div>
<!-- 分页 -->
<Pagination
v-model:limit="pageSize"
2024-06-05 17:08:27 +08:00
v-model:page="pageNo"
2024-04-28 16:20:45 +08:00
:total="tableObject.total"
@pagination="getList"
/>
</div>
</template>
<script setup>
2024-05-10 16:21:07 +08:00
import draggable from 'vuedraggable'
2024-06-11 20:29:30 +08:00
import * as ClueCacheApi from '@/api/clue/clueCache'
2024-05-10 16:21:07 +08:00
import { useRoute } from 'vue-router'
2024-04-28 16:20:45 +08:00
const props = defineProps({
tableObject: { type: Object, default: () => ({ tableList: [] }) },
tableColumns: { type: Array, default: () => [] }
})
2024-08-02 18:03:21 +08:00
const emit = defineEmits(['update:tableObject', 'getList', 'getCheckedColumns', 'selection-change'])
2024-05-10 16:21:07 +08:00
const route = useRoute()
2024-04-28 16:20:45 +08:00
2024-06-05 17:08:27 +08:00
const pageNo = ref(props.tableObject?.pageNo || 1)
2024-04-28 16:20:45 +08:00
const pageSize = ref(props.tableObject?.pageSize || 20)
const ColumnSetting = ref()
const TableColumnPop = ref()
2024-05-10 16:21:07 +08:00
// 展示在设置里的所有表格列,由于会排序,所以使用新属性,不直接修改原值
2024-06-11 20:29:30 +08:00
const allColumns = ref([...props.tableColumns])
2024-05-10 16:21:07 +08:00
// 已勾选的选项
2024-04-28 16:20:45 +08:00
const checkedColumns = ref([])
2024-05-10 16:21:07 +08:00
// 调用获取数据的接口,分页时需要使用
2024-04-28 16:20:45 +08:00
function getList({ page, limit }) {
2024-06-05 17:08:27 +08:00
emit('update:tableObject', { ...props.tableObject, pageNo: page, pageSize: limit })
2024-04-28 16:20:45 +08:00
nextTick(() => {
emit('getList')
})
}
2024-05-10 16:21:07 +08:00
// 点击"表格列控制"按钮,出现设置页面
2024-04-28 16:20:45 +08:00
const clickSetting = () => {
unref(TableColumnPop).TableColumnPop?.delayHide?.()
}
2024-05-10 16:21:07 +08:00
2024-06-11 20:29:30 +08:00
const routeMap = {
CluePool: 1,
ClueOrder: 2
2024-05-10 16:21:07 +08:00
}
2024-06-11 20:29:30 +08:00
2024-05-10 16:21:07 +08:00
// 获取用户已勾选的表头
2024-06-11 20:29:30 +08:00
async function getUserCheckedColumns() {
checkedColumns.value = await ClueCacheApi.getClueCache({
settingType: 2,
model: routeMap[route.name]
})
// 回显到表格中
2024-05-10 16:21:07 +08:00
emitColumns()
}
// 表格列排序
function onDragEnd() {
2024-06-11 20:29:30 +08:00
ClueCacheApi.setClueCache({
settingType: 2,
model: routeMap[route.name],
clueParamId: checkedColumns.value
})
// 表格回显
2024-05-10 16:21:07 +08:00
emitColumns()
}
2024-08-02 18:03:21 +08:00
function handleSelectionChange(val) {
emit('selection-change', val)
}
2024-05-10 16:21:07 +08:00
// 勾选确认
function confirm() {
2024-06-11 20:29:30 +08:00
ClueCacheApi.setClueCache({
settingType: 2,
model: routeMap[route.name],
clueParamId: checkedColumns.value
})
// usedSchema.value = allColumns.value.filter((it) => checkedColumns.value.includes(it.id))
2024-05-10 16:21:07 +08:00
emitColumns()
}
// 将表头数据返回至父组件
function emitColumns() {
2024-06-11 20:29:30 +08:00
const arr = allColumns.value.filter((item) => checkedColumns.value.includes(item.id))
2024-05-10 16:21:07 +08:00
emit('getCheckedColumns', arr)
}
getUserCheckedColumns()
defineExpose({ getUserCheckedColumns })
2024-04-28 16:20:45 +08:00
</script>
<style lang="scss" scoped></style>