diff --git a/src/views/system/Department/components/AddDeviceOrProductDialog.vue b/src/views/system/Department/components/AddDeviceOrProductDialog.vue index ac1f2ad2..115fe3cd 100644 --- a/src/views/system/Department/components/AddDeviceOrProductDialog.vue +++ b/src/views/system/Department/components/AddDeviceOrProductDialog.vue @@ -3,12 +3,10 @@ class="add-device-or-product-dialog-container" title="绑定" width="1440px" - @ok="dialog.handleOk" - :confirmLoading="dialog.loading.value" - cancelText="取消" - okText="确定" - v-model:visible="dialog.visible.value" - destroyOnClose + @ok="confirm" + :confirmLoading="loading" + @cancel="emits('update:visible', false)" + visible >
@@ -110,52 +108,47 @@ import { ExclamationCircleOutlined } from '@ant-design/icons-vue'; import { getImage } from '@/utils/comm'; import { uniq, intersection } from 'lodash-es'; import { - getDeviceOrProductList_api,getDeviceList_api, + getDeviceOrProductList_api, + getDeviceList_api, getPermission_api, bindDeviceOrProductList_api, } from '@/api/system/department'; import { message } from 'ant-design-vue'; import { dictType } from '../typing'; -const emits = defineEmits(['confirm']); +const emits = defineEmits(['confirm', 'update:visible']); const props = defineProps<{ + visible: boolean; queryColumns: any[]; parentId: string; allPermission: dictType; assetType: 'product' | 'device'; }>(); // 弹窗相关 -const dialog = { - visible: ref(false), - loading: ref(false), - handleOk: () => { - if (table.selectedRows.length < 1) { - return message.warning('请先勾选数据'); - } +const loading = ref(false); +const confirm = () => { + if (table.selectedRows.length < 1) { + return message.warning('请先勾选数据'); + } - const params = table.selectedRows.map((item: any) => ({ - targetType: 'org', - targetId: props.parentId, - assetType: props.assetType, - assetIdList: [item.id], - permission: item.selectPermissions, - })); + const params = table.selectedRows.map((item: any) => ({ + targetType: 'org', + targetId: props.parentId, + assetType: props.assetType, + assetIdList: [item.id], + permission: item.selectPermissions, + })); - dialog.loading.value = true; - bindDeviceOrProductList_api(props.assetType, params) - .then(() => { - message.success('操作成功'); - emits('confirm'); - dialog.changeVisible(); - }) - .finally(() => { - dialog.loading.value = false; - }); - }, - // 控制弹窗的打开与关闭 - changeVisible: () => { - dialog.visible.value = !dialog.visible.value; - }, + loading.value = true; + bindDeviceOrProductList_api(props.assetType, params) + .then(() => { + message.success('操作成功'); + emits('confirm'); + emits('update:visible', false); + }) + .finally(() => { + loading.value = false; + }); }; const bulkBool = ref(true); @@ -308,7 +301,10 @@ const table: any = { // 获取并整理数据 getData: (params: object, parentId: string) => new Promise((resolve) => { - const api = props.assetType === 'product' ? getDeviceOrProductList_api: getDeviceList_api; + const api = + props.assetType === 'product' + ? getDeviceOrProductList_api + : getDeviceList_api; api(params).then((resp: any) => { type resultType = { data: any[]; @@ -319,43 +315,55 @@ const table: any = { const { pageIndex, pageSize, total, data } = resp.result as resultType; const ids = data.map((item) => item.id); - getPermission_api(props.assetType,ids, parentId).then((perResp: any) => { - const permissionObj = {}; - perResp.result.forEach((item: any) => { - permissionObj[item.assetId] = props.allPermission - .filter((permission) => - item.allPermissions.includes(permission.id), - ) - .map((item) => ({ - label: item.name, - value: item.id, - disabled: true, - })); - }); - data.forEach((item) => { - item.permissionList = permissionObj[item.id]; - item.selectPermissions = ['read']; + getPermission_api(props.assetType, ids, parentId).then( + (perResp: any) => { + const permissionObj = {}; + perResp.result.forEach((item: any) => { + permissionObj[item.assetId] = props.allPermission + .filter((permission) => + item.allPermissions.includes(permission.id), + ) + .map((item) => ({ + label: item.name, + value: item.id, + disabled: true, + })); + }); + data.forEach((item) => { + item.permissionList = permissionObj[item.id]; + item.selectPermissions = ['read']; - // 产品的状态进行转换处理 - if(props.assetType === 'product') { - item.state = { - value: item.state === 1 ? 'online': item.state === 0 ? 'offline': '', - text: item.state === 1 ? '正常': item.state === 0 ? '禁用': '' + // 产品的状态进行转换处理 + if (props.assetType === 'product') { + item.state = { + value: + item.state === 1 + ? 'online' + : item.state === 0 + ? 'offline' + : '', + text: + item.state === 1 + ? '正常' + : item.state === 0 + ? '禁用' + : '', + }; } - } - }); + }); - resolve({ - code: 200, - result: { - data: data, - pageIndex, - pageSize, - total, - }, - status: 200, - }); - }); + resolve({ + code: 200, + result: { + data: data, + pageIndex, + pageSize, + total, + }, + status: 200, + }); + }, + ); }); }), // 整理参数并获取数据 @@ -412,11 +420,6 @@ const table: any = { }, }; table.init(); - -// 将打开弹窗的操作暴露给父组件 -defineExpose({ - openDialog: dialog.changeVisible, -}); diff --git a/src/views/system/Department/components/EditPermissionDialog.vue b/src/views/system/Department/components/EditPermissionDialog.vue index 42182b6f..11038ada 100644 --- a/src/views/system/Department/components/EditPermissionDialog.vue +++ b/src/views/system/Department/components/EditPermissionDialog.vue @@ -1,22 +1,21 @@ diff --git a/src/views/system/Department/components/LeftTree.vue b/src/views/system/Department/components/LeftTree.vue index 7057903b..bdc1dd9b 100644 --- a/src/views/system/Department/components/LeftTree.vue +++ b/src/views/system/Department/components/LeftTree.vue @@ -1,6 +1,6 @@ - +
{{ name }} - - - - - @@ -109,8 +73,10 @@
@@ -215,9 +181,24 @@ function refresh(id: string) { } // 弹窗 -const editDialogRef = ref(); // 新增弹窗实例 +const dialog = reactive({ + visible: false, + selectItem: {}, +}); const openDialog = (row: any = {}) => { - editDialogRef.value.openDialog(true, row); + // 计算默认排序值,为子列表中最大的排序值+1 + let sortIndex = row.sortIndex || 1; + if (!row.id) { + let childrens = [] as any[]; + if (row.parentId) { + childrens = row.children; + } else childrens = treeData.value; + sortIndex = + Math.max(...(childrens?.map((item) => item.sortIndex) || [0])) + 1; + } + + dialog.selectItem = { ...row, sortIndex }; + dialog.visible = true; }; init(); function init() { @@ -236,6 +217,7 @@ function init() { diff --git a/src/views/system/Department/device/index.vue b/src/views/system/Department/device/index.vue index cc474d9f..6927ba59 100644 --- a/src/views/system/Department/device/index.vue +++ b/src/views/system/Department/device/index.vue @@ -13,7 +13,7 @@ @cancelSelect="table.cancelSelect" >