From a75f2a3fd69693043e89ea8b745445a0c5b494c3 Mon Sep 17 00:00:00 2001 From: JiangQiming <291854119@qq.com> Date: Thu, 30 Mar 2023 16:20:16 +0800 Subject: [PATCH] fix: bug#11106 --- src/store/department.ts | 5 +++ .../Platforms/Api/components/ChooseApi.vue | 45 +++++-------------- src/views/system/Platforms/Api/index.vue | 23 +++++++--- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/store/department.ts b/src/store/department.ts index d8f49c97..72abbff5 100644 --- a/src/store/department.ts +++ b/src/store/department.ts @@ -5,6 +5,7 @@ type DepartmentStateType = { productId: string; optType: string | undefined; crossPageKeys: string[]; + changedApis: any; } export const useDepartmentStore = defineStore({ @@ -16,6 +17,7 @@ export const useDepartmentStore = defineStore({ // 2. optType === ': 产品资产分配后, 自动弹出设备资产分配 optType: '', crossPageKeys: [], // 表格跨页多选的keys + changedApis: {}, }), actions: { setProductId(value: string) { @@ -27,6 +29,9 @@ export const useDepartmentStore = defineStore({ setSelectedKeys(value: string[], type?: string) { // 分页保留选中项 this.crossPageKeys = type === 'concat' ? [...new Set([...this.crossPageKeys, ...value])] : value; + }, + setChangedApis(value: any) { + this.changedApis = { ...this.changedApis, ...value }; } } }) \ No newline at end of file diff --git a/src/views/system/Platforms/Api/components/ChooseApi.vue b/src/views/system/Platforms/Api/components/ChooseApi.vue index 166ce578..dfa74792 100644 --- a/src/views/system/Platforms/Api/components/ChooseApi.vue +++ b/src/views/system/Platforms/Api/components/ChooseApi.vue @@ -37,6 +37,9 @@ import { } from '@/api/system/apiPage'; import { message } from 'ant-design-vue'; import { modeType } from '../typing'; +import { useDepartmentStore } from '@/store/department'; + +const department = useDepartmentStore(); const emits = defineEmits([ 'refresh', 'update:clickApi', @@ -64,11 +67,6 @@ const columns = [ dataIndex: 'summary', key: 'summary', }, - // { - // title: 'ID', - // dataIndex: 'id', - // key: 'id', - // }, ]; const rowSelection = { // onSelect: (record: any) => { @@ -95,7 +93,7 @@ const rowSelection = { props.sourceKeys.includes(key), ); // 除当前表格之外, 勾选上的数据 - const otherSelectedKeys = props.sourceKeys.filter( + const otherSelectedKeys = department.crossPageKeys.filter( (key) => !currenTableKeys.includes(key), ); @@ -103,6 +101,7 @@ const rowSelection = { const removeKeys = oldSelectedKeys.filter((key) => !keys.includes(key)); // 新增选择的项 const addKeys = keys.filter((key) => !oldSelectedKeys.includes(key)); + // 缓存当前表格和其他表格改变的数据 emits('update:selectedRowKeys', [...otherSelectedKeys, ...keys]); // 新增选中/取消选中的数据 @@ -111,37 +110,21 @@ const rowSelection = { changed[key] = props.tableData.find((f: any) => f.id === key); }); if (props.mode === 'appManger') { - emits('update:changedApis', changed); + // 缓存当前表格和其他表格改变的数据 + emits('update:changedApis', { + ...department.changedApis, + ...changed, + }); } }, selectedRowKeys: ref([]), }; const save = async () => { - // fix: #bug10828 - // 当前节点表格数据id - // const currenTableKeys = props.tableData.map((m: any) => m.id); - // // 当前表格选中的id - // const currentSelectedKeys = rowSelection.selectedRowKeys.value.filter( - // (key: string) => currenTableKeys.includes(key), - // ); - // // 当前表格, 原有选中的id - // const oldSelectedKeys = currenTableKeys.filter((key) => - // props.sourceKeys.includes(key), - // ); - const keys = props.selectedRowKeys; + // 移除的key const removeKeys = props.sourceKeys.filter((key) => !keys.includes(key)); + // 新选中的key const addKeys = keys.filter((key) => !props.sourceKeys.includes(key)); - // console.log('addKeys: ', addKeys); - // console.log('removeKeys: ', removeKeys); - // 取消选择的数据项 - // const removeKeys = oldSelectedKeys.filter( - // (key) => !currentSelectedKeys.includes(key), - // ); - // // 新增选择的项 - // const addKeys = currentSelectedKeys.filter( - // (key) => !oldSelectedKeys.includes(key), - // ); if (props.mode === 'api') { // 此时是api配置 @@ -163,14 +146,10 @@ const save = async () => { const removeItems = removeKeys.map((key) => ({ id: key, permissions: props.changedApis[key]?.security, - // permissions: props.tableData.find((f: any) => f.id === key) - // ?.security, })); const addItems = addKeys.map((key) => ({ id: key, permissions: props.changedApis[key]?.security, - // permissions: props.tableData.find((f: any) => f.id === key) - // ?.security, })); Promise.all([ updateOperations_api(code, '_delete', { operations: removeItems }), diff --git a/src/views/system/Platforms/Api/index.vue b/src/views/system/Platforms/Api/index.vue index 6d72a575..74beb4c2 100644 --- a/src/views/system/Platforms/Api/index.vue +++ b/src/views/system/Platforms/Api/index.vue @@ -76,6 +76,9 @@ import LeftTree from './components/LeftTree.vue'; import ChooseApi from './components/ChooseApi.vue'; import ApiDoes from './components/ApiDoes.vue'; import ApiTest from './components/ApiTest.vue'; +import { useDepartmentStore } from '@/store/department'; + +const department = useDepartmentStore(); const props = defineProps<{ mode: modeType; @@ -157,12 +160,20 @@ function getSelectKeys() { } } -// watch( -// () => changedApis.value, -// (val: any) => { -// console.log('changedApis: ', val); -// }, -// ); +watch( + () => selectedKeys.value, + (val: any) => { + // console.log('selectedKeys: ', val); + department.setSelectedKeys(val); + }, +); +watch( + () => changedApis.value, + (val: any) => { + // console.log('changedApis: ', val); + department.setChangedApis(val); + }, +);