Commit 8e597b2ec289fab341397b3ad020afa20f97d43b
Merge branch 'local_dev_ft' into 'main'
feat:产品详情新增设备类型数量跳转到设备列表 See merge request huang/yun-teng-iot-front!454
Showing
7 changed files
with
159 additions
and
35 deletions
| @@ -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,49 @@ | @@ -260,6 +263,49 @@ | ||
| 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 | + console.log(deviceProfileId.value); | ||
| 279 | + const setRowClassName = async () => { | ||
| 280 | + if (deviceProfileId.value !== undefined) { | ||
| 281 | + const { items } = await devicePage({ | ||
| 282 | + page: 1, | ||
| 283 | + pageSize: count.value === 0 ? 10 : count.value, | ||
| 284 | + deviceProfileId: deviceProfileId.value, | ||
| 285 | + }); | ||
| 286 | + nextTick(() => { | ||
| 287 | + setTableData(items); | ||
| 288 | + const { setFieldsValue, resetFields } = getForm(); | ||
| 289 | + setFieldsValue({ | ||
| 290 | + deviceProfileId: deviceProfileId.value, | ||
| 291 | + }); | ||
| 292 | + if (onCloseVal.value == 1) { | ||
| 293 | + resetFields(); | ||
| 294 | + } | ||
| 295 | + }); | ||
| 296 | + } else { | ||
| 297 | + setTimeout(() => { | ||
| 298 | + reload(); | ||
| 299 | + }, 80); | ||
| 300 | + } | ||
| 301 | + }; | ||
| 302 | + setRowClassName(); | ||
| 303 | + onUnmounted(() => { | ||
| 304 | + deviceProfileId.value = ''; | ||
| 305 | + count.value = 10; | ||
| 306 | + onCloseVal.value = 1; | ||
| 307 | + }); | ||
| 308 | + | ||
| 263 | const userInfo: any = getAuthCache(USER_INFO_KEY); | 309 | const userInfo: any = getAuthCache(USER_INFO_KEY); |
| 264 | const role: string = userInfo.roles[0]; | 310 | const role: string = userInfo.roles[0]; |
| 265 | 311 |
| @@ -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,27 @@ | @@ -33,6 +37,27 @@ | ||
| 33 | { | 37 | { |
| 34 | field: 'deviceType', | 38 | field: 'deviceType', |
| 35 | label: '设备类型', | 39 | label: '设备类型', |
| 40 | + render: (_, data) => { | ||
| 41 | + console.log(data); | ||
| 42 | + return h( | ||
| 43 | + Button, | ||
| 44 | + { | ||
| 45 | + type: 'link', | ||
| 46 | + style: { marginLeft: -8 + 'px' }, | ||
| 47 | + size: 'small', | ||
| 48 | + onClick: () => { | ||
| 49 | + go( | ||
| 50 | + PageEnum.DEVICE_LIST + | ||
| 51 | + '?count=' + | ||
| 52 | + data.deviceCount + | ||
| 53 | + '&deviceProfileId=' + | ||
| 54 | + data.id | ||
| 55 | + ); | ||
| 56 | + }, | ||
| 57 | + }, | ||
| 58 | + () => `${data.deviceType}(${data.deviceCount})` | ||
| 59 | + ); | ||
| 60 | + }, | ||
| 36 | }, | 61 | }, |
| 37 | { | 62 | { |
| 38 | field: 'name', | 63 | field: 'name', |
| @@ -87,19 +112,30 @@ | @@ -87,19 +112,30 @@ | ||
| 87 | return {}; | 112 | return {}; |
| 88 | }; | 113 | }; |
| 89 | 114 | ||
| 115 | + async function getValues() { | ||
| 116 | + const { defaultRuleChainId, deviceType, defaultQueueName } = props.record; | ||
| 117 | + return await Promise.all([ | ||
| 118 | + findDeviceType(deviceType), | ||
| 119 | + findHandleQueue(defaultQueueName), | ||
| 120 | + findRuleChain(defaultRuleChainId), | ||
| 121 | + ]); | ||
| 122 | + } | ||
| 123 | + | ||
| 90 | const renderProductInfo = async () => { | 124 | const renderProductInfo = async () => { |
| 91 | try { | 125 | try { |
| 92 | data.value = {} as unknown as DeviceRecord; | 126 | data.value = {} as unknown as DeviceRecord; |
| 93 | loading.value = true; | 127 | loading.value = true; |
| 94 | - const { defaultRuleChainId, deviceType, defaultQueueName } = props.record; | ||
| 95 | - data.value = props.record; | ||
| 96 | - const values = await Promise.all([ | ||
| 97 | - findDeviceType(deviceType), | ||
| 98 | - findHandleQueue(defaultQueueName), | ||
| 99 | - findRuleChain(defaultRuleChainId), | ||
| 100 | - ]); | 128 | + const values = await getValues(); |
| 129 | + // const { defaultRuleChainId, deviceType, defaultQueueName } = props.record; | ||
| 130 | + // data.value = props.record; | ||
| 131 | + // const values = await Promise.all([ | ||
| 132 | + // findDeviceType(deviceType), | ||
| 133 | + // findHandleQueue(defaultQueueName), | ||
| 134 | + // findRuleChain(defaultRuleChainId), | ||
| 135 | + // ]); | ||
| 101 | const value = values.reduce((prev, next) => ({ ...prev, ...next }), {}); | 136 | const value = values.reduce((prev, next) => ({ ...prev, ...next }), {}); |
| 102 | - data.value = Object.assign(unref(data), value); | 137 | + data.value = Object.assign(unref(data), props.record, value); |
| 138 | + console.log(data.value); | ||
| 103 | setDescProps({ data: unref(data) }); | 139 | setDescProps({ data: unref(data) }); |
| 104 | } catch (error) { | 140 | } catch (error) { |
| 105 | throw error; | 141 | throw error; |
| @@ -40,6 +40,8 @@ | @@ -40,6 +40,8 @@ | ||
| 40 | import { FileItem } from '/@/components/Upload/src/typing'; | 40 | import { FileItem } from '/@/components/Upload/src/typing'; |
| 41 | import { upload } from '/@/api/oss/ossFileUploader'; | 41 | import { upload } from '/@/api/oss/ossFileUploader'; |
| 42 | import { getTenantRoles, updateOrCreateTenant } from '/@/api/tenant/tenantApi'; | 42 | import { getTenantRoles, updateOrCreateTenant } from '/@/api/tenant/tenantApi'; |
| 43 | + import { useMessage } from '/@/hooks/web/useMessage'; | ||
| 44 | + | ||
| 43 | export default defineComponent({ | 45 | export default defineComponent({ |
| 44 | name: 'TenantDrawer', | 46 | name: 'TenantDrawer', |
| 45 | components: { | 47 | components: { |
| @@ -52,6 +54,7 @@ | @@ -52,6 +54,7 @@ | ||
| 52 | emits: ['success', 'register'], | 54 | emits: ['success', 'register'], |
| 53 | setup(_, { emit }) { | 55 | setup(_, { emit }) { |
| 54 | const loading = ref(false); | 56 | const loading = ref(false); |
| 57 | + const { createMessage } = useMessage(); | ||
| 55 | 58 | ||
| 56 | const isUpdate = ref(true); | 59 | const isUpdate = ref(true); |
| 57 | const tenantLogo = ref(''); | 60 | const tenantLogo = ref(''); |
| @@ -141,6 +144,7 @@ | @@ -141,6 +144,7 @@ | ||
| 141 | }; | 144 | }; |
| 142 | await updateOrCreateTenant(req); | 145 | await updateOrCreateTenant(req); |
| 143 | emit('success'); | 146 | emit('success'); |
| 147 | + createMessage.success(`${unref(isUpdate) ? '编辑' : '新增'}成功`); | ||
| 144 | closeDrawer(); //关闭侧框 | 148 | closeDrawer(); //关闭侧框 |
| 145 | } catch (e) { | 149 | } catch (e) { |
| 146 | if ((e as { code: string }).code === 'ECONNABORTED') { | 150 | if ((e as { code: string }).code === 'ECONNABORTED') { |