Commit edd03aca269b1c09bf9752166ddefe346b236799

Authored by xp.Huang
2 parents c68621b8 aced671b

Merge branch 'perf/device-detail-things-model' into 'main_dev'

perf: 优化设备详情物模型数据量过大设置前端分页

See merge request yunteng/thingskit-front!786
1 1 <script lang="ts" setup>
2   - import { nextTick, onMounted, onUnmounted, reactive, ref, unref } from 'vue';
3   - import { List, Card, Tooltip, Space } from 'ant-design-vue';
  2 + import { nextTick, onMounted, onUnmounted, reactive, ref, unref, computed } from 'vue';
  3 + import { List, Card, Tooltip, Space, PaginationProps } from 'ant-design-vue';
4 4 import { PageWrapper } from '/@/components/Page';
5 5 import { BasicTable, useTable } from '/@/components/Table';
6 6 import { realTimeDataColumns } from '../../config/detail.config';
... ... @@ -14,7 +14,6 @@
14 14 import { BasicModal, useModal } from '/@/components/Modal';
15 15 import { getDeviceAttrs } from '/@/api/device/deviceManager';
16 16 import { DeviceModelOfMatterAttrs, DeviceRecord } from '/@/api/device/model/deviceModel';
17   - import { computed } from '@vue/reactivity';
18 17 import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel';
19 18 import { isArray, isObject } from '/@/utils/is';
20 19 import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config';
... ... @@ -50,11 +49,24 @@
50 49 const grid = {
51 50 gutter: 8,
52 51 column: 3,
53   - };
  52 + } as any;
54 53
  54 + const listElRef = ref<Nullable<ComponentElRef<HTMLDivElement>>>(null);
55 55 const token = getAuthCache(JWT_TOKEN_KEY);
56 56 const { socketUrl } = useGlobSetting();
  57 +
  58 + const pagination = reactive<PaginationProps>({
  59 + size: 'small',
  60 + showSizeChanger: true,
  61 + showQuickJumper: true,
  62 + hideOnSinglePage: false,
  63 + showTotal: (total: number) => `共${total}条数据`,
  64 + onChange: handleChange,
  65 + onShowSizeChange: handleChange,
  66 + });
  67 +
57 68 const socketInfo = reactive({
  69 + cmdId: 0,
58 70 origin: `${socketUrl}${token}`,
59 71 attr: undefined as string | undefined,
60 72 originData: [] as DataSource[],
... ... @@ -63,6 +75,22 @@
63 75 attrKeys: [] as DeviceModelOfMatterAttrs[],
64 76 });
65 77
  78 + const getPaginationAttrkey = computed<DeviceModelOfMatterAttrs[]>(() => {
  79 + const { current = 1, pageSize = 10 } = pagination;
  80 + return socketInfo.attrKeys.slice(current * pageSize - pageSize, current * pageSize);
  81 + });
  82 +
  83 + function createUnsubscribeMessage(cmdId: number) {
  84 + return {
  85 + tsSubCmds: [
  86 + {
  87 + cmdId,
  88 + unsubscribe: true,
  89 + },
  90 + ],
  91 + };
  92 + }
  93 +
66 94 const getSendValue = computed(() => {
67 95 return {
68 96 tsSubCmds: [
... ... @@ -70,8 +98,10 @@
70 98 entityType: 'DEVICE',
71 99 entityId: props.deviceDetail!.tbDeviceId,
72 100 scope: 'LATEST_TELEMETRY',
73   - cmdId: 1,
74   - keys: socketInfo.attrKeys.map((item) => item.identifier).join(','),
  101 + cmdId: socketInfo.cmdId,
  102 + keys: unref(getPaginationAttrkey)
  103 + .map((item) => item.identifier)
  104 + .join(','),
75 105 },
76 106 ],
77 107 };
... ... @@ -116,10 +146,19 @@
116 146 const [registerTable, { setTableData }] = useTable({
117 147 columns: realTimeDataColumns,
118 148 showTableSetting: true,
  149 + pagination: pagination as any,
119 150 bordered: true,
120 151 showIndexColumn: false,
121 152 });
122 153
  154 + function handleChange(page: number, pageSize: number) {
  155 + pagination.current = page;
  156 + pagination.pageSize = pageSize;
  157 + send(JSON.stringify(createUnsubscribeMessage(socketInfo.cmdId)));
  158 + socketInfo.cmdId = socketInfo.cmdId + 1;
  159 + send(JSON.stringify(unref(getSendValue)));
  160 + }
  161 +
123 162 const [registerModal, { openModal }] = useModal();
124 163
125 164 const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD);
... ... @@ -127,7 +166,7 @@
127 166 const switchMode = async (value: EnumTableCardMode) => {
128 167 mode.value = value;
129 168 await nextTick();
130   - setTableData(socketInfo.dataSource);
  169 + setTableData(socketInfo.originData);
131 170 };
132 171
133 172 const { createMessage } = useMessage();
... ... @@ -242,13 +281,24 @@
242 281 } as ModalParamsType);
243 282 };
244 283
  284 + onMounted(() => {
  285 + const element = unref(listElRef)?.$el;
  286 + if (!element) return;
  287 + const totalHeight = document.documentElement.clientHeight;
  288 + const { top } = element?.getBoundingClientRect() || {};
  289 + const containerEl = element.querySelector('.ant-spin-container') as HTMLDivElement;
  290 + containerEl.style.height = `${totalHeight - top - 20 - 50}px`;
  291 + containerEl.style.overflowY = 'auto';
  292 + containerEl.style.overflowX = 'hidden';
  293 + });
  294 +
245 295 onUnmounted(() => close());
246 296 </script>
247 297
248 298 <template>
249 299 <PageWrapper
250 300 dense
251   - content-class="flex flex-col bg-transparent p-4 bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"
  301 + content-class="flex flex-col p-4 dark:text-gray-300 dark:bg-dark-700 bg-gray-100"
252 302 >
253 303 <section
254 304 class="flex flex-col justify-between w-full bg-light-50 pt-3 mb-4 dark:text-gray-300 dark:bg-dark-900"
... ... @@ -266,9 +316,11 @@
266 316 </div>
267 317 <List
268 318 v-if="mode === EnumTableCardMode.CARD"
  319 + ref="listElRef"
269 320 class="list-mode !px-2"
270   - :data-source="socketInfo.dataSource"
  321 + :data-source="socketInfo.originData"
271 322 :grid="grid"
  323 + :pagination="pagination"
272 324 >
273 325 <template #renderItem="{ item }">
274 326 <List.Item>
... ... @@ -279,11 +331,6 @@
279 331 <template #extra>
280 332 <Space>
281 333 <Tooltip title="属性下发">
282   - <!-- <MacCommandOutlined
283   - v-if="ReadAndWriteEnum.READ_AND_WRITE === item.accessMode"
284   - class="cursor-pointer text-lg svg:fill-blue-500"
285   - @click="handleSendCommandModal(item)"
286   - /> -->
287 334 <SvgIcon
288 335 name="send-command"
289 336 prefix="iconfont"
... ...