fix: bug#10766

This commit is contained in:
JiangQiming 2023-03-27 20:00:18 +08:00
parent f54b498053
commit 1aae61582e
2 changed files with 49 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import { defineStore } from "pinia";
type DepartmentStateType = {
productId: string;
optType: string | undefined;
crossPageKeys: string[];
}
export const useDepartmentStore = defineStore({
@ -13,14 +14,20 @@ export const useDepartmentStore = defineStore({
// 设备资产分配弹窗操作类型:
// 1. optType === 'handle': 手动点击资产分配按钮;
// 2. optType === ': 产品资产分配后, 自动弹出设备资产分配
optType: ''
optType: '',
crossPageKeys: [], // 表格跨页多选的keys
}),
actions: {
setProductId(value: string) {
this.productId = value
this.productId = value;
},
setType(value: string | undefined) {
this.optType = value
this.optType = value;
},
setSelectedKeys(value: string[], type?: string) {
// 分页保留选中项
// this.crossPageKeys = type === 'pagination' ? [...new Set([...this.crossPageKeys, ...value])] : value;
this.crossPageKeys = [...new Set([...this.crossPageKeys, ...value])];
}
}
})

View File

@ -33,6 +33,7 @@
:pagination="{
showSizeChanger: true,
pageSizeOptions: ['10', '20', '50', '100'],
change: handlePageChange,
}"
/>
</div>
@ -42,6 +43,9 @@
<script setup lang="ts">
import { bindUser_api, getBindUserList_api } from '@/api/system/department';
import { message } from 'jetlinks-ui-components';
import { useDepartmentStore } from '@/store/department';
const department = useDepartmentStore();
const emits = defineEmits(['confirm', 'update:visible']);
@ -52,17 +56,19 @@ const props = defineProps<{
//
const loading = ref(false);
const confirm = () => {
if (table._selectedRowKeys.length && props.parentId) {
if (department.crossPageKeys.length && props.parentId) {
loading.value = true;
bindUser_api(props.parentId, table._selectedRowKeys)
bindUser_api(props.parentId, department.crossPageKeys)
.then(() => {
message.success('操作成功');
emits('confirm');
emits('update:visible', false);
table._selectedRowKeys = [];
})
.finally(() => (loading.value = false));
} else {
emits('update:visible', false);
// emits('update:visible', false);
message.warning('请选择要绑定的用户');
}
};
@ -134,6 +140,36 @@ const table = reactive({
table._selectedRowKeys = [];
},
});
watch(
() => table._selectedRowKeys,
(val: string[]) => {
// console.log('_selectedRowKeys: ', val);
department.setSelectedKeys(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>
<style lang="less" scoped>