Commit 9e208411a24d4ccc9306555cc45aa7135d0df78f
1 parent
5a3861b9
feat(demo): add permission table demo
Showing
5 changed files
with
141 additions
and
0 deletions
src/locales/lang/en/routes/demo/table.ts
@@ -16,4 +16,5 @@ export default { | @@ -16,4 +16,5 @@ export default { | ||
16 | footerTable: 'Footer', | 16 | footerTable: 'Footer', |
17 | editCellTable: 'Editable cell', | 17 | editCellTable: 'Editable cell', |
18 | editRowTable: 'Editable row', | 18 | editRowTable: 'Editable row', |
19 | + authColumn: 'Auth column', | ||
19 | }; | 20 | }; |
src/locales/lang/zh_CN/routes/demo/table.ts
src/router/menus/modules/demo/comp.ts
@@ -118,6 +118,10 @@ const menu: MenuModule = { | @@ -118,6 +118,10 @@ const menu: MenuModule = { | ||
118 | path: 'editRowTable', | 118 | path: 'editRowTable', |
119 | name: t('routes.demo.table.editRowTable'), | 119 | name: t('routes.demo.table.editRowTable'), |
120 | }, | 120 | }, |
121 | + { | ||
122 | + path: 'authColumn', | ||
123 | + name: t('routes.demo.table.authColumn'), | ||
124 | + }, | ||
121 | ], | 125 | ], |
122 | }, | 126 | }, |
123 | { | 127 | { |
src/router/routes/modules/demo/comp.ts
@@ -230,6 +230,14 @@ const comp: AppRouteModule = { | @@ -230,6 +230,14 @@ const comp: AppRouteModule = { | ||
230 | title: t('routes.demo.table.editRowTable'), | 230 | title: t('routes.demo.table.editRowTable'), |
231 | }, | 231 | }, |
232 | }, | 232 | }, |
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 | + }, | ||
233 | ], | 241 | ], |
234 | }, | 242 | }, |
235 | { | 243 | { |
src/views/demo/table/AuthColumn.vue
0 → 100644
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> |