Commit edd03aca269b1c09bf9752166ddefe346b236799
Merge branch 'perf/device-detail-things-model' into 'main_dev'
perf: 优化设备详情物模型数据量过大设置前端分页 See merge request yunteng/thingskit-front!786
Showing
1 changed file
with
61 additions
and
14 deletions
| 1 | <script lang="ts" setup> | 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 | import { PageWrapper } from '/@/components/Page'; | 4 | import { PageWrapper } from '/@/components/Page'; |
| 5 | import { BasicTable, useTable } from '/@/components/Table'; | 5 | import { BasicTable, useTable } from '/@/components/Table'; |
| 6 | import { realTimeDataColumns } from '../../config/detail.config'; | 6 | import { realTimeDataColumns } from '../../config/detail.config'; |
| @@ -14,7 +14,6 @@ | @@ -14,7 +14,6 @@ | ||
| 14 | import { BasicModal, useModal } from '/@/components/Modal'; | 14 | import { BasicModal, useModal } from '/@/components/Modal'; |
| 15 | import { getDeviceAttrs } from '/@/api/device/deviceManager'; | 15 | import { getDeviceAttrs } from '/@/api/device/deviceManager'; |
| 16 | import { DeviceModelOfMatterAttrs, DeviceRecord } from '/@/api/device/model/deviceModel'; | 16 | import { DeviceModelOfMatterAttrs, DeviceRecord } from '/@/api/device/model/deviceModel'; |
| 17 | - import { computed } from '@vue/reactivity'; | ||
| 18 | import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | 17 | import { Specs, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| 19 | import { isArray, isObject } from '/@/utils/is'; | 18 | import { isArray, isObject } from '/@/utils/is'; |
| 20 | import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config'; | 19 | import { DataTypeEnum } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
| @@ -50,11 +49,24 @@ | @@ -50,11 +49,24 @@ | ||
| 50 | const grid = { | 49 | const grid = { |
| 51 | gutter: 8, | 50 | gutter: 8, |
| 52 | column: 3, | 51 | column: 3, |
| 53 | - }; | 52 | + } as any; |
| 54 | 53 | ||
| 54 | + const listElRef = ref<Nullable<ComponentElRef<HTMLDivElement>>>(null); | ||
| 55 | const token = getAuthCache(JWT_TOKEN_KEY); | 55 | const token = getAuthCache(JWT_TOKEN_KEY); |
| 56 | const { socketUrl } = useGlobSetting(); | 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 | const socketInfo = reactive({ | 68 | const socketInfo = reactive({ |
| 69 | + cmdId: 0, | ||
| 58 | origin: `${socketUrl}${token}`, | 70 | origin: `${socketUrl}${token}`, |
| 59 | attr: undefined as string | undefined, | 71 | attr: undefined as string | undefined, |
| 60 | originData: [] as DataSource[], | 72 | originData: [] as DataSource[], |
| @@ -63,6 +75,22 @@ | @@ -63,6 +75,22 @@ | ||
| 63 | attrKeys: [] as DeviceModelOfMatterAttrs[], | 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 | const getSendValue = computed(() => { | 94 | const getSendValue = computed(() => { |
| 67 | return { | 95 | return { |
| 68 | tsSubCmds: [ | 96 | tsSubCmds: [ |
| @@ -70,8 +98,10 @@ | @@ -70,8 +98,10 @@ | ||
| 70 | entityType: 'DEVICE', | 98 | entityType: 'DEVICE', |
| 71 | entityId: props.deviceDetail!.tbDeviceId, | 99 | entityId: props.deviceDetail!.tbDeviceId, |
| 72 | scope: 'LATEST_TELEMETRY', | 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,10 +146,19 @@ | ||
| 116 | const [registerTable, { setTableData }] = useTable({ | 146 | const [registerTable, { setTableData }] = useTable({ |
| 117 | columns: realTimeDataColumns, | 147 | columns: realTimeDataColumns, |
| 118 | showTableSetting: true, | 148 | showTableSetting: true, |
| 149 | + pagination: pagination as any, | ||
| 119 | bordered: true, | 150 | bordered: true, |
| 120 | showIndexColumn: false, | 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 | const [registerModal, { openModal }] = useModal(); | 162 | const [registerModal, { openModal }] = useModal(); |
| 124 | 163 | ||
| 125 | const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD); | 164 | const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD); |
| @@ -127,7 +166,7 @@ | @@ -127,7 +166,7 @@ | ||
| 127 | const switchMode = async (value: EnumTableCardMode) => { | 166 | const switchMode = async (value: EnumTableCardMode) => { |
| 128 | mode.value = value; | 167 | mode.value = value; |
| 129 | await nextTick(); | 168 | await nextTick(); |
| 130 | - setTableData(socketInfo.dataSource); | 169 | + setTableData(socketInfo.originData); |
| 131 | }; | 170 | }; |
| 132 | 171 | ||
| 133 | const { createMessage } = useMessage(); | 172 | const { createMessage } = useMessage(); |
| @@ -242,13 +281,24 @@ | @@ -242,13 +281,24 @@ | ||
| 242 | } as ModalParamsType); | 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 | onUnmounted(() => close()); | 295 | onUnmounted(() => close()); |
| 246 | </script> | 296 | </script> |
| 247 | 297 | ||
| 248 | <template> | 298 | <template> |
| 249 | <PageWrapper | 299 | <PageWrapper |
| 250 | dense | 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 | <section | 303 | <section |
| 254 | class="flex flex-col justify-between w-full bg-light-50 pt-3 mb-4 dark:text-gray-300 dark:bg-dark-900" | 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,9 +316,11 @@ | ||
| 266 | </div> | 316 | </div> |
| 267 | <List | 317 | <List |
| 268 | v-if="mode === EnumTableCardMode.CARD" | 318 | v-if="mode === EnumTableCardMode.CARD" |
| 319 | + ref="listElRef" | ||
| 269 | class="list-mode !px-2" | 320 | class="list-mode !px-2" |
| 270 | - :data-source="socketInfo.dataSource" | 321 | + :data-source="socketInfo.originData" |
| 271 | :grid="grid" | 322 | :grid="grid" |
| 323 | + :pagination="pagination" | ||
| 272 | > | 324 | > |
| 273 | <template #renderItem="{ item }"> | 325 | <template #renderItem="{ item }"> |
| 274 | <List.Item> | 326 | <List.Item> |
| @@ -279,11 +331,6 @@ | @@ -279,11 +331,6 @@ | ||
| 279 | <template #extra> | 331 | <template #extra> |
| 280 | <Space> | 332 | <Space> |
| 281 | <Tooltip title="属性下发"> | 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 | <SvgIcon | 334 | <SvgIcon |
| 288 | name="send-command" | 335 | name="send-command" |
| 289 | prefix="iconfont" | 336 | prefix="iconfont" |