Commit 64868c79d80d0c6b8215a8f0fb36944f2c1d3de6

Authored by ww
1 parent 8e3c8434

feat: 设备列表新增公开设备和私有设备操作

... ... @@ -36,6 +36,10 @@ enum DeviceManagerApi {
36 36 GATEWAY_DEVICE = '/device/gateway/list',
37 37
38 38 DEVICE_STATE_LOG_URL = '/device/state/log',
  39 +
  40 + DEVICE_PUBLIC = '/customer/public/device',
  41 +
  42 + DEVICE_PRIVATE = '/customer/device',
39 43 }
40 44
41 45 export const devicePage = (params: DeviceQueryParam) => {
... ... @@ -308,3 +312,21 @@ export const deviceStateLogPost = (data) => {
308 312 // }
309 313 );
310 314 };
  315 +
  316 +export const publicDevice = (tbDeviceId: string) => {
  317 + return defHttp.post(
  318 + {
  319 + url: `${DeviceManagerApi.DEVICE_PUBLIC}/${tbDeviceId}`,
  320 + },
  321 + { joinPrefix: false }
  322 + );
  323 +};
  324 +
  325 +export const privateDevice = (tbDeviceId: string) => {
  326 + return defHttp.delete(
  327 + {
  328 + url: `${DeviceManagerApi.DEVICE_PRIVATE}/${tbDeviceId}`,
  329 + },
  330 + { joinPrefix: false }
  331 + );
  332 +};
... ...
... ... @@ -186,6 +186,9 @@ export interface DeviceRecord {
186 186 name: string;
187 187 transportType: string;
188 188 };
  189 + customerAdditionalInfo?: {
  190 + isPublic?: boolean;
  191 + };
189 192 }
190 193
191 194 export interface DeviceModelOfMatterAttrs {
... ...
... ... @@ -15,6 +15,8 @@ export enum ConfigurationPermission {
15 15 DELETE = 'api:yt:configuration:center:delete',
16 16 DESIGN = 'api:yt:configuration:center:get_configuration_info:design',
17 17 PREVIEW = 'api:yt:configuration:center:get_configuration_info:preview',
  18 + SHARE = 'api:yt:configuration:center:share',
  19 + UN_SHARE = 'api:yt:configuration:center:monopoly',
18 20 }
19 21
20 22 export const PC_DEFAULT_CONTENT =
... ...
1 1 import { formatToDate } from '/@/utils/dateUtil';
2 2 import { BasicColumn } from '/@/components/Table';
3 3 import { FormSchema } from '/@/components/Table';
4   -import { DeviceTypeEnum, DeviceState } from '/@/api/device/model/deviceModel';
  4 +import { DeviceTypeEnum, DeviceState, DeviceRecord } from '/@/api/device/model/deviceModel';
5 5 import { deviceProfile } from '/@/api/device/deviceManager';
  6 +import { h } from 'vue';
  7 +import { Tag } from 'ant-design-vue';
6 8
7 9 // 表格列数据
8 10 export const columns: BasicColumn[] = [
... ... @@ -50,9 +52,13 @@ export const columns: BasicColumn[] = [
50 52 width: 100,
51 53 },
52 54 {
53   - title: '标签',
54   - dataIndex: 'label',
  55 + title: '公开',
  56 + dataIndex: 'public',
55 57 width: 100,
  58 + customRender({ record }: { record: DeviceRecord }) {
  59 + const flag = record?.customerAdditionalInfo?.isPublic;
  60 + return h(Tag, { color: flag ? 'blue' : 'orange' }, () => (flag ? '公开' : '私有'));
  61 + },
56 62 },
57 63 {
58 64 title: '最后连接时间',
... ...
... ... @@ -146,6 +146,13 @@
146 146 onClick: handleDispatchCustomer.bind(null, record),
147 147 },
148 148 {
  149 + label: record?.customerAdditionalInfo?.isPublic ? '私有' : '公开',
  150 + icon: record?.customerAdditionalInfo?.isPublic
  151 + ? 'ant-design:lock-outlined'
  152 + : 'ant-design:unlock-outlined',
  153 + onClick: handlePublicDevice.bind(null, record),
  154 + },
  155 + {
149 156 label: '上下线记录',
150 157 icon: 'ant-design:rise-outlined',
151 158 onClick: handleUpAndDownRecord.bind(null, record),
... ... @@ -198,6 +205,8 @@
198 205 checkDeviceOccupied,
199 206 cancelDispatchCustomer,
200 207 getGATEWAY,
  208 + privateDevice,
  209 + publicDevice,
201 210 } from '/@/api/device/deviceManager';
202 211 import { PageEnum } from '/@/enums/pageEnum';
203 212 import { useGo } from '/@/hooks/web/usePage';
... ... @@ -218,6 +227,7 @@
218 227 import { Authority } from '/@/components/Authority';
219 228 import { useRoute, useRouter } from 'vue-router';
220 229 import { useBatchOperation } from '/@/utils/useBatchOperation';
  230 + import { useSyncConfirm } from '/@/hooks/component/useSyncConfirm';
221 231
222 232 export default defineComponent({
223 233 name: 'DeviceManagement',
... ... @@ -440,6 +450,28 @@
440 450 reload();
441 451 };
442 452
  453 + const { createSyncConfirm } = useSyncConfirm();
  454 + const handlePublicDevice = async (record: DeviceRecord) => {
  455 + try {
  456 + const publicFlag = record?.customerAdditionalInfo?.isPublic;
  457 + const type = publicFlag ? '私有' : '公开';
  458 + const flag = await createSyncConfirm({
  459 + iconType: 'warning',
  460 + title: `您确定要将设备 '${record.name}' 设为${type}吗?`,
  461 + content: `确认后,设备及其所有数据将被设为${type}并${
  462 + publicFlag ? '不' : ''
  463 + }可被其他人访问。`,
  464 + });
  465 + if (!flag) return;
  466 + if (publicFlag) {
  467 + await privateDevice(record.tbDeviceId);
  468 + } else {
  469 + await publicDevice(record.tbDeviceId);
  470 + }
  471 + reload();
  472 + } catch (error) {}
  473 + };
  474 +
443 475 onMounted(() => {
444 476 const queryParams = ROUTE.query as Record<'deviceProfileId', undefined | string>;
445 477 const { setFieldsValue } = getForm();
... ... @@ -479,6 +511,7 @@
479 511 registerImportModal,
480 512 handleBatchImport,
481 513 handleImportFinally,
  514 + handlePublicDevice,
482 515 };
483 516 },
484 517 });
... ...