Showing
1 changed file
with
62 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,15 +75,34 @@ | @@ -63,15 +75,34 @@ | ||
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(() => { |
95 | + console.log(unref(getPaginationAttrkey)); | ||
67 | return { | 96 | return { |
68 | tsSubCmds: [ | 97 | tsSubCmds: [ |
69 | { | 98 | { |
70 | entityType: 'DEVICE', | 99 | entityType: 'DEVICE', |
71 | entityId: props.deviceDetail!.tbDeviceId, | 100 | entityId: props.deviceDetail!.tbDeviceId, |
72 | scope: 'LATEST_TELEMETRY', | 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,10 +147,19 @@ | ||
116 | const [registerTable, { setTableData }] = useTable({ | 147 | const [registerTable, { setTableData }] = useTable({ |
117 | columns: realTimeDataColumns, | 148 | columns: realTimeDataColumns, |
118 | showTableSetting: true, | 149 | showTableSetting: true, |
150 | + pagination: pagination as any, | ||
119 | bordered: true, | 151 | bordered: true, |
120 | showIndexColumn: false, | 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 | const [registerModal, { openModal }] = useModal(); | 163 | const [registerModal, { openModal }] = useModal(); |
124 | 164 | ||
125 | const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD); | 165 | const mode = ref<EnumTableCardMode>(EnumTableCardMode.CARD); |
@@ -127,7 +167,7 @@ | @@ -127,7 +167,7 @@ | ||
127 | const switchMode = async (value: EnumTableCardMode) => { | 167 | const switchMode = async (value: EnumTableCardMode) => { |
128 | mode.value = value; | 168 | mode.value = value; |
129 | await nextTick(); | 169 | await nextTick(); |
130 | - setTableData(socketInfo.dataSource); | 170 | + setTableData(socketInfo.originData); |
131 | }; | 171 | }; |
132 | 172 | ||
133 | const { createMessage } = useMessage(); | 173 | const { createMessage } = useMessage(); |
@@ -242,13 +282,24 @@ | @@ -242,13 +282,24 @@ | ||
242 | } as ModalParamsType); | 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 | onUnmounted(() => close()); | 296 | onUnmounted(() => close()); |
246 | </script> | 297 | </script> |
247 | 298 | ||
248 | <template> | 299 | <template> |
249 | <PageWrapper | 300 | <PageWrapper |
250 | dense | 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 | <section | 304 | <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" | 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,9 +317,11 @@ | ||
266 | </div> | 317 | </div> |
267 | <List | 318 | <List |
268 | v-if="mode === EnumTableCardMode.CARD" | 319 | v-if="mode === EnumTableCardMode.CARD" |
320 | + ref="listElRef" | ||
269 | class="list-mode !px-2" | 321 | class="list-mode !px-2" |
270 | - :data-source="socketInfo.dataSource" | 322 | + :data-source="socketInfo.originData" |
271 | :grid="grid" | 323 | :grid="grid" |
324 | + :pagination="pagination" | ||
272 | > | 325 | > |
273 | <template #renderItem="{ item }"> | 326 | <template #renderItem="{ item }"> |
274 | <List.Item> | 327 | <List.Item> |
@@ -279,11 +332,6 @@ | @@ -279,11 +332,6 @@ | ||
279 | <template #extra> | 332 | <template #extra> |
280 | <Space> | 333 | <Space> |
281 | <Tooltip title="属性下发"> | 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 | <SvgIcon | 335 | <SvgIcon |
288 | name="send-command" | 336 | name="send-command" |
289 | prefix="iconfont" | 337 | prefix="iconfont" |