Skip to content

Commit 9e20841

Browse files
committed
feat(demo): add permission table demo
1 parent 5a3861b commit 9e20841

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

src/locales/lang/en/routes/demo/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export default {
1616
footerTable: 'Footer',
1717
editCellTable: 'Editable cell',
1818
editRowTable: 'Editable row',
19+
authColumn: 'Auth column',
1920
};

src/locales/lang/zh_CN/routes/demo/table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export default {
1616
footerTable: '表尾行合计',
1717
editCellTable: '可编辑单元格',
1818
editRowTable: '可编辑行',
19+
authColumn: '权限列',
1920
};

src/router/menus/modules/demo/comp.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ const menu: MenuModule = {
118118
path: 'editRowTable',
119119
name: t('routes.demo.table.editRowTable'),
120120
},
121+
{
122+
path: 'authColumn',
123+
name: t('routes.demo.table.authColumn'),
124+
},
121125
],
122126
},
123127
{

src/router/routes/modules/demo/comp.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ const comp: AppRouteModule = {
230230
title: t('routes.demo.table.editRowTable'),
231231
},
232232
},
233+
{
234+
path: 'authColumn',
235+
name: 'AuthColumnDemo',
236+
component: () => import('/@/views/demo/table/AuthColumn.vue'),
237+
meta: {
238+
title: t('routes.demo.table.authColumn'),
239+
},
240+
},
233241
],
234242
},
235243
{
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
2+
<div class="p-4">
3+
<BasicTable @register="registerTable">
4+
<template #action="{ record }">
5+
<TableAction
6+
:actions="[
7+
{
8+
label: '编辑',
9+
onClick: handleEdit.bind(null, record),
10+
auth: 'other', // 根据权限控制是否显示: 无权限,不显示
11+
},
12+
{
13+
label: '删除',
14+
icon: 'ic:outline-delete-outline',
15+
onClick: handleDelete.bind(null, record),
16+
auth: 'super', // 根据权限控制是否显示: 有权限,会显示
17+
},
18+
]"
19+
:dropDownActions="[
20+
{
21+
label: '启用',
22+
popConfirm: {
23+
title: '是否启用?',
24+
confirm: handleOpen.bind(null, record),
25+
},
26+
ifShow: (_action) => {
27+
return record.status !== 'enable'; // 根据业务控制是否显示: 非enable状态的不显示启用按钮
28+
},
29+
},
30+
{
31+
label: '禁用',
32+
popConfirm: {
33+
title: '是否禁用?',
34+
confirm: handleOpen.bind(null, record),
35+
},
36+
ifShow: () => {
37+
return record.status === 'enable'; // 根据业务控制是否显示: enable状态的显示禁用按钮
38+
},
39+
},
40+
{
41+
label: '同时控制',
42+
popConfirm: {
43+
title: '是否动态显示?',
44+
confirm: handleOpen.bind(null, record),
45+
},
46+
auth: 'super', // 同时根据权限和业务控制是否显示
47+
ifShow: () => {
48+
return true;
49+
},
50+
},
51+
]"
52+
/>
53+
</template>
54+
</BasicTable>
55+
</div>
56+
</template>
57+
<script lang="ts">
58+
import { defineComponent } from 'vue';
59+
import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
60+
61+
import { demoListApi } from '/@/api/demo/table';
62+
const columns: BasicColumn[] = [
63+
{
64+
title: '编号',
65+
dataIndex: 'no',
66+
width: 100,
67+
},
68+
{
69+
title: '姓名',
70+
dataIndex: 'name',
71+
auth: 'test', // 根据权限控制是否显示: 无权限,不显示
72+
},
73+
{
74+
title: '状态',
75+
dataIndex: 'status',
76+
},
77+
{
78+
title: '地址',
79+
dataIndex: 'address',
80+
auth: 'super', // 同时根据权限和业务控制是否显示
81+
ifShow: (_column) => {
82+
return true;
83+
},
84+
},
85+
{
86+
title: '开始时间',
87+
dataIndex: 'beginTime',
88+
},
89+
{
90+
title: '结束时间',
91+
dataIndex: 'endTime',
92+
width: 200,
93+
},
94+
];
95+
export default defineComponent({
96+
components: { BasicTable, TableAction },
97+
setup() {
98+
const [registerTable] = useTable({
99+
title: 'TableAction组件及固定列示例',
100+
api: demoListApi,
101+
columns: columns,
102+
bordered: true,
103+
actionColumn: {
104+
width: 250,
105+
title: 'Action',
106+
dataIndex: 'action',
107+
slots: { customRender: 'action' },
108+
},
109+
});
110+
function handleEdit(record: Recordable) {
111+
console.log('点击了编辑', record);
112+
}
113+
function handleDelete(record: Recordable) {
114+
console.log('点击了删除', record);
115+
}
116+
function handleOpen(record: Recordable) {
117+
console.log('点击了启用', record);
118+
}
119+
return {
120+
registerTable,
121+
handleEdit,
122+
handleDelete,
123+
handleOpen,
124+
};
125+
},
126+
});
127+
</script>

0 commit comments

Comments
 (0)