update 修改用户选择组件获取数据逻辑

This commit is contained in:
LiuHao 2024-01-28 19:42:47 +08:00
parent 02210db064
commit 4b99f1e7b8

View File

@ -89,7 +89,7 @@
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>
@ -158,15 +158,6 @@ const confirm = () => {
userDialog.closeDialog(); userDialog.closeDialog();
}; };
const refreshDefaultUser = async (data) => {
const ids = computedIds(data);
if (ids.length > 0) {
// const { data } = await api.optionSelect(ids);
// await tableRef.value?.setCheckboxRow(data, true);
// selectUserList.value = data;
}
};
const computedIds = (data) => { const computedIds = (data) => {
if (data instanceof Array) { if (data instanceof Array) {
return [...data]; return [...data];
@ -180,17 +171,8 @@ const computedIds = (data) => {
} }
}; };
const defaultSelectUserIds = computed(() => { const defaultSelectUserIds = computed(() => computedIds(prop.data));
return computedIds(prop.data);
});
watch(
() => prop.data,
(newVal) => {
refreshDefaultUser(newVal);
},
{ deep: true }
);
/** 根据名称筛选部门树 */ /** 根据名称筛选部门树 */
watchEffect( watchEffect(
() => { () => {
@ -222,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 defaultSelectUserIds.value.includes(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;
@ -281,15 +271,17 @@ const handleCloseTag = (user: UserVO) => {
selectUserList.value.splice(index, 1); selectUserList.value.splice(index, 1);
}; };
const initData = async () => { const initSelectUser = async () => {
const { data } = await api.optionSelect(defaultSelectUserIds.value); if (defaultSelectUserIds.value.length > 0) {
selectUserList.value = data; const { data } = await api.optionSelect(defaultSelectUserIds.value);
selectUserList.value = data;
}
}; };
onMounted(() => { onMounted(() => {
initSelectUser();
getTreeSelect(); // getTreeSelect(); //
getList(); // getList(); //
initData();
}); });
defineExpose({ defineExpose({