Showing
6 changed files
with
139 additions
and
30 deletions
... | ... | @@ -2,6 +2,7 @@ import { formatToDate } from '/@/utils/dateUtil'; |
2 | 2 | import { BasicColumn } from '/@/components/Table'; |
3 | 3 | import { FormSchema } from '/@/components/Table'; |
4 | 4 | import { DeviceTypeEnum, DeviceState } from '/@/api/device/model/deviceModel'; |
5 | +import { deviceProfile } from '/@/api/device/deviceManager'; | |
5 | 6 | |
6 | 7 | // 表格列数据 |
7 | 8 | export const columns: BasicColumn[] = [ |
... | ... | @@ -105,4 +106,39 @@ export const searchFormSchema: FormSchema[] = [ |
105 | 106 | }, |
106 | 107 | colProps: { span: 6 }, |
107 | 108 | }, |
109 | + { | |
110 | + field: 'deviceProfileId', | |
111 | + label: '产品', | |
112 | + component: 'ApiSearchSelect', | |
113 | + colProps: { span: 6 }, | |
114 | + componentProps: () => { | |
115 | + return { | |
116 | + showSearch: true, | |
117 | + labelField: 'name', | |
118 | + valueField: 'id', | |
119 | + resultField: 'data', | |
120 | + placeholder: '请选择产品', | |
121 | + api: async () => { | |
122 | + const data = await deviceProfile({ params: '' }); | |
123 | + const returnData = data.map((m) => { | |
124 | + return { | |
125 | + name: m.name, | |
126 | + id: m.id, | |
127 | + }; | |
128 | + }); | |
129 | + return returnData; | |
130 | + }, | |
131 | + searchApi: async (params: Recordable) => { | |
132 | + const data = await deviceProfile({ textSearch: params.text }); | |
133 | + const returnData = data.map((m) => { | |
134 | + return { | |
135 | + name: m.name, | |
136 | + id: m.id, | |
137 | + }; | |
138 | + }); | |
139 | + return returnData; | |
140 | + }, | |
141 | + }; | |
142 | + }, | |
143 | + }, | |
108 | 144 | ]; | ... | ... |
... | ... | @@ -164,7 +164,7 @@ |
164 | 164 | </div> |
165 | 165 | </template> |
166 | 166 | <script lang="ts"> |
167 | - import { defineComponent, reactive, unref, nextTick, h } from 'vue'; | |
167 | + import { defineComponent, reactive, unref, nextTick, h, onUnmounted, ref } from 'vue'; | |
168 | 168 | import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel'; |
169 | 169 | import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table'; |
170 | 170 | import { columns, searchFormSchema } from './config/device.data'; |
... | ... | @@ -215,6 +215,7 @@ |
215 | 215 | setup(_) { |
216 | 216 | const { createMessage } = useMessage(); |
217 | 217 | const go = useGo(); |
218 | + const immediateStatus = ref(false); | |
218 | 219 | const searchInfo = reactive<Recordable>({}); |
219 | 220 | const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); |
220 | 221 | const [registerModal, { openModal }] = useModal(); |
... | ... | @@ -223,29 +224,31 @@ |
223 | 224 | const [registerTbDetailDrawer, { openDrawer: openTbDeviceDrawer }] = useDrawer(); |
224 | 225 | const [registerGatewayDetailDrawer, { openDrawer: openGatewayDetailDrawer }] = useDrawer(); |
225 | 226 | |
226 | - const [registerTable, { reload, setSelectedRowKeys, setProps }] = useTable({ | |
227 | - title: '设备列表', | |
228 | - api: devicePage, | |
229 | - columns, | |
230 | - formConfig: { | |
231 | - labelWidth: 100, | |
232 | - schemas: searchFormSchema, | |
233 | - resetFunc: resetFn, | |
234 | - }, | |
235 | - useSearchForm: true, | |
236 | - showTableSetting: true, | |
237 | - bordered: true, | |
238 | - showIndexColumn: false, | |
239 | - rowKey: 'id', | |
240 | - searchInfo: searchInfo, | |
241 | - clickToRowSelect: false, | |
242 | - actionColumn: { | |
243 | - width: 200, | |
244 | - title: '操作', | |
245 | - slots: { customRender: 'action' }, | |
246 | - fixed: 'right', | |
247 | - }, | |
248 | - }); | |
227 | + const [registerTable, { reload, setSelectedRowKeys, setProps, setTableData, getForm }] = | |
228 | + useTable({ | |
229 | + title: '设备列表', | |
230 | + api: devicePage, | |
231 | + immediate: immediateStatus.value, | |
232 | + columns, | |
233 | + formConfig: { | |
234 | + labelWidth: 100, | |
235 | + schemas: searchFormSchema, | |
236 | + resetFunc: resetFn, | |
237 | + }, | |
238 | + useSearchForm: true, | |
239 | + showTableSetting: true, | |
240 | + bordered: true, | |
241 | + showIndexColumn: false, | |
242 | + rowKey: 'id', | |
243 | + searchInfo: searchInfo, | |
244 | + clickToRowSelect: false, | |
245 | + actionColumn: { | |
246 | + width: 200, | |
247 | + title: '操作', | |
248 | + slots: { customRender: 'action' }, | |
249 | + fixed: 'right', | |
250 | + }, | |
251 | + }); | |
249 | 252 | const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } = |
250 | 253 | useBatchDelete(deleteDevice, handleSuccess, setProps); |
251 | 254 | selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => { |
... | ... | @@ -260,6 +263,48 @@ |
260 | 263 | setProps(selectionOptions); |
261 | 264 | }); |
262 | 265 | |
266 | + function getParams(keyword) { | |
267 | + const reg = new RegExp('(^|&)' + keyword + '=([^&]*)(&|$)', 'i'); | |
268 | + const r = window.location.search.substr(1).match(reg); | |
269 | + if (r != null) return unescape(r[2]); | |
270 | + return null; //注意此处参数是中文,解码使用的方法是unescape ,那么在传值的时候如果是中文,需要使用escape('曲浩')方法来编码。 | |
271 | + } | |
272 | + | |
273 | + const count = ref(0); | |
274 | + const onCloseVal = ref(0); | |
275 | + const deviceProfileId = ref(''); | |
276 | + count.value = Number(getParams('count')); | |
277 | + deviceProfileId.value = getParams('deviceProfileId') || ''; | |
278 | + const setRowClassName = async () => { | |
279 | + if (deviceProfileId.value !== '') { | |
280 | + const { items } = await devicePage({ | |
281 | + page: 1, | |
282 | + pageSize: count.value === 0 ? 10 : count.value, | |
283 | + deviceProfileId: deviceProfileId.value, | |
284 | + }); | |
285 | + nextTick(() => { | |
286 | + setTableData(items); | |
287 | + const { setFieldsValue, resetFields } = getForm(); | |
288 | + setFieldsValue({ | |
289 | + deviceProfileId: deviceProfileId.value, | |
290 | + }); | |
291 | + if (onCloseVal.value == 1) { | |
292 | + resetFields(); | |
293 | + } | |
294 | + }); | |
295 | + } else { | |
296 | + setTimeout(() => { | |
297 | + reload(); | |
298 | + }, 80); | |
299 | + } | |
300 | + }; | |
301 | + setRowClassName(); | |
302 | + onUnmounted(() => { | |
303 | + deviceProfileId.value = ''; | |
304 | + count.value = 10; | |
305 | + onCloseVal.value = 1; | |
306 | + }); | |
307 | + | |
263 | 308 | const userInfo: any = getAuthCache(USER_INFO_KEY); |
264 | 309 | const role: string = userInfo.roles[0]; |
265 | 310 | ... | ... |
... | ... | @@ -44,8 +44,8 @@ |
44 | 44 | const DevConStRef = ref<InstanceType<typeof ProductDescription>>(); |
45 | 45 | const TransConStRef = ref<InstanceType<typeof TransportConfigurationStep>>(); |
46 | 46 | |
47 | - const setDeviceConfFormData = async () => { | |
48 | - unref(DevConStRef)?.renderProductInfo(); | |
47 | + const setDeviceConfFormData = async (record) => { | |
48 | + unref(DevConStRef)?.renderProductInfo(record); | |
49 | 49 | }; |
50 | 50 | const setTransConfFormData = async (res: Recordable) => { |
51 | 51 | await nextTick(); |
... | ... | @@ -56,7 +56,7 @@ |
56 | 56 | activeKey.value = 'product'; |
57 | 57 | record.value = data.record; |
58 | 58 | record.value = await deviceConfigGetDetail(data.record.id); |
59 | - setDeviceConfFormData(); | |
59 | + setDeviceConfFormData(record.value); | |
60 | 60 | }); |
61 | 61 | |
62 | 62 | const handlePanelChange = (activeKey: ActiveKey) => { | ... | ... |
... | ... | @@ -9,12 +9,16 @@ |
9 | 9 | import { Description, useDescription } from '/@/components/Description'; |
10 | 10 | import { to } from '/@/utils/to'; |
11 | 11 | import productDefaultImage from '/@/assets/icons/product-default.svg'; |
12 | + import { Button } from '/@/components/Button'; | |
13 | + import { useGo } from '/@/hooks/web/usePage'; | |
14 | + import { PageEnum } from '/@/enums/pageEnum'; | |
12 | 15 | |
13 | 16 | const loading = ref(false); |
14 | 17 | |
15 | 18 | const props = defineProps<{ |
16 | 19 | record: DeviceRecord; |
17 | 20 | }>(); |
21 | + const go = useGo(); | |
18 | 22 | |
19 | 23 | const data = ref<DeviceRecord>({} as unknown as DeviceRecord); |
20 | 24 | |
... | ... | @@ -33,6 +37,26 @@ |
33 | 37 | { |
34 | 38 | field: 'deviceType', |
35 | 39 | label: '设备类型', |
40 | + render: (_, data) => { | |
41 | + return h( | |
42 | + Button, | |
43 | + { | |
44 | + type: 'link', | |
45 | + style: { marginLeft: -8 + 'px' }, | |
46 | + size: 'small', | |
47 | + onClick: () => { | |
48 | + go( | |
49 | + PageEnum.DEVICE_LIST + | |
50 | + '?count=' + | |
51 | + data.deviceCount + | |
52 | + '&deviceProfileId=' + | |
53 | + data.id | |
54 | + ); | |
55 | + }, | |
56 | + }, | |
57 | + () => `${data.deviceType}(${data.deviceCount})` | |
58 | + ); | |
59 | + }, | |
36 | 60 | }, |
37 | 61 | { |
38 | 62 | field: 'name', |
... | ... | @@ -87,7 +111,7 @@ |
87 | 111 | return {}; |
88 | 112 | }; |
89 | 113 | |
90 | - const renderProductInfo = async () => { | |
114 | + const renderProductInfo = async (record) => { | |
91 | 115 | try { |
92 | 116 | data.value = {} as unknown as DeviceRecord; |
93 | 117 | loading.value = true; |
... | ... | @@ -98,8 +122,10 @@ |
98 | 122 | findHandleQueue(defaultQueueName), |
99 | 123 | findRuleChain(defaultRuleChainId), |
100 | 124 | ]); |
101 | - const value = values.reduce((prev, next) => ({ ...prev, ...next }), {}); | |
102 | - data.value = Object.assign(unref(data), value); | |
125 | + if (values) { | |
126 | + const value = values.reduce((prev, next) => ({ ...prev, ...next }), {}); | |
127 | + data.value = Object.assign(unref(data), value, { deviceCount: record.deviceCount }); | |
128 | + } | |
103 | 129 | setDescProps({ data: unref(data) }); |
104 | 130 | } catch (error) { |
105 | 131 | throw error; | ... | ... |