fix 修复设计器无法选人问题,修复抄送打开弹出选中全部人员问题

This commit is contained in:
gssong 2024-03-07 21:18:08 +08:00
parent 6f9851a4e5
commit d50c90afd1
3 changed files with 160 additions and 53 deletions

View File

@ -59,7 +59,7 @@ const taskId = ref<string>('');
// //
const selectCopyUserList = ref<UserVO[]>([]); const selectCopyUserList = ref<UserVO[]>([]);
//id //id
const selectCopyUserIds = ref<string>(''); const selectCopyUserIds = ref<string>(undefined);
const dialog = reactive<DialogOption>({ const dialog = reactive<DialogOption>({
@ -76,7 +76,7 @@ const form = ref<Record<string, any>>({
}); });
// //
const openDialog = (id?: string) => { const openDialog = (id?: string) => {
selectCopyUserIds.value = '' selectCopyUserIds.value = undefined
selectCopyUserList.value = [] selectCopyUserList.value = []
form.value.fileId = undefined form.value.fileId = undefined
taskId.value = id; taskId.value = id;

View File

@ -36,7 +36,7 @@
:data="roleList" :data="roleList"
:loading="loading" :loading="loading"
:row-config="{ keyField: 'roleId' }" :row-config="{ keyField: 'roleId' }"
:checkbox-config="{ reserve: true, checkRowKeys: roleIds }" :checkbox-config="{ reserve: true, checkRowKeys: defaultSelectRoleIds }"
highlight-current-row highlight-current-row
@checkbox-all="handleCheckboxAll" @checkbox-all="handleCheckboxAll"
@checkbox-change="handleCheckboxChange" @checkbox-change="handleCheckboxChange"
@ -63,42 +63,41 @@
v-model:total="total" v-model:total="total"
v-model:page="queryParams.pageNum" v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
@pagination="getList" @pagination="pageList"
/> />
</el-card> </el-card>
<template #footer> <template #footer>
<el-button @click="roleDialog.closeDialog">取消</el-button> <el-button @click="close">取消</el-button>
<el-button type="primary" @click="confirm">确定</el-button> <el-button type="primary" @click="confirm">确定</el-button>
</template> </template>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script setup name="Role" lang="ts"> <script setup lang="ts">
import { listRole } from '@/api/system/role';
import { RoleVO, RoleQuery } from '@/api/system/role/types'; import { RoleVO, RoleQuery } from '@/api/system/role/types';
import { VxeTableInstance } from 'vxe-table'; import { VxeTableInstance } from 'vxe-table';
import useDialog from '@/hooks/useDialog'; import useDialog from '@/hooks/useDialog';
import api from '@/api/system/role';
interface PropType { interface PropType {
modelValue?: RoleVO[]; modelValue?: RoleVO[] | RoleVO | undefined;
multiple?: boolean;
data?: string | number | (string | number)[];
} }
const prop = withDefaults(defineProps<PropType>(), { const prop = withDefaults(defineProps<PropType>(), {
modelValue: () => [] multiple: true,
modelValue: undefined,
data: undefined
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue', 'confirmCallBack']);
const router = useRouter(); const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_normal_disable } = toRefs<any>(proxy?.useDict('sys_normal_disable')); const { sys_normal_disable } = toRefs<any>(proxy?.useDict('sys_normal_disable'));
const roleIds = computed(() => prop.modelValue.map((item) => item.roleId as string));
const roleList = ref<RoleVO[]>(); const roleList = ref<RoleVO[]>();
const loading = ref(true); const loading = ref(true);
const showSearch = ref(true); const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0); const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']); const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const selectRoleList = ref<RoleVO[]>([]); const selectRoleList = ref<RoleVO[]>([]);
@ -117,22 +116,46 @@ const queryParams = ref<RoleQuery>({
roleKey: '', roleKey: '',
status: '' status: ''
}); });
const defaultSelectRoleIds = computed(() => computedIds(prop.data));
const confirm = () => { const confirm = () => {
emit('update:modelValue', [...selectRoleList.value]); emit('update:modelValue', selectRoleList.value);
emit('confirmCallBack', selectRoleList.value);
roleDialog.closeDialog(); roleDialog.closeDialog();
}; };
const computedIds = (data) => {
if (data instanceof Array) {
return [...data];
} else if (typeof data === 'string') {
return data.split(',');
} else if (typeof data === 'number') {
return [data];
} else {
console.warn('<RoleSelect> The data type of data should be array or string or number, but I received other');
return [];
}
};
/** /**
* 查询角色列表 * 查询角色列表
*/ */
const getList = () => { const getList = () => {
loading.value = true; loading.value = true;
listRole(proxy?.addDateRange(queryParams.value, dateRange.value)).then((res) => { api.listRole(proxy?.addDateRange(queryParams.value, dateRange.value)).then((res) => {
roleList.value = res.rows; roleList.value = res.rows;
total.value = res.total; total.value = res.total;
loading.value = false; loading.value = false;
}); });
}; };
const pageList = async () => {
await getList();
const roles = roleList.value.filter((item) => {
return selectRoleList.value.some((role) => role.roleId === item.roleId);
});
await tableRef.value.setCheckboxRow(roles, true);
};
/** /**
* 搜索按钮操作 * 搜索按钮操作
*/ */
@ -149,6 +172,10 @@ const resetQuery = () => {
}; };
const handleCheckboxChange = (checked) => { const handleCheckboxChange = (checked) => {
if (!prop.multiple && checked.checked) {
tableRef.value.setCheckboxRow(selectRoleList.value, false);
selectRoleList.value = [];
}
const row = checked.row; const row = checked.row;
if (checked.checked) { if (checked.checked) {
selectRoleList.value.push(row); selectRoleList.value.push(row);
@ -181,19 +208,43 @@ const handleCloseTag = (user: RoleVO) => {
tableRef.value?.setCheckboxRow(rows, false); tableRef.value?.setCheckboxRow(rows, false);
selectRoleList.value.splice(index, 1); selectRoleList.value.splice(index, 1);
}; };
/**
* 初始化选中数据
*/
const initSelectRole = async () => {
if (defaultSelectRoleIds.value.length > 0) {
const { data } = await api.optionSelect(defaultSelectRoleIds.value);
selectRoleList.value = data;
const users = roleList.value.filter((item) => {
return defaultSelectRoleIds.value.includes(String(item.roleId));
});
await nextTick(() => {
tableRef.value.setCheckboxRow(users, true);
});
}
};
const close = () => {
roleDialog.closeDialog();
};
watch( watch(
() => prop.modelValue, () => roleDialog.visible.value,
(newVal, oldValue) => { (newValue: boolean) => {
Object.assign(selectRoleList.value, newVal); if (newValue) {
}, initSelectRole();
{ deep: true } } else {
tableRef.value.clearCheckboxReserve();
tableRef.value.clearCheckboxRow();
resetQuery();
selectRoleList.value = [];
}
}
); );
onMounted(() => {
getList(); //
});
defineExpose({ defineExpose({
open: roleDialog.openDialog, open: roleDialog.openDialog,
close: roleDialog.closeDialog close: roleDialog.closeDialog
}); });
onMounted(() => {
getList();
});
</script> </script>

View File

@ -47,7 +47,7 @@
</transition> </transition>
<el-card shadow="hover"> <el-card shadow="hover">
<template #header> <template v-if="prop.multiple" #header>
<el-tag v-for="user in selectUserList" :key="user.userId" closable style="margin: 2px" @close="handleCloseTag(user)"> <el-tag v-for="user in selectUserList" :key="user.userId" closable style="margin: 2px" @close="handleCloseTag(user)">
{{ user.userName }} {{ user.userName }}
</el-tag> </el-tag>
@ -60,9 +60,8 @@
show-overflow show-overflow
:data="userList" :data="userList"
:loading="loading" :loading="loading"
:row-config="{ keyField: 'userId' }" :row-config="{ keyField: 'userId', isHover: true }"
:checkbox-config="{ reserve: true, checkRowKeys: userIds }" :checkbox-config="{ reserve: true, trigger: 'row', highlight: true, showHeader: prop.multiple }"
highlight-current-row
@checkbox-all="handleCheckboxAll" @checkbox-all="handleCheckboxAll"
@checkbox-change="handleCheckboxChange" @checkbox-change="handleCheckboxChange"
> >
@ -90,14 +89,14 @@
v-model:page="queryParams.pageNum" v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
:total="total" :total="total"
@pagination="getList" @pagination="pageList"
/> />
</el-card> </el-card>
</el-col> </el-col>
</el-row> </el-row>
<template #footer> <template #footer>
<el-button @click="userDialog.closeDialog">取消</el-button> <el-button @click="close">取消</el-button>
<el-button type="primary" @click="confirm">确定</el-button> <el-button type="primary" @click="confirm">确定</el-button>
</template> </template>
</el-dialog> </el-dialog>
@ -112,18 +111,20 @@ import { VxeTableInstance } from 'vxe-table';
import useDialog from '@/hooks/useDialog'; import useDialog from '@/hooks/useDialog';
interface PropType { interface PropType {
modelValue?: UserVO[]; modelValue?: UserVO[] | UserVO | undefined;
multiple?: boolean;
data?: string | number | (string | number)[];
} }
const prop = withDefaults(defineProps<PropType>(), { const prop = withDefaults(defineProps<PropType>(), {
modelValue: () => [] multiple: true,
modelValue: undefined,
data: undefined
}); });
const emit = defineEmits(['update:modelValue']); const emit = defineEmits(['update:modelValue', 'confirmCallBack']);
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_normal_disable } = toRefs<any>(proxy?.useDict('sys_normal_disable')); const { sys_normal_disable } = toRefs<any>(proxy?.useDict('sys_normal_disable'));
const userIds = computed(() => prop.modelValue.map((item) => item.userId as string));
const userList = ref<UserVO[]>(); const userList = ref<UserVO[]>();
const loading = ref(true); const loading = ref(true);
const showSearch = ref(true); const showSearch = ref(true);
@ -151,11 +152,8 @@ const queryParams = ref<UserQuery>({
roleId: '' roleId: ''
}); });
/** 通过条件过滤节点 */ const defaultSelectUserIds = computed(() => computedIds(prop.data));
const filterNode = (value: string, data: any) => {
if (!value) return true;
return data.label.indexOf(value) !== -1;
};
/** 根据名称筛选部门树 */ /** 根据名称筛选部门树 */
watchEffect( watchEffect(
() => { () => {
@ -167,10 +165,30 @@ watchEffect(
); );
const confirm = () => { const confirm = () => {
emit('update:modelValue', [...selectUserList.value]); emit('update:modelValue', selectUserList.value);
emit('confirmCallBack', selectUserList.value);
userDialog.closeDialog(); userDialog.closeDialog();
}; };
const computedIds = (data) => {
if (data instanceof Array) {
return [...data];
} else if (typeof data === 'string') {
return data.split(',');
} else if (typeof data === 'number') {
return [data];
} else {
console.warn('<UserSelect> The data type of data should be array or string or number, but I received other');
return [];
}
};
/** 通过条件过滤节点 */
const filterNode = (value: string, data: any) => {
if (!value) return true;
return data.label.indexOf(value) !== -1;
};
/** 查询部门下拉树结构 */ /** 查询部门下拉树结构 */
const getTreeSelect = async () => { const getTreeSelect = async () => {
const res = await api.deptTreeSelect(); const res = await api.deptTreeSelect();
@ -186,6 +204,14 @@ const getList = async () => {
total.value = res.total; total.value = res.total;
}; };
const pageList = async () => {
await getList();
const users = userList.value.filter((item) => {
return selectUserList.value.some((user) => user.userId === item.userId);
});
await tableRef.value.setCheckboxRow(users, true);
};
/** 节点单击事件 */ /** 节点单击事件 */
const handleNodeClick = (data: DeptVO) => { const handleNodeClick = (data: DeptVO) => {
queryParams.value.deptId = data.id; queryParams.value.deptId = data.id;
@ -208,6 +234,10 @@ const resetQuery = () => {
}; };
const handleCheckboxChange = (checked) => { const handleCheckboxChange = (checked) => {
if (!prop.multiple && checked.checked) {
tableRef.value.setCheckboxRow(selectUserList.value, false);
selectUserList.value = [];
}
const row = checked.row; const row = checked.row;
if (checked.checked) { if (checked.checked) {
selectUserList.value.push(row); selectUserList.value.push(row);
@ -234,22 +264,48 @@ const handleCheckboxAll = (checked) => {
const handleCloseTag = (user: UserVO) => { const handleCloseTag = (user: UserVO) => {
const userId = user.userId; const userId = user.userId;
// 使split
const index = selectUserList.value.findIndex((item) => item.userId === userId); const index = selectUserList.value.findIndex((item) => item.userId === userId);
const rows = selectUserList.value[index]; const rows = selectUserList.value[index];
tableRef.value?.setCheckboxRow(rows, false); tableRef.value?.setCheckboxRow(rows, false);
selectUserList.value.splice(index, 1); selectUserList.value.splice(index, 1);
}; };
const initSelectUser = async () => {
if (defaultSelectUserIds.value.length > 0) {
const { data } = await api.optionSelect(defaultSelectUserIds.value);
selectUserList.value = data;
const users = userList.value.filter((item) => {
return defaultSelectUserIds.value.includes(String(item.userId));
});
await nextTick(() => {
tableRef.value.setCheckboxRow(users, true);
});
}
};
const close = () => {
userDialog.closeDialog();
};
watch( watch(
() => prop.modelValue, () => userDialog.visible.value,
(newVal, oldValue) => { (newValue: boolean) => {
Object.assign(selectUserList.value, newVal); console.log(selectUserList.value)
},
{ deep: true } if (newValue) {
initSelectUser();
} else {
tableRef.value.clearCheckboxReserve();
tableRef.value.clearCheckboxRow();
resetQuery();
selectUserList.value = [];
}
}
); );
onMounted(() => { onMounted(() => {
getTreeSelect(); getTreeSelect(); //
getList(); getList(); //
}); });
defineExpose({ defineExpose({