Commit ba503b7bdc5e52155f210fd52ce0993409f8defb
Merge branch 'feat/device/modal-add-delete' into 'main_dev'
feat: 设备详情子设备添加和删除 See merge request yunteng/thingskit-front!1329
Showing
1 changed file
with
87 additions
and
6 deletions
1 | 1 | <template> |
2 | 2 | <div class="bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"> |
3 | 3 | <BasicTable @register="registerTable"> |
4 | + <template #toolbar> | |
5 | + <Authority :value="DeviceListAuthEnum.DELETE"> | |
6 | + <Popconfirm | |
7 | + title="您确定要批量删除数据" | |
8 | + ok-text="确定" | |
9 | + cancel-text="取消" | |
10 | + @confirm="handleDelete()" | |
11 | + :disabled="disabledDeleteFlag" | |
12 | + > | |
13 | + <Button type="primary" danger :disabled="disabledDeleteFlag"> 批量删除 </Button> | |
14 | + </Popconfirm> | |
15 | + </Authority> | |
16 | + </template> | |
4 | 17 | <template #tbDeviceName="{ record }"> |
5 | 18 | <div style="color: #619eff" class="cursor-pointer" @click="handleGetTbDeviceId(record)"> |
6 | 19 | {{ record.alias || record.tbDeviceName }} |
... | ... | @@ -26,22 +39,44 @@ |
26 | 39 | }} |
27 | 40 | </Tag> |
28 | 41 | </template> |
42 | + <template #action="{ record }"> | |
43 | + <TableAction | |
44 | + :actions="[ | |
45 | + { | |
46 | + label: '删除', | |
47 | + auth: DeviceListAuthEnum.DETAIL, | |
48 | + icon: 'ant-design:eye-outlined', | |
49 | + popConfirm: { | |
50 | + title: '是否确认删除', | |
51 | + confirm: handleDelete.bind(null, record), | |
52 | + }, | |
53 | + }, | |
54 | + ]" | |
55 | + /> | |
56 | + </template> | |
29 | 57 | </BasicTable> |
30 | 58 | </div> |
31 | 59 | </template> |
32 | 60 | <script lang="ts"> |
33 | - import { defineComponent } from 'vue'; | |
34 | - import { Tag } from 'ant-design-vue'; | |
35 | - import { DeviceState } from '/@/api/device/model/deviceModel'; | |
61 | + import { defineComponent, ref } from 'vue'; | |
62 | + import { Tag, Button, Popconfirm } from 'ant-design-vue'; | |
63 | + import { DeviceRecord, DeviceState } from '/@/api/device/model/deviceModel'; | |
36 | 64 | import { getTbDeviceId } from '/@/api/device/deviceConfigApi'; |
37 | - import { BasicTable, useTable } from '/@/components/Table'; | |
65 | + import { BasicTable, useTable, TableAction } from '/@/components/Table'; | |
38 | 66 | import { childDeviceColumns, childDeviceSchemas } from '../../config/detail.config'; |
39 | - import { getChildDevicePage } from '/@/api/device/deviceManager'; | |
67 | + import { deleteDevice, getChildDevicePage } from '/@/api/device/deviceManager'; | |
68 | + import { DeviceListAuthEnum } from '../../config/device.data'; | |
69 | + import { Authority } from '/@/components/Authority'; | |
70 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
40 | 71 | export default defineComponent({ |
41 | 72 | name: 'DeviceManagement', |
42 | 73 | components: { |
43 | 74 | BasicTable, |
75 | + Popconfirm, | |
44 | 76 | Tag, |
77 | + TableAction, | |
78 | + Authority, | |
79 | + Button, | |
45 | 80 | }, |
46 | 81 | props: { |
47 | 82 | fromId: { |
... | ... | @@ -51,7 +86,7 @@ |
51 | 86 | }, |
52 | 87 | emits: ['openTbDeviceDetail'], |
53 | 88 | setup(props, { emit }) { |
54 | - const [registerTable] = useTable({ | |
89 | + const [registerTable, { getSelectRowKeys, reload, setLoading }] = useTable({ | |
55 | 90 | api: getChildDevicePage, |
56 | 91 | columns: childDeviceColumns, |
57 | 92 | formConfig: { |
... | ... | @@ -61,12 +96,35 @@ |
61 | 96 | beforeFetch: (data) => { |
62 | 97 | Reflect.set(data, 'fromId', props.fromId); |
63 | 98 | }, |
99 | + rowKey: 'id', | |
64 | 100 | useSearchForm: true, |
65 | 101 | showTableSetting: true, |
66 | 102 | bordered: true, |
67 | 103 | showIndexColumn: false, |
104 | + clickToRowSelect: false, | |
105 | + actionColumn: { | |
106 | + width: 200, | |
107 | + title: '操作', | |
108 | + slots: { customRender: 'action' }, | |
109 | + fixed: 'right', | |
110 | + }, | |
111 | + | |
112 | + rowSelection: { | |
113 | + type: 'checkbox', | |
114 | + onSelect: (_record, _flag, allSelecteds) => { | |
115 | + disabledDeleteFlag.value = !allSelecteds.length; | |
116 | + }, | |
117 | + onSelectAll: () => { | |
118 | + // 全选事件 | |
119 | + disabledDeleteFlag.value = false; | |
120 | + }, | |
121 | + }, | |
68 | 122 | }); |
69 | 123 | |
124 | + const { createMessage } = useMessage(); | |
125 | + | |
126 | + const disabledDeleteFlag = ref(true); | |
127 | + | |
70 | 128 | const handleGetTbDeviceId = async (record) => { |
71 | 129 | try { |
72 | 130 | const res = await getTbDeviceId(record.tbDeviceId); |
... | ... | @@ -75,10 +133,33 @@ |
75 | 133 | } |
76 | 134 | } catch (error) {} |
77 | 135 | }; |
136 | + | |
137 | + const handleDelete = async (record?: DeviceRecord) => { | |
138 | + let ids: string[] = []; | |
139 | + if (record) { | |
140 | + ids.push(record.id); | |
141 | + } else { | |
142 | + ids = getSelectRowKeys(); | |
143 | + } | |
144 | + try { | |
145 | + setLoading(true); | |
146 | + await deleteDevice(ids); | |
147 | + createMessage.success('删除成功'); | |
148 | + reload(); | |
149 | + } catch (error) { | |
150 | + throw error; | |
151 | + } finally { | |
152 | + setLoading(false); | |
153 | + } | |
154 | + }; | |
155 | + | |
78 | 156 | return { |
79 | 157 | registerTable, |
80 | 158 | DeviceState, |
81 | 159 | handleGetTbDeviceId, |
160 | + DeviceListAuthEnum, | |
161 | + handleDelete, | |
162 | + disabledDeleteFlag, | |
82 | 163 | }; |
83 | 164 | }, |
84 | 165 | }); | ... | ... |