...
|
...
|
@@ -14,13 +14,21 @@ |
14
|
14
|
title="您确定要批量删除数据"
|
15
|
15
|
ok-text="确定"
|
16
|
16
|
cancel-text="取消"
|
17
|
|
- @confirm="handleDeleteOrBatchDelete(null)"
|
|
17
|
+ @confirm="handleDelete()"
|
18
|
18
|
>
|
19
|
|
- <a-button color="error" v-if="authBtn(role)" :disabled="hasBatchDelete">
|
|
19
|
+ <a-button color="error" v-if="authBtn(role)" :disabled="!isExistOption">
|
20
|
20
|
批量删除
|
21
|
21
|
</a-button>
|
22
|
22
|
</Popconfirm>
|
23
|
23
|
</Authority>
|
|
24
|
+ <a-button
|
|
25
|
+ v-if="authBtn(role)"
|
|
26
|
+ type="primary"
|
|
27
|
+ @click="handleBatchAssign"
|
|
28
|
+ :disabled="!isExistOption"
|
|
29
|
+ >
|
|
30
|
+ 批量分配
|
|
31
|
+ </a-button>
|
24
|
32
|
</template>
|
25
|
33
|
<template #img="{ record }">
|
26
|
34
|
<TableImg
|
...
|
...
|
@@ -147,7 +155,7 @@ |
147
|
155
|
color: 'error',
|
148
|
156
|
popConfirm: {
|
149
|
157
|
title: '是否确认删除',
|
150
|
|
- confirm: handleDeleteOrBatchDelete.bind(null, record),
|
|
158
|
+ confirm: handleDelete.bind(null, record),
|
151
|
159
|
},
|
152
|
160
|
},
|
153
|
161
|
]"
|
...
|
...
|
@@ -170,7 +178,12 @@ |
170
|
178
|
</template>
|
171
|
179
|
<script lang="ts">
|
172
|
180
|
import { defineComponent, reactive, unref, nextTick, h, onUnmounted, ref } from 'vue';
|
173
|
|
- import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
|
|
181
|
+ import {
|
|
182
|
+ DeviceModel,
|
|
183
|
+ DeviceRecord,
|
|
184
|
+ DeviceState,
|
|
185
|
+ DeviceTypeEnum,
|
|
186
|
+ } from '/@/api/device/model/deviceModel';
|
174
|
187
|
import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table';
|
175
|
188
|
import { columns, searchFormSchema } from './config/device.data';
|
176
|
189
|
import { Tag, Tooltip, Popover, Popconfirm } from 'ant-design-vue';
|
...
|
...
|
@@ -194,11 +207,11 @@ |
194
|
207
|
import { USER_INFO_KEY } from '/@/enums/cacheEnum';
|
195
|
208
|
import { getAuthCache } from '/@/utils/auth';
|
196
|
209
|
import { authBtn } from '/@/enums/roleEnum';
|
197
|
|
- import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
|
198
|
210
|
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
|
199
|
211
|
import { QuestionCircleOutlined } from '@ant-design/icons-vue';
|
200
|
212
|
import { Authority } from '/@/components/Authority';
|
201
|
213
|
import { useRouter } from 'vue-router';
|
|
214
|
+ import { useBatchOperation } from '/@/utils/useBatchOperation';
|
202
|
215
|
|
203
|
216
|
export default defineComponent({
|
204
|
217
|
name: 'DeviceManagement',
|
...
|
...
|
@@ -233,7 +246,17 @@ |
233
|
246
|
|
234
|
247
|
const [
|
235
|
248
|
registerTable,
|
236
|
|
- { reload, setSelectedRowKeys, setProps, setTableData, getForm, setPagination },
|
|
249
|
+ {
|
|
250
|
+ reload,
|
|
251
|
+ setLoading,
|
|
252
|
+ setSelectedRowKeys,
|
|
253
|
+ setTableData,
|
|
254
|
+ getForm,
|
|
255
|
+ setPagination,
|
|
256
|
+ getSelectRowKeys,
|
|
257
|
+ getSelectRows,
|
|
258
|
+ getRowSelection,
|
|
259
|
+ },
|
237
|
260
|
] = useTable({
|
238
|
261
|
title: '设备列表',
|
239
|
262
|
api: devicePage,
|
...
|
...
|
@@ -241,7 +264,6 @@ |
241
|
264
|
columns,
|
242
|
265
|
beforeFetch: (params) => {
|
243
|
266
|
const { deviceProfileId } = params;
|
244
|
|
- console.log(deviceProfileId);
|
245
|
267
|
const obj = {
|
246
|
268
|
...params,
|
247
|
269
|
...{
|
...
|
...
|
@@ -272,21 +294,16 @@ |
272
|
294
|
slots: { customRender: 'action' },
|
273
|
295
|
fixed: 'right',
|
274
|
296
|
},
|
275
|
|
- });
|
276
|
|
- const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
|
277
|
|
- useBatchDelete(deleteDevice, handleSuccess, setProps);
|
278
|
|
- selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
|
279
|
|
- // Demo:status为1的选择框禁用
|
280
|
|
- if (record.customerId) {
|
281
|
|
- return { disabled: true };
|
282
|
|
- } else {
|
283
|
|
- return { disabled: false };
|
284
|
|
- }
|
285
|
|
- };
|
286
|
|
- nextTick(() => {
|
287
|
|
- setProps(selectionOptions);
|
|
297
|
+ rowSelection: {
|
|
298
|
+ type: 'checkbox',
|
|
299
|
+ getCheckboxProps: (record: DeviceModel) => {
|
|
300
|
+ return { disabled: !!record.customerId };
|
|
301
|
+ },
|
|
302
|
+ },
|
288
|
303
|
});
|
289
|
304
|
|
|
305
|
+ const { isExistOption } = useBatchOperation(getRowSelection, setSelectedRowKeys);
|
|
306
|
+
|
290
|
307
|
function getParams(keyword) {
|
291
|
308
|
const reg = new RegExp('(^|&)' + keyword + '=([^&]*)(&|$)', 'i');
|
292
|
309
|
const r = window.location.search.substr(1).match(reg);
|
...
|
...
|
@@ -349,7 +366,6 @@ |
349
|
366
|
}
|
350
|
367
|
function handleReload() {
|
351
|
368
|
setSelectedRowKeys([]);
|
352
|
|
- resetSelectedRowKeys();
|
353
|
369
|
handleSuccess();
|
354
|
370
|
}
|
355
|
371
|
// 取消分配客户
|
...
|
...
|
@@ -419,6 +435,48 @@ |
419
|
435
|
});
|
420
|
436
|
};
|
421
|
437
|
|
|
438
|
+ const handleCheckHasDiffenterOrg = (options: DeviceModel[]) => {
|
|
439
|
+ let orgId: string | undefined;
|
|
440
|
+ let flag = false;
|
|
441
|
+ for (const item of options) {
|
|
442
|
+ const _orgId = item.organizationId;
|
|
443
|
+ if (!orgId) orgId = _orgId;
|
|
444
|
+ if (orgId !== _orgId) {
|
|
445
|
+ flag = true;
|
|
446
|
+ break;
|
|
447
|
+ }
|
|
448
|
+ }
|
|
449
|
+ return flag;
|
|
450
|
+ };
|
|
451
|
+
|
|
452
|
+ const handleBatchAssign = () => {
|
|
453
|
+ const options = getSelectRows();
|
|
454
|
+ if (handleCheckHasDiffenterOrg(options)) {
|
|
455
|
+ createMessage.error('当前选中项中存在不同所属组织的设备!');
|
|
456
|
+ return;
|
|
457
|
+ }
|
|
458
|
+ openCustomerModal(true, options);
|
|
459
|
+ };
|
|
460
|
+
|
|
461
|
+ const handleDelete = async (record?: DeviceRecord) => {
|
|
462
|
+ let ids: string[] = [];
|
|
463
|
+ if (record) {
|
|
464
|
+ ids.push(record.id);
|
|
465
|
+ } else {
|
|
466
|
+ ids = getSelectRowKeys();
|
|
467
|
+ }
|
|
468
|
+ try {
|
|
469
|
+ setLoading(true);
|
|
470
|
+ await deleteDevice(ids);
|
|
471
|
+ createMessage.success('删除成功');
|
|
472
|
+ handleReload();
|
|
473
|
+ } catch (error) {
|
|
474
|
+ createMessage.error('删除失败');
|
|
475
|
+ } finally {
|
|
476
|
+ setLoading(false);
|
|
477
|
+ }
|
|
478
|
+ };
|
|
479
|
+
|
422
|
480
|
return {
|
423
|
481
|
registerTable,
|
424
|
482
|
handleCreate,
|
...
|
...
|
@@ -439,14 +497,17 @@ |
439
|
497
|
authBtn,
|
440
|
498
|
role,
|
441
|
499
|
copySN,
|
442
|
|
- hasBatchDelete,
|
443
|
|
- handleDeleteOrBatchDelete,
|
|
500
|
+ isExistOption,
|
|
501
|
+ handleDelete,
|
|
502
|
+ // hasBatchDelete,
|
|
503
|
+ // handleDeleteOrBatchDelete,
|
444
|
504
|
handleReload,
|
445
|
505
|
registerTbDetailDrawer,
|
446
|
506
|
handleOpenTbDeviceDetail,
|
447
|
507
|
handleOpenGatewayDetail,
|
448
|
508
|
registerGatewayDetailDrawer,
|
449
|
509
|
handleUpAndDownRecord,
|
|
510
|
+ handleBatchAssign,
|
450
|
511
|
};
|
451
|
512
|
},
|
452
|
513
|
});
|
...
|
...
|
|