Showing
1 changed file
with
87 additions
and
6 deletions
| 1 | <template> | 1 | <template> | 
| 2 | <div class="bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"> | 2 | <div class="bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"> | 
| 3 | <BasicTable @register="registerTable"> | 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 | <template #tbDeviceName="{ record }"> | 17 | <template #tbDeviceName="{ record }"> | 
| 5 | <div style="color: #619eff" class="cursor-pointer" @click="handleGetTbDeviceId(record)"> | 18 | <div style="color: #619eff" class="cursor-pointer" @click="handleGetTbDeviceId(record)"> | 
| 6 | {{ record.alias || record.tbDeviceName }} | 19 | {{ record.alias || record.tbDeviceName }} | 
| @@ -26,22 +39,44 @@ | @@ -26,22 +39,44 @@ | ||
| 26 | }} | 39 | }} | 
| 27 | </Tag> | 40 | </Tag> | 
| 28 | </template> | 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 | </BasicTable> | 57 | </BasicTable> | 
| 30 | </div> | 58 | </div> | 
| 31 | </template> | 59 | </template> | 
| 32 | <script lang="ts"> | 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 | import { getTbDeviceId } from '/@/api/device/deviceConfigApi'; | 64 | import { getTbDeviceId } from '/@/api/device/deviceConfigApi'; | 
| 37 | - import { BasicTable, useTable } from '/@/components/Table'; | 65 | + import { BasicTable, useTable, TableAction } from '/@/components/Table'; | 
| 38 | import { childDeviceColumns, childDeviceSchemas } from '../../config/detail.config'; | 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 | export default defineComponent({ | 71 | export default defineComponent({ | 
| 41 | name: 'DeviceManagement', | 72 | name: 'DeviceManagement', | 
| 42 | components: { | 73 | components: { | 
| 43 | BasicTable, | 74 | BasicTable, | 
| 75 | + Popconfirm, | ||
| 44 | Tag, | 76 | Tag, | 
| 77 | + TableAction, | ||
| 78 | + Authority, | ||
| 79 | + Button, | ||
| 45 | }, | 80 | }, | 
| 46 | props: { | 81 | props: { | 
| 47 | fromId: { | 82 | fromId: { | 
| @@ -51,7 +86,7 @@ | @@ -51,7 +86,7 @@ | ||
| 51 | }, | 86 | }, | 
| 52 | emits: ['openTbDeviceDetail'], | 87 | emits: ['openTbDeviceDetail'], | 
| 53 | setup(props, { emit }) { | 88 | setup(props, { emit }) { | 
| 54 | - const [registerTable] = useTable({ | 89 | + const [registerTable, { getSelectRowKeys, reload, setLoading }] = useTable({ | 
| 55 | api: getChildDevicePage, | 90 | api: getChildDevicePage, | 
| 56 | columns: childDeviceColumns, | 91 | columns: childDeviceColumns, | 
| 57 | formConfig: { | 92 | formConfig: { | 
| @@ -61,12 +96,35 @@ | @@ -61,12 +96,35 @@ | ||
| 61 | beforeFetch: (data) => { | 96 | beforeFetch: (data) => { | 
| 62 | Reflect.set(data, 'fromId', props.fromId); | 97 | Reflect.set(data, 'fromId', props.fromId); | 
| 63 | }, | 98 | }, | 
| 99 | + rowKey: 'id', | ||
| 64 | useSearchForm: true, | 100 | useSearchForm: true, | 
| 65 | showTableSetting: true, | 101 | showTableSetting: true, | 
| 66 | bordered: true, | 102 | bordered: true, | 
| 67 | showIndexColumn: false, | 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 | const handleGetTbDeviceId = async (record) => { | 128 | const handleGetTbDeviceId = async (record) => { | 
| 71 | try { | 129 | try { | 
| 72 | const res = await getTbDeviceId(record.tbDeviceId); | 130 | const res = await getTbDeviceId(record.tbDeviceId); | 
| @@ -75,10 +133,33 @@ | @@ -75,10 +133,33 @@ | ||
| 75 | } | 133 | } | 
| 76 | } catch (error) {} | 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 | return { | 156 | return { | 
| 79 | registerTable, | 157 | registerTable, | 
| 80 | DeviceState, | 158 | DeviceState, | 
| 81 | handleGetTbDeviceId, | 159 | handleGetTbDeviceId, | 
| 160 | + DeviceListAuthEnum, | ||
| 161 | + handleDelete, | ||
| 162 | + disabledDeleteFlag, | ||
| 82 | }; | 163 | }; | 
| 83 | }, | 164 | }, | 
| 84 | }); | 165 | }); |