2025-08-27 17:54:46 +08:00
|
|
|
|
<template>
|
2025-09-08 18:11:21 +08:00
|
|
|
|
<div class="w100 h100">
|
2025-08-27 17:54:46 +08:00
|
|
|
|
<!-- 表格头部按钮 -->
|
2025-09-26 19:39:36 +08:00
|
|
|
|
<el-row :gutter="10" style="margin: 0 0 8px 0;">
|
2025-09-04 18:25:23 +08:00
|
|
|
|
<template v-if="config && config.tableButton && config.tableButton.top">
|
|
|
|
|
|
<el-col :span="1.5" v-for="item of config.tableButton.top">
|
|
|
|
|
|
<el-button :type="item.type" plain size="mini" :icon="item.icon" @click="handleClick(item,{})" :hasPermi="[item.hasPermi]">{{item.content}}</el-button>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</template>
|
2025-09-10 10:30:21 +08:00
|
|
|
|
<right-toolbar v-if="!(config && config.colTopHiddenIcon)" :showSearch.sync="showSearch" @queryTable="renderList" @columnsChange="columnsChange" :columns="columns"></right-toolbar>
|
2025-08-27 17:54:46 +08:00
|
|
|
|
</el-row>
|
|
|
|
|
|
<!-- 表格数据 -->
|
2025-09-24 20:58:25 +08:00
|
|
|
|
<el-table v-loading="loading" :data="tableList" :ref="config && config.tableKey ? `tableRef_${config.tableKey}` : `selChangeList`" :key="tableKey" highlight-selection-row @select-all="handleSelectAll" @select="handleSelectionChange">
|
2025-09-23 20:03:01 +08:00
|
|
|
|
<!-- :selectable="() => config && config.selectable ? false : true" -->
|
2025-09-22 21:36:22 +08:00
|
|
|
|
<el-table-column v-if="!(config && config.colHiddenCheck)" fixed="left" type="selection" width="55" :selectable="() => config && config.selectable ? false : true" align="center" />
|
2025-09-22 10:39:04 +08:00
|
|
|
|
<!-- 展开列内容 -->
|
|
|
|
|
|
<el-table-column v-if="config && config.expand" type="expand">
|
|
|
|
|
|
<template #default="props">
|
|
|
|
|
|
<slot
|
|
|
|
|
|
name="tableExpand"
|
|
|
|
|
|
:row="props.row"
|
|
|
|
|
|
:rowIndex="props.$index"
|
|
|
|
|
|
:props="props"
|
|
|
|
|
|
></slot>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2025-08-27 17:54:46 +08:00
|
|
|
|
<template v-for="(column, key, index) of columns">
|
2025-09-05 18:51:20 +08:00
|
|
|
|
<el-table-column v-if="column && column.visible" :label="column.label" :key="key" :prop="key" :width="column.width" :min-width="column.minWidth || '100px'" align="left" :show-overflow-tooltip="true">
|
2025-08-27 17:54:46 +08:00
|
|
|
|
<!-- 插槽 自定义列表表头数据格式 -->
|
|
|
|
|
|
<template #header v-if="column && column.slotHeaderName">
|
|
|
|
|
|
<span>{{column.label}}</span>
|
|
|
|
|
|
<el-tooltip trigger="click" effect="dark" placement="top">
|
|
|
|
|
|
<template #content>{{column.slotHeaderName}}</template>
|
|
|
|
|
|
<i class="el-icon-question"></i>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 插槽 自定义列表内数据格式 -->
|
|
|
|
|
|
<template #default="scope" v-if="column && column.slotName">
|
|
|
|
|
|
<!-- 传递行数据、行索引等信息到父组件的插槽 -->
|
|
|
|
|
|
<slot
|
|
|
|
|
|
:name="column.slotName"
|
2025-09-01 18:33:42 +08:00
|
|
|
|
:valueKey="key"
|
2025-08-27 17:54:46 +08:00
|
|
|
|
:row="scope.row"
|
|
|
|
|
|
:rowIndex="scope.$index"
|
|
|
|
|
|
:column="column"
|
|
|
|
|
|
:scope="scope"
|
|
|
|
|
|
></slot>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<!-- 表格行内按钮 -->
|
|
|
|
|
|
<el-table-column v-if="config && config.tableButton && config.tableButton.line" :width="config.tableButton.line.length * 60 + `px`" label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
|
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
|
<template v-for="item of config.tableButton.line">
|
2025-09-05 18:51:20 +08:00
|
|
|
|
<!-- <el-tooltip v-if="item && item.content" :content="item.content" placement="top">-->
|
|
|
|
|
|
<el-button v-if="item && item.content" size="mini" link :type="item.type" :icon="item.icon" v-show="scope.row[item.showName] === item.showVal" @click="handleClick(item, scope.row)" :hasPermi="[item.hasPermi]">{{item.content}}</el-button>
|
|
|
|
|
|
<!-- </el-tooltip>-->
|
2025-08-27 17:54:46 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
2025-09-08 18:11:21 +08:00
|
|
|
|
<pagination v-show="queryParams.total > 0" :layout="queryParams && queryParams.layout" :total="queryParams.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="renderList" />
|
|
|
|
|
|
|
|
|
|
|
|
<el-dialog title="导出项" :visible.sync="dialogOpen" width="800px" append-to-body>
|
|
|
|
|
|
<el-checkbox-group v-model="checkColumns">
|
|
|
|
|
|
<template v-for="(item, key, index) of columns">
|
|
|
|
|
|
<el-checkbox v-if="key !== 'id'" :label="key" :key="key" style="width: 25%;margin-right: 0px;">{{item.label}}</el-checkbox>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-checkbox-group>
|
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
|
<el-button type="primary" @click="diaColSubmit">确 定</el-button>
|
|
|
|
|
|
<el-button @click="diaColCancel">取 消</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
2025-08-27 17:54:46 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'table-list',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
tableList: {
|
|
|
|
|
|
type: Array,
|
|
|
|
|
|
default: () => []
|
|
|
|
|
|
},
|
|
|
|
|
|
columns: {
|
|
|
|
|
|
type: Object,
|
|
|
|
|
|
default: () => {}
|
|
|
|
|
|
},
|
|
|
|
|
|
queryParams: {
|
|
|
|
|
|
type: Object,
|
|
|
|
|
|
default: {
|
2025-09-08 18:11:21 +08:00
|
|
|
|
total: 0,
|
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
layout: 'total, sizes, prev, pager, next, jumper'
|
2025-08-27 17:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
config: {
|
|
|
|
|
|
type: Object,
|
2025-08-29 17:21:52 +08:00
|
|
|
|
default: () => ({
|
2025-09-04 18:25:23 +08:00
|
|
|
|
colHiddenCheck: false,
|
|
|
|
|
|
colTopHiddenIcon: false
|
2025-08-29 17:21:52 +08:00
|
|
|
|
})
|
2025-08-27 17:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
2025-09-10 10:30:21 +08:00
|
|
|
|
tableKey: 0,
|
2025-08-27 17:54:46 +08:00
|
|
|
|
loading: false,
|
|
|
|
|
|
showSearch: true,
|
2025-09-08 18:11:21 +08:00
|
|
|
|
dialogOpen: false,
|
2025-08-27 17:54:46 +08:00
|
|
|
|
ids: [],
|
|
|
|
|
|
selectList: [],
|
|
|
|
|
|
isProcessing: false, // 防止事件循环的标志位
|
2025-09-24 20:58:25 +08:00
|
|
|
|
checkColumns: []
|
2025-08-27 17:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 监听showSearch的变化,并且把变化后的值传给父组件
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
showSearch: {
|
|
|
|
|
|
handler(val) {
|
|
|
|
|
|
this.$emit('value-change', val)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
// 所有方法都抛出到父组件里去
|
2025-09-08 18:11:21 +08:00
|
|
|
|
handleClick(result, row) {
|
|
|
|
|
|
if (result && result.fnCode) {
|
|
|
|
|
|
switch (result.fnCode) {
|
|
|
|
|
|
case 'export':
|
|
|
|
|
|
this.dialogOpen = true;
|
|
|
|
|
|
this.diaColumnCheck();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
this.$emit("fnClick", result, row, this.ids, this.selectList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 导出弹窗 默认选中项
|
|
|
|
|
|
diaColumnCheck() {
|
|
|
|
|
|
this.checkColumns = [];
|
|
|
|
|
|
Object.keys(this.columns).forEach(item => {
|
|
|
|
|
|
if (item !== 'id' && this.columns[item] && this.columns[item].visible) {
|
|
|
|
|
|
this.checkColumns.push(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// 弹窗确认
|
|
|
|
|
|
diaColSubmit(){
|
|
|
|
|
|
this.$emit("fnClick", {fnCode: 'export'}, {properties: this.checkColumns});
|
|
|
|
|
|
this.dialogOpen = false;
|
|
|
|
|
|
},
|
|
|
|
|
|
// 弹窗取消
|
|
|
|
|
|
diaColCancel() {
|
|
|
|
|
|
this.dialogOpen = false;
|
2025-08-27 17:54:46 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/** 多选框选中数据 */
|
|
|
|
|
|
handleSelectionChange(selection) {
|
2025-09-01 18:33:42 +08:00
|
|
|
|
if (this.config && this.config['tableKey']) {
|
|
|
|
|
|
this.selectList = [];
|
|
|
|
|
|
this.ids = [];
|
|
|
|
|
|
if (this.isProcessing) return;
|
|
|
|
|
|
this.isProcessing = true;
|
|
|
|
|
|
// 当选中行有关联值时,默认把所关联的的行选中
|
|
|
|
|
|
selection.forEach(res => {
|
|
|
|
|
|
if (res && res.relevance) {
|
|
|
|
|
|
let selArr = [res];
|
|
|
|
|
|
Object.keys(res.relevance).forEach(item => {
|
|
|
|
|
|
res.relevance[item].forEach(val => {
|
|
|
|
|
|
this.tableList.some(tabVal => {
|
|
|
|
|
|
if (tabVal[item] === val) {
|
|
|
|
|
|
selArr.push(tabVal);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-08-27 17:54:46 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-09-01 18:33:42 +08:00
|
|
|
|
this.selectList = this.selectList.concat(selArr);
|
|
|
|
|
|
this.ids = this.ids.concat(selArr.map(item => item.id));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (!this.ids.includes(res.id)) {
|
|
|
|
|
|
this.selectList = this.selectList.concat(res);
|
|
|
|
|
|
this.ids = this.ids.concat(res.id);
|
|
|
|
|
|
}
|
2025-08-27 17:54:46 +08:00
|
|
|
|
}
|
2025-09-01 18:33:42 +08:00
|
|
|
|
});
|
|
|
|
|
|
this.selectList.forEach(val => {
|
2025-09-24 20:58:25 +08:00
|
|
|
|
this.$refs[`tableRef_${this.config.tableKey}`].toggleRowSelection(val,true);
|
2025-09-01 18:33:42 +08:00
|
|
|
|
});
|
2025-09-28 19:02:28 +08:00
|
|
|
|
this.isProcessing = false;
|
2025-09-01 18:33:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.selectList = selection;
|
|
|
|
|
|
this.ids = selection.map(item => item.id);
|
|
|
|
|
|
}
|
2025-08-27 17:54:46 +08:00
|
|
|
|
},
|
2025-09-24 20:58:25 +08:00
|
|
|
|
// 全选按钮操作
|
|
|
|
|
|
handleSelectAll(tabAll){
|
|
|
|
|
|
// 资源监控策略和资源监控模块使用 selectable: 控制列是否可选,值为false则不可选--this.config.selectable为判断
|
|
|
|
|
|
if (this.config && this.config.tableKey && this.config.selectable === true) {
|
|
|
|
|
|
if (tabAll && tabAll.length > 0) {
|
|
|
|
|
|
this.defaultSelectRows([]); // 取消全选
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.selectAllRows(); // 全选
|
|
|
|
|
|
}
|
2025-09-28 19:02:28 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (tabAll && tabAll.length > 0) {
|
|
|
|
|
|
this.selectList = tabAll;
|
|
|
|
|
|
this.ids = tabAll.map(tabId => tabId.id);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 清空
|
|
|
|
|
|
this.selectList = [];
|
|
|
|
|
|
this.ids = [];
|
|
|
|
|
|
}
|
2025-09-24 20:58:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-09-01 18:33:42 +08:00
|
|
|
|
// 提供给父组件调用的方法:返回当前表格的选中数据 资源监控策略和资源监控模块使用
|
2025-08-27 17:54:46 +08:00
|
|
|
|
getSelectedData() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
tableKey: this.config.tableKey, // 表格唯一标识
|
|
|
|
|
|
data: [...this.selectList] // 选中的数据
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
2025-09-24 20:58:25 +08:00
|
|
|
|
// 提供给父组件调用的方法:全选所有行 资源监控策略和资源监控模块使用
|
2025-09-23 20:03:01 +08:00
|
|
|
|
selectAllRows() {
|
2025-09-24 20:58:25 +08:00
|
|
|
|
const table = this.config && this.config.tableKey ? this.$refs[`tableRef_${this.config.tableKey}`] : this.$refs.selChangeList;
|
2025-09-23 20:03:01 +08:00
|
|
|
|
if (!table) return;
|
|
|
|
|
|
// 清空现有选中状态
|
|
|
|
|
|
this.selectList = [];
|
|
|
|
|
|
this.ids = [];
|
|
|
|
|
|
// 遍历所有行,执行选中
|
|
|
|
|
|
this.tableList.forEach(row => {
|
|
|
|
|
|
// 跳过不可选的行(根据selectable配置)
|
|
|
|
|
|
// const isSelectable = !(this.config && this.config.selectable);
|
|
|
|
|
|
// if (isSelectable) {
|
|
|
|
|
|
table.toggleRowSelection(row, true); // 选中行
|
|
|
|
|
|
this.selectList.push(row); // 同步到选中列表
|
|
|
|
|
|
this.ids.push(row.id); // 同步到选中ID列表
|
|
|
|
|
|
// }
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// 提供给父组件调用的方法:默认选中值
|
|
|
|
|
|
defaultSelectRows(rows){
|
2025-09-24 20:58:25 +08:00
|
|
|
|
const tableInstance = this.config && this.config.tableKey ? this.$refs[`tableRef_${this.config.tableKey}`] : this.$refs.selChangeList;
|
2025-09-23 20:03:01 +08:00
|
|
|
|
this.selectList = [];
|
|
|
|
|
|
this.ids = [];
|
|
|
|
|
|
if (tableInstance) {
|
2025-09-24 20:58:25 +08:00
|
|
|
|
if (rows && rows.length > 0) {
|
2025-09-23 20:03:01 +08:00
|
|
|
|
rows.forEach(row => {
|
|
|
|
|
|
tableInstance.toggleRowSelection(row, true);
|
|
|
|
|
|
this.selectList.push(row);
|
|
|
|
|
|
this.ids.push(row.id);
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tableInstance.clearSelection();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-08-27 17:54:46 +08:00
|
|
|
|
renderList() {
|
|
|
|
|
|
this.$emit("fnRenderList");
|
|
|
|
|
|
},
|
2025-09-10 10:30:21 +08:00
|
|
|
|
// columns改变时触发,重新计算样式并渲染列表(解决:新增列,多选框和操作按钮错位)
|
|
|
|
|
|
columnsChange() {
|
|
|
|
|
|
this.tableKey++;
|
|
|
|
|
|
},
|
2025-08-27 17:54:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|