fix: bug#11106

This commit is contained in:
JiangQiming 2023-03-30 15:51:16 +08:00
parent 57af547bfb
commit c88706282f
2 changed files with 66 additions and 35 deletions

View File

@ -64,6 +64,11 @@ 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) => {
@ -83,43 +88,60 @@ const rowSelection = {
// } // }
// }, // },
onChange: (keys: string[]) => { onChange: (keys: string[]) => {
// rowSelection.selectedRowKeys.value = keys; // id
emits('update:selectedRowKeys', keys); const currenTableKeys = props.tableData.map((m: any) => m.id);
keys.forEach((key: string) => { // , id
if (props.mode === 'appManger') { const oldSelectedKeys = currenTableKeys.filter((key) =>
emits('update:changedApis', { props.sourceKeys.includes(key),
...props.changedApis, );
[key]: props.tableData.find((f: any) => f.id === key), // ,
}); const otherSelectedKeys = props.sourceKeys.filter(
} (key) => !currenTableKeys.includes(key),
);
//
const removeKeys = oldSelectedKeys.filter((key) => !keys.includes(key));
//
const addKeys = keys.filter((key) => !oldSelectedKeys.includes(key));
emits('update:selectedRowKeys', [...otherSelectedKeys, ...keys]);
// /
const changed = {};
[...addKeys, ...removeKeys].forEach((key: string) => {
changed[key] = props.tableData.find((f: any) => f.id === key);
}); });
if (props.mode === 'appManger') {
emits('update:changedApis', changed);
}
}, },
selectedRowKeys: ref<string[]>([]), selectedRowKeys: ref<string[]>([]),
}; };
const save = async () => { const save = async () => {
// fix: #bug10828 // fix: #bug10828
// id // id
const currenTableKeys = props.tableData.map((m: any) => m.id); // const currenTableKeys = props.tableData.map((m: any) => m.id);
// id // // id
const currentSelectedKeys = rowSelection.selectedRowKeys.value.filter( // const currentSelectedKeys = rowSelection.selectedRowKeys.value.filter(
(key: string) => currenTableKeys.includes(key), // (key: string) => currenTableKeys.includes(key),
); // );
// , id // // , id
const oldSelectedKeys = currenTableKeys.filter((key) => // const oldSelectedKeys = currenTableKeys.filter((key) =>
props.sourceKeys.includes(key), // props.sourceKeys.includes(key),
); // );
// const keys = props.selectedRowKeys; const keys = props.selectedRowKeys;
// const removeKeys = props.sourceKeys.filter((key) => !keys.includes(key)); const removeKeys = props.sourceKeys.filter((key) => !keys.includes(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( // const removeKeys = oldSelectedKeys.filter(
(key) => !currentSelectedKeys.includes(key), // (key) => !currentSelectedKeys.includes(key),
); // );
// // //
const addKeys = currentSelectedKeys.filter( // const addKeys = currentSelectedKeys.filter(
(key) => !oldSelectedKeys.includes(key), // (key) => !oldSelectedKeys.includes(key),
); // );
if (props.mode === 'api') { if (props.mode === 'api') {
// api // api
@ -140,15 +162,15 @@ const save = async () => {
} else if (props.mode === 'appManger') { } else if (props.mode === 'appManger') {
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) // permissions: props.tableData.find((f: any) => f.id === key)
?.security, // ?.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) // permissions: props.tableData.find((f: any) => f.id === key)
?.security, // ?.security,
})); }));
Promise.all([ Promise.all([
updateOperations_api(code, '_delete', { operations: removeItems }), updateOperations_api(code, '_delete', { operations: removeItems }),
@ -161,9 +183,11 @@ const save = async () => {
}); });
} }
}; };
watch( watch(
() => props.selectedRowKeys, () => props.selectedRowKeys,
(n) => { (n) => {
// console.log('props.selectedRowKeys: ', n);
rowSelection.selectedRowKeys.value = n; rowSelection.selectedRowKeys.value = n;
}, },
); );

View File

@ -109,7 +109,7 @@ const treeSelect = (node: treeNodeTpye, nodeSchemas: object = {}) => {
tableData.value = table; tableData.value = table;
}; };
const activeKey = ref<'does' | 'test'>('does'); const activeKey = ref<'does' | 'test'>('does');
const schemas = ref({}); // api const schemas = ref({}); // api
const initSelectedApi: apiDetailsType = { const initSelectedApi: apiDetailsType = {
url: '', url: '',
@ -156,6 +156,13 @@ function getSelectKeys() {
}); });
} }
} }
// watch(
// () => changedApis.value,
// (val: any) => {
// console.log('changedApis: ', val);
// },
// );
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>