diff --git a/src/views/system/Platforms/Api/components/ChooseApi.vue b/src/views/system/Platforms/Api/components/ChooseApi.vue index c61338a5..166ce578 100644 --- a/src/views/system/Platforms/Api/components/ChooseApi.vue +++ b/src/views/system/Platforms/Api/components/ChooseApi.vue @@ -64,6 +64,11 @@ const columns = [ dataIndex: 'summary', key: 'summary', }, + // { + // title: 'ID', + // dataIndex: 'id', + // key: 'id', + // }, ]; const rowSelection = { // onSelect: (record: any) => { @@ -83,43 +88,60 @@ const rowSelection = { // } // }, onChange: (keys: string[]) => { - // rowSelection.selectedRowKeys.value = keys; - emits('update:selectedRowKeys', keys); - keys.forEach((key: string) => { - if (props.mode === 'appManger') { - emits('update:changedApis', { - ...props.changedApis, - [key]: props.tableData.find((f: any) => f.id === key), - }); - } + // 当前节点表格数据id + const currenTableKeys = props.tableData.map((m: any) => m.id); + // 当前表格, 原有选中的id + const oldSelectedKeys = currenTableKeys.filter((key) => + props.sourceKeys.includes(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([]), }; 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 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 removeKeys = props.sourceKeys.filter((key) => !keys.includes(key)); - // const addKeys = keys.filter((key) => !props.sourceKeys.includes(key)); + const keys = props.selectedRowKeys; + const removeKeys = props.sourceKeys.filter((key) => !keys.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), - ); + // const removeKeys = oldSelectedKeys.filter( + // (key) => !currentSelectedKeys.includes(key), + // ); + // // 新增选择的项 + // const addKeys = currentSelectedKeys.filter( + // (key) => !oldSelectedKeys.includes(key), + // ); if (props.mode === 'api') { // 此时是api配置 @@ -140,15 +162,15 @@ const save = async () => { } else if (props.mode === 'appManger') { const removeItems = removeKeys.map((key) => ({ id: key, - // permissions: props.changedApis[key]?.security, - permissions: props.tableData.find((f: any) => f.id === key) - ?.security, + 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, + permissions: props.changedApis[key]?.security, + // permissions: props.tableData.find((f: any) => f.id === key) + // ?.security, })); Promise.all([ updateOperations_api(code, '_delete', { operations: removeItems }), @@ -161,9 +183,11 @@ const save = async () => { }); } }; + watch( () => props.selectedRowKeys, (n) => { + // console.log('props.selectedRowKeys: ', n); rowSelection.selectedRowKeys.value = n; }, ); diff --git a/src/views/system/Platforms/Api/index.vue b/src/views/system/Platforms/Api/index.vue index 6678b973..6d72a575 100644 --- a/src/views/system/Platforms/Api/index.vue +++ b/src/views/system/Platforms/Api/index.vue @@ -109,7 +109,7 @@ const treeSelect = (node: treeNodeTpye, nodeSchemas: object = {}) => { tableData.value = table; }; -const activeKey = ref<'does' | 'test'>('does'); +const activeKey = ref<'does' | 'test'>('does'); const schemas = ref({}); // 对应一级api相关的类 const initSelectedApi: apiDetailsType = { url: '', @@ -156,6 +156,13 @@ function getSelectKeys() { }); } } + +// watch( +// () => changedApis.value, +// (val: any) => { +// console.log('changedApis: ', val); +// }, +// );