Commit 1ab09593c1871bac6370a3b6d5cf5288f3568251

Authored by ww
1 parent fa3509a4

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

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,15 +75,34 @@
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(() => {
  95 + console.log(unref(getPaginationAttrkey));
67 96 return {
68 97 tsSubCmds: [
69 98 {
70 99 entityType: 'DEVICE',
71 100 entityId: props.deviceDetail!.tbDeviceId,
72 101 scope: 'LATEST_TELEMETRY',
73   - cmdId: 1,
74   - keys: socketInfo.attrKeys.map((item) => item.identifier).join(','),
  102 + cmdId: socketInfo.cmdId,
  103 + keys: unref(getPaginationAttrkey)
  104 + .map((item) => item.identifier)
  105 + .join(','),
75 106 },
76 107 ],
77 108 };
... ... @@ -116,10 +147,19 @@
116 147 const [registerTable, { setTableData }] = useTable({
117 148 columns: realTimeDataColumns,
118 149 showTableSetting: true,
  150 + pagination: pagination as any,
119 151 bordered: true,
120 152 showIndexColumn: false,
121 153 });
122 154
  155 + function handleChange(page: number, pageSize: number) {
  156 + pagination.current = page;
  157 + pagination.pageSize = pageSize;
  158 + send(JSON.stringify(createUnsubscribeMessage(socketInfo.cmdId)));
  159 + socketInfo.cmdId = socketInfo.cmdId + 1;
  160 + send(JSON.stringify(unref(getSendValue)));
  161 + }
  162 +
123 163 const [registerModal, { openModal }] = useModal();
124 164
125 165 const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD);
... ... @@ -127,7 +167,7 @@
127 167 const switchMode = async (value: EnumTableCardMode) => {
128 168 mode.value = value;
129 169 await nextTick();
130   - setTableData(socketInfo.dataSource);
  170 + setTableData(socketInfo.originData);
131 171 };
132 172
133 173 const { createMessage } = useMessage();
... ... @@ -242,13 +282,24 @@
242 282 } as ModalParamsType);
243 283 };
244 284
  285 + onMounted(() => {
  286 + const element = unref(listElRef)?.$el;
  287 + if (!element) return;
  288 + const totalHeight = document.documentElement.clientHeight;
  289 + const { top } = element?.getBoundingClientRect() || {};
  290 + const containerEl = element.querySelector('.ant-spin-container') as HTMLDivElement;
  291 + containerEl.style.height = `${totalHeight - top - 20 - 50}px`;
  292 + containerEl.style.overflowY = 'auto';
  293 + containerEl.style.overflowX = 'hidden';
  294 + });
  295 +
245 296 onUnmounted(() => close());
246 297 </script>
247 298
248 299 <template>
249 300 <PageWrapper
250 301 dense
251   - content-class="flex flex-col bg-transparent p-4 bg-neutral-100 dark:text-gray-300 dark:bg-dark-700"
  302 + content-class="flex flex-col p-4 dark:text-gray-300 dark:bg-dark-700 bg-gray-100"
252 303 >
253 304 <section
254 305 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 +317,11 @@
266 317 </div>
267 318 <List
268 319 v-if="mode === EnumTableCardMode.CARD"
  320 + ref="listElRef"
269 321 class="list-mode !px-2"
270   - :data-source="socketInfo.dataSource"
  322 + :data-source="socketInfo.originData"
271 323 :grid="grid"
  324 + :pagination="pagination"
272 325 >
273 326 <template #renderItem="{ item }">
274 327 <List.Item>
... ... @@ -279,11 +332,6 @@
279 332 <template #extra>
280 333 <Space>
281 334 <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 335 <SvgIcon
288 336 name="send-command"
289 337 prefix="iconfont"
... ...