fix: bug#11106

This commit is contained in:
JiangQiming 2023-03-30 16:20:16 +08:00
parent 2bccd21378
commit a75f2a3fd6
3 changed files with 34 additions and 39 deletions

View File

@ -5,6 +5,7 @@ type DepartmentStateType = {
productId: string; productId: string;
optType: string | undefined; optType: string | undefined;
crossPageKeys: string[]; crossPageKeys: string[];
changedApis: any;
} }
export const useDepartmentStore = defineStore({ export const useDepartmentStore = defineStore({
@ -16,6 +17,7 @@ export const useDepartmentStore = defineStore({
// 2. optType === ': 产品资产分配后, 自动弹出设备资产分配 // 2. optType === ': 产品资产分配后, 自动弹出设备资产分配
optType: '', optType: '',
crossPageKeys: [], // 表格跨页多选的keys crossPageKeys: [], // 表格跨页多选的keys
changedApis: {},
}), }),
actions: { actions: {
setProductId(value: string) { setProductId(value: string) {
@ -27,6 +29,9 @@ export const useDepartmentStore = defineStore({
setSelectedKeys(value: string[], type?: string) { setSelectedKeys(value: string[], type?: string) {
// 分页保留选中项 // 分页保留选中项
this.crossPageKeys = type === 'concat' ? [...new Set([...this.crossPageKeys, ...value])] : value; this.crossPageKeys = type === 'concat' ? [...new Set([...this.crossPageKeys, ...value])] : value;
},
setChangedApis(value: any) {
this.changedApis = { ...this.changedApis, ...value };
} }
} }
}) })

View File

@ -37,6 +37,9 @@ import {
} from '@/api/system/apiPage'; } from '@/api/system/apiPage';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { modeType } from '../typing'; import { modeType } from '../typing';
import { useDepartmentStore } from '@/store/department';
const department = useDepartmentStore();
const emits = defineEmits([ const emits = defineEmits([
'refresh', 'refresh',
'update:clickApi', 'update:clickApi',
@ -64,11 +67,6 @@ const columns = [
dataIndex: 'summary', dataIndex: 'summary',
key: 'summary', key: 'summary',
}, },
// {
// title: 'ID',
// dataIndex: 'id',
// key: 'id',
// },
]; ];
const rowSelection = { const rowSelection = {
// onSelect: (record: any) => { // onSelect: (record: any) => {
@ -95,7 +93,7 @@ const rowSelection = {
props.sourceKeys.includes(key), props.sourceKeys.includes(key),
); );
// , // ,
const otherSelectedKeys = props.sourceKeys.filter( const otherSelectedKeys = department.crossPageKeys.filter(
(key) => !currenTableKeys.includes(key), (key) => !currenTableKeys.includes(key),
); );
@ -103,6 +101,7 @@ const rowSelection = {
const removeKeys = oldSelectedKeys.filter((key) => !keys.includes(key)); const removeKeys = oldSelectedKeys.filter((key) => !keys.includes(key));
// //
const addKeys = keys.filter((key) => !oldSelectedKeys.includes(key)); const addKeys = keys.filter((key) => !oldSelectedKeys.includes(key));
//
emits('update:selectedRowKeys', [...otherSelectedKeys, ...keys]); emits('update:selectedRowKeys', [...otherSelectedKeys, ...keys]);
// / // /
@ -111,37 +110,21 @@ const rowSelection = {
changed[key] = props.tableData.find((f: any) => f.id === key); changed[key] = props.tableData.find((f: any) => f.id === key);
}); });
if (props.mode === 'appManger') { if (props.mode === 'appManger') {
emits('update:changedApis', changed); //
emits('update:changedApis', {
...department.changedApis,
...changed,
});
} }
}, },
selectedRowKeys: ref<string[]>([]), selectedRowKeys: ref<string[]>([]),
}; };
const save = async () => { 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; const keys = props.selectedRowKeys;
// key
const removeKeys = props.sourceKeys.filter((key) => !keys.includes(key)); const removeKeys = props.sourceKeys.filter((key) => !keys.includes(key));
// key
const addKeys = keys.filter((key) => !props.sourceKeys.includes(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') { if (props.mode === 'api') {
// api // api
@ -163,14 +146,10 @@ const save = async () => {
const removeItems = removeKeys.map((key) => ({ const removeItems = removeKeys.map((key) => ({
id: key, id: key,
permissions: props.changedApis[key]?.security, permissions: props.changedApis[key]?.security,
// permissions: props.tableData.find((f: any) => f.id === key)
// ?.security,
})); }));
const addItems = addKeys.map((key) => ({ const addItems = addKeys.map((key) => ({
id: key, id: key,
permissions: props.changedApis[key]?.security, permissions: props.changedApis[key]?.security,
// permissions: props.tableData.find((f: any) => f.id === key)
// ?.security,
})); }));
Promise.all([ Promise.all([
updateOperations_api(code, '_delete', { operations: removeItems }), updateOperations_api(code, '_delete', { operations: removeItems }),

View File

@ -76,6 +76,9 @@ import LeftTree from './components/LeftTree.vue';
import ChooseApi from './components/ChooseApi.vue'; import ChooseApi from './components/ChooseApi.vue';
import ApiDoes from './components/ApiDoes.vue'; import ApiDoes from './components/ApiDoes.vue';
import ApiTest from './components/ApiTest.vue'; import ApiTest from './components/ApiTest.vue';
import { useDepartmentStore } from '@/store/department';
const department = useDepartmentStore();
const props = defineProps<{ const props = defineProps<{
mode: modeType; mode: modeType;
@ -157,12 +160,20 @@ function getSelectKeys() {
} }
} }
// watch( watch(
// () => changedApis.value, () => selectedKeys.value,
// (val: any) => { (val: any) => {
// console.log('changedApis: ', val); // console.log('selectedKeys: ', val);
// }, department.setSelectedKeys(val);
// ); },
);
watch(
() => changedApis.value,
(val: any) => {
// console.log('changedApis: ', val);
department.setChangedApis(val);
},
);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>