From b4734056d8782f6b115af13b627c9e3fdc7a8386 Mon Sep 17 00:00:00 2001 From: JiangQiming <291854119@qq.com> Date: Thu, 23 Mar 2023 15:36:31 +0800 Subject: [PATCH] fix: bug#10609-1 --- src/store/department.ts | 26 ++++++++++++++++++ .../components/AddDeviceOrProductDialog.vue | 27 +++++++++++++++++++ src/views/system/Department/device/index.vue | 17 +++++++----- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 src/store/department.ts diff --git a/src/store/department.ts b/src/store/department.ts new file mode 100644 index 00000000..3bcbbb9b --- /dev/null +++ b/src/store/department.ts @@ -0,0 +1,26 @@ + +import { defineStore } from "pinia"; + +type DepartmentStateType = { + productId: string; + optType: string | undefined; +} + +export const useDepartmentStore = defineStore({ + id: 'department', + state: (): DepartmentStateType => ({ + productId: '', + // 设备资产分配弹窗操作类型: + // 1. optType === 'handle': 手动点击资产分配按钮; + // 2. optType === ': 产品资产分配后, 自动弹出设备资产分配 + optType: '' + }), + actions: { + setProductId(value: string) { + this.productId = value + }, + setType(value: string | undefined) { + this.optType = value + } + } +}) \ No newline at end of file diff --git a/src/views/system/Department/components/AddDeviceOrProductDialog.vue b/src/views/system/Department/components/AddDeviceOrProductDialog.vue index 6fbea17b..c82bc814 100644 --- a/src/views/system/Department/components/AddDeviceOrProductDialog.vue +++ b/src/views/system/Department/components/AddDeviceOrProductDialog.vue @@ -143,6 +143,9 @@ import { } from '@/api/system/department'; import { message } from 'jetlinks-ui-components'; import { dictType } from '../typing'; +import { useDepartmentStore } from '@/store/department'; + +const departmentStore = useDepartmentStore(); const emits = defineEmits(['confirm', 'update:visible']); const props = defineProps<{ @@ -154,6 +157,9 @@ const props = defineProps<{ }>(); // 弹窗相关 const loading = ref(false); +// 资产咨询次数, 产品分配后自动进入的设备资产, 第一次需要带上产品id查询 +const queryCount = ref(0); + const confirm = () => { if (table.selectedRows.length < 1) { return message.warning('请先勾选数据'); @@ -167,6 +173,11 @@ const confirm = () => { permission: item.selectPermissions, })); + if (params.length === 1) { + // 只选择一个产品资产分配时, 分配之后, 进入设备资产分配需查出对应产品下的设备 + departmentStore.setProductId(params[0].assetIdList[0]); + } + loading.value = true; bindDeviceOrProductList_api(props.assetType, params) .then(() => { @@ -398,6 +409,7 @@ const table: any = { }), // 整理参数并获取数据 requestFun: async (oParams: any) => { + queryCount.value += 1; if (props.parentId) { const terms = [ { @@ -415,9 +427,24 @@ const table: any = { ], }, }, + { + column: 'productId$product-info', + type: 'and', + value: `id is ${departmentStore.productId}`, + }, ], }, ]; + + if ( + props.assetType !== 'device' || + !departmentStore.productId || + queryCount.value > 1 || + departmentStore.optType === 'handle' + ) { + // 非设备|产品id不存在|有其他查询操作(queryCount+1)|设备页面手动点击资产分配, 均删除产品带入的id + terms[0].terms.pop(); + } if (oParams.terms && oParams.terms.length > 0) terms.unshift({ terms: oParams.terms }); const params = { diff --git a/src/views/system/Department/device/index.vue b/src/views/system/Department/device/index.vue index 212960c1..d4e70dc4 100644 --- a/src/views/system/Department/device/index.vue +++ b/src/views/system/Department/device/index.vue @@ -22,7 +22,7 @@ 资产分配 @@ -211,6 +211,9 @@ import { intersection } from 'lodash-es'; import type { dictType, optionsType } from '../typing'; import { message } from 'jetlinks-ui-components'; +import { useDepartmentStore } from '@/store/department'; + +const departmentStore = useDepartmentStore(); const permission = 'system/Department'; @@ -248,7 +251,7 @@ const columns = [ rename: 'productId$product-info', type: 'select', handleValue(value: string) { - return `id is ${value}` + return `id is ${value}`; }, options: () => new Promise((resolve) => { @@ -291,9 +294,9 @@ const columns = [ search: { type: 'select', options: [ - { label: '禁用', value: 'notActive' }, - { label: '离线', value: 'offline' }, - { label: '在线', value: 'online' }, + { label: '禁用', value: 'notActive' }, + { label: '离线', value: 'offline' }, + { label: '在线', value: 'online' }, ], }, scopedSlots: true, @@ -465,7 +468,9 @@ const table = { }; } }, - clickAdd: () => { + clickAdd: (type?: string) => { + // 设备资产分配弹窗操作类型: type = 'handle': 手动点击资产分配按钮, !type产品资产分配后, 自动弹出设备资产分配 + departmentStore.setType(type) dialogs.addShow = true; }, clickEdit: (row?: any) => {