fix: bug#10766

This commit is contained in:
JiangQiming 2023-03-29 22:06:27 +08:00
parent e9f84f959a
commit cea070b35c
2 changed files with 19 additions and 32 deletions

View File

@ -26,8 +26,7 @@ export const useDepartmentStore = defineStore({
}, },
setSelectedKeys(value: string[], type?: string) { setSelectedKeys(value: string[], type?: string) {
// 分页保留选中项 // 分页保留选中项
// this.crossPageKeys = type === 'pagination' ? [...new Set([...this.crossPageKeys, ...value])] : value; this.crossPageKeys = type === 'concat' ? [...new Set([...this.crossPageKeys, ...value])] : value;
this.crossPageKeys = [...new Set([...this.crossPageKeys, ...value])];
} }
} }
}) })

View File

@ -7,9 +7,10 @@
centered centered
:confirmLoading="loading" :confirmLoading="loading"
@ok="confirm" @ok="confirm"
@cancel="emits('update:visible', false)" @cancel="cancel"
> >
<pro-search <pro-search
type="simple"
:columns="columns" :columns="columns"
target="category" target="category"
@search="(params:any)=>queryParams = {...params}" @search="(params:any)=>queryParams = {...params}"
@ -33,7 +34,6 @@
:pagination="{ :pagination="{
showSizeChanger: true, showSizeChanger: true,
pageSizeOptions: ['10', '20', '50', '100'], pageSizeOptions: ['10', '20', '50', '100'],
change: handlePageChange,
}" }"
/> />
</div> </div>
@ -63,7 +63,8 @@ const confirm = () => {
message.success('操作成功'); message.success('操作成功');
emits('confirm'); emits('confirm');
emits('update:visible', false); emits('update:visible', false);
table._selectedRowKeys = []; // table._selectedRowKeys = [];
department.setSelectedKeys([]);
}) })
.finally(() => (loading.value = false)); .finally(() => (loading.value = false));
} else { } else {
@ -72,6 +73,11 @@ const confirm = () => {
} }
}; };
const cancel = () => {
emits('update:visible', false);
department.setSelectedKeys([]);
};
const columns = [ const columns = [
{ {
title: '姓名', title: '姓名',
@ -134,42 +140,24 @@ const table = reactive({
} }
}, },
onSelectChange: (keys: string[]) => { onSelectChange: (keys: string[]) => {
table._selectedRowKeys = keys; // console.log(': ', keys);
// table._selectedRowKeys = keys;
department.setSelectedKeys(keys, keys.length ? 'concat' : '');
}, },
cancelSelect: () => { cancelSelect: () => {
table._selectedRowKeys = []; // console.log(' ', 1111111111);
// table._selectedRowKeys = [];
department.setSelectedKeys([], 'concat');
}, },
}); });
watch( watch(
() => table._selectedRowKeys, () => department.crossPageKeys,
(val: string[]) => { (val: string[]) => {
// console.log('_selectedRowKeys: ', val); // console.log('crossPageKeys: ', val);
department.setSelectedKeys(val); table._selectedRowKeys = val;
// const newKeys = [];
// val.forEach((key: string) => {
// if (!department.crossPageKeys.includes(key)) {
// newKeys.push(key);
// }
// });
// if (newKeys.length) {
// department.setSelectedKeys(val);
// console.log('_selectedRowKeys: ', val);
// }
}, },
); );
// watch(
// () => department.crossPageKeys,
// (val: string[]) => {
// // console.log('crossPageKeys: ', val);
// table._selectedRowKeys = val;
// },
// );
const handlePageChange = () => {
console.log('PageChange');
// department.setSelectedKeys([], 'pagination');
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>