Commit 3f242e9e975a43937cfc46f8362b6b1023266ff5

Authored by fengtao
1 parent 328d7d65

feat:产品详情新增点击跳转到设备列表

@@ -155,6 +155,7 @@ export interface DeviceRecord { @@ -155,6 +155,7 @@ export interface DeviceRecord {
155 transportType: string; 155 transportType: string;
156 provisionType: string; 156 provisionType: string;
157 deviceType: string; 157 deviceType: string;
  158 + deviceCount: number;
158 tbProfileId: string; 159 tbProfileId: string;
159 profileData: ProfileData; 160 profileData: ProfileData;
160 defaultQueueName: string; 161 defaultQueueName: string;
@@ -13,4 +13,5 @@ export const PageEnum = { @@ -13,4 +13,5 @@ export const PageEnum = {
13 MESSAGE_CONFIG: '/message/config', 13 MESSAGE_CONFIG: '/message/config',
14 //设备配置 14 //设备配置
15 DEVICE_PROFILE: '/product/profiles', 15 DEVICE_PROFILE: '/product/profiles',
  16 + DEVICE_LIST: '/device/list',
16 }; 17 };
@@ -2,6 +2,7 @@ import { formatToDate } from '/@/utils/dateUtil'; @@ -2,6 +2,7 @@ import { formatToDate } from '/@/utils/dateUtil';
2 import { BasicColumn } from '/@/components/Table'; 2 import { BasicColumn } from '/@/components/Table';
3 import { FormSchema } from '/@/components/Table'; 3 import { FormSchema } from '/@/components/Table';
4 import { DeviceTypeEnum, DeviceState } from '/@/api/device/model/deviceModel'; 4 import { DeviceTypeEnum, DeviceState } from '/@/api/device/model/deviceModel';
  5 +import { deviceProfile } from '/@/api/device/deviceManager';
5 6
6 // 表格列数据 7 // 表格列数据
7 export const columns: BasicColumn[] = [ 8 export const columns: BasicColumn[] = [
@@ -105,4 +106,39 @@ export const searchFormSchema: FormSchema[] = [ @@ -105,4 +106,39 @@ export const searchFormSchema: FormSchema[] = [
105 }, 106 },
106 colProps: { span: 6 }, 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,7 +164,7 @@
164 </div> 164 </div>
165 </template> 165 </template>
166 <script lang="ts"> 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 import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel'; 168 import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
169 import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table'; 169 import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table';
170 import { columns, searchFormSchema } from './config/device.data'; 170 import { columns, searchFormSchema } from './config/device.data';
@@ -215,6 +215,7 @@ @@ -215,6 +215,7 @@
215 setup(_) { 215 setup(_) {
216 const { createMessage } = useMessage(); 216 const { createMessage } = useMessage();
217 const go = useGo(); 217 const go = useGo();
  218 + const immediateStatus = ref(false);
218 const searchInfo = reactive<Recordable>({}); 219 const searchInfo = reactive<Recordable>({});
219 const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo); 220 const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo);
220 const [registerModal, { openModal }] = useModal(); 221 const [registerModal, { openModal }] = useModal();
@@ -223,29 +224,31 @@ @@ -223,29 +224,31 @@
223 const [registerTbDetailDrawer, { openDrawer: openTbDeviceDrawer }] = useDrawer(); 224 const [registerTbDetailDrawer, { openDrawer: openTbDeviceDrawer }] = useDrawer();
224 const [registerGatewayDetailDrawer, { openDrawer: openGatewayDetailDrawer }] = useDrawer(); 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 const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } = 252 const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions, resetSelectedRowKeys } =
250 useBatchDelete(deleteDevice, handleSuccess, setProps); 253 useBatchDelete(deleteDevice, handleSuccess, setProps);
251 selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => { 254 selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
@@ -260,6 +263,48 @@ @@ -260,6 +263,48 @@
260 setProps(selectionOptions); 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 const userInfo: any = getAuthCache(USER_INFO_KEY); 308 const userInfo: any = getAuthCache(USER_INFO_KEY);
264 const role: string = userInfo.roles[0]; 309 const role: string = userInfo.roles[0];
265 310
@@ -44,8 +44,8 @@ @@ -44,8 +44,8 @@
44 const DevConStRef = ref<InstanceType<typeof ProductDescription>>(); 44 const DevConStRef = ref<InstanceType<typeof ProductDescription>>();
45 const TransConStRef = ref<InstanceType<typeof TransportConfigurationStep>>(); 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 const setTransConfFormData = async (res: Recordable) => { 50 const setTransConfFormData = async (res: Recordable) => {
51 await nextTick(); 51 await nextTick();
@@ -56,7 +56,7 @@ @@ -56,7 +56,7 @@
56 activeKey.value = 'product'; 56 activeKey.value = 'product';
57 record.value = data.record; 57 record.value = data.record;
58 record.value = await deviceConfigGetDetail(data.record.id); 58 record.value = await deviceConfigGetDetail(data.record.id);
59 - setDeviceConfFormData(); 59 + setDeviceConfFormData(record.value);
60 }); 60 });
61 61
62 const handlePanelChange = (activeKey: ActiveKey) => { 62 const handlePanelChange = (activeKey: ActiveKey) => {
@@ -9,12 +9,16 @@ @@ -9,12 +9,16 @@
9 import { Description, useDescription } from '/@/components/Description'; 9 import { Description, useDescription } from '/@/components/Description';
10 import { to } from '/@/utils/to'; 10 import { to } from '/@/utils/to';
11 import productDefaultImage from '/@/assets/icons/product-default.svg'; 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 const loading = ref(false); 16 const loading = ref(false);
14 17
15 const props = defineProps<{ 18 const props = defineProps<{
16 record: DeviceRecord; 19 record: DeviceRecord;
17 }>(); 20 }>();
  21 + const go = useGo();
18 22
19 const data = ref<DeviceRecord>({} as unknown as DeviceRecord); 23 const data = ref<DeviceRecord>({} as unknown as DeviceRecord);
20 24
@@ -33,6 +37,26 @@ @@ -33,6 +37,26 @@
33 { 37 {
34 field: 'deviceType', 38 field: 'deviceType',
35 label: '设备类型', 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 field: 'name', 62 field: 'name',
@@ -87,7 +111,7 @@ @@ -87,7 +111,7 @@
87 return {}; 111 return {};
88 }; 112 };
89 113
90 - const renderProductInfo = async () => { 114 + const renderProductInfo = async (record) => {
91 try { 115 try {
92 data.value = {} as unknown as DeviceRecord; 116 data.value = {} as unknown as DeviceRecord;
93 loading.value = true; 117 loading.value = true;
@@ -98,8 +122,10 @@ @@ -98,8 +122,10 @@
98 findHandleQueue(defaultQueueName), 122 findHandleQueue(defaultQueueName),
99 findRuleChain(defaultRuleChainId), 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 setDescProps({ data: unref(data) }); 129 setDescProps({ data: unref(data) });
104 } catch (error) { 130 } catch (error) {
105 throw error; 131 throw error;