提交 | 用户 | age
|
f353bc
|
1 |
import { BasicColumn, FormSchema } from '@/components/Table'; |
S |
2 |
import { h } from 'vue'; |
|
3 |
import { Switch } from 'ant-design-vue'; |
|
4 |
import { setRoleStatus } from '@/api/demo/system'; |
|
5 |
import { useMessage } from '@/hooks/web/useMessage'; |
|
6 |
|
|
7 |
type CheckedType = boolean | string | number; |
|
8 |
export const columns: BasicColumn[] = [ |
|
9 |
{ |
|
10 |
title: '角色名称', |
|
11 |
dataIndex: 'roleName', |
|
12 |
width: 200, |
|
13 |
}, |
|
14 |
{ |
|
15 |
title: '角色值', |
|
16 |
dataIndex: 'roleValue', |
|
17 |
width: 180, |
|
18 |
}, |
|
19 |
{ |
|
20 |
title: '排序', |
|
21 |
dataIndex: 'orderNo', |
|
22 |
width: 50, |
|
23 |
}, |
|
24 |
{ |
|
25 |
title: '状态', |
|
26 |
dataIndex: 'status', |
|
27 |
width: 120, |
|
28 |
customRender: ({ record }) => { |
|
29 |
if (!Reflect.has(record, 'pendingStatus')) { |
|
30 |
record.pendingStatus = false; |
|
31 |
} |
|
32 |
return h(Switch, { |
|
33 |
checked: record.status === '1', |
|
34 |
checkedChildren: '停用', |
|
35 |
unCheckedChildren: '启用', |
|
36 |
loading: record.pendingStatus, |
|
37 |
onChange(checked: CheckedType) { |
|
38 |
record.pendingStatus = true; |
|
39 |
const newStatus = checked ? '1' : '0'; |
|
40 |
const { createMessage } = useMessage(); |
|
41 |
setRoleStatus(record.id, newStatus) |
|
42 |
.then(() => { |
|
43 |
record.status = newStatus; |
|
44 |
createMessage.success(`已成功修改角色状态`); |
|
45 |
}) |
|
46 |
.catch(() => { |
|
47 |
createMessage.error('修改角色状态失败'); |
|
48 |
}) |
|
49 |
.finally(() => { |
|
50 |
record.pendingStatus = false; |
|
51 |
}); |
|
52 |
}, |
|
53 |
}); |
|
54 |
}, |
|
55 |
}, |
|
56 |
{ |
|
57 |
title: '创建时间', |
|
58 |
dataIndex: 'createTime', |
|
59 |
width: 180, |
|
60 |
}, |
|
61 |
{ |
|
62 |
title: '备注', |
|
63 |
dataIndex: 'remark', |
|
64 |
}, |
|
65 |
]; |
|
66 |
|
|
67 |
export const searchFormSchema: FormSchema[] = [ |
|
68 |
{ |
|
69 |
field: 'roleNme', |
|
70 |
label: '角色名称', |
|
71 |
component: 'Input', |
|
72 |
colProps: { span: 8 }, |
|
73 |
}, |
|
74 |
{ |
|
75 |
field: 'status', |
|
76 |
label: '状态', |
|
77 |
component: 'Select', |
|
78 |
componentProps: { |
|
79 |
options: [ |
|
80 |
{ label: '启用', value: '1' }, |
|
81 |
{ label: '停用', value: '0' }, |
|
82 |
], |
|
83 |
}, |
|
84 |
colProps: { span: 8 }, |
|
85 |
}, |
|
86 |
]; |
|
87 |
|
|
88 |
export const formSchema: FormSchema[] = [ |
|
89 |
{ |
|
90 |
field: 'roleName', |
|
91 |
label: '角色名称', |
|
92 |
required: true, |
|
93 |
component: 'Input', |
|
94 |
}, |
|
95 |
{ |
|
96 |
field: 'roleValue', |
|
97 |
label: '角色值', |
|
98 |
required: true, |
|
99 |
component: 'Input', |
|
100 |
}, |
|
101 |
{ |
|
102 |
field: 'status', |
|
103 |
label: '状态', |
|
104 |
component: 'RadioButtonGroup', |
|
105 |
defaultValue: '0', |
|
106 |
componentProps: { |
|
107 |
options: [ |
|
108 |
{ label: '启用', value: '1' }, |
|
109 |
{ label: '停用', value: '0' }, |
|
110 |
], |
|
111 |
}, |
|
112 |
}, |
|
113 |
{ |
|
114 |
label: '备注', |
|
115 |
field: 'remark', |
|
116 |
component: 'InputTextArea', |
|
117 |
}, |
|
118 |
{ |
|
119 |
label: ' ', |
|
120 |
field: 'menu', |
|
121 |
slot: 'menu', |
|
122 |
}, |
|
123 |
]; |