| | |
| | | <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave"> |
| | | <div v-show="showSearch" class="mb-[10px]"> |
| | | <el-card shadow="hover"> |
| | | <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="68px"> |
| | | <el-form ref="queryFormRef" :model="queryParams" :inline="true"> |
| | | <el-form-item label="用户名称" prop="userName"> |
| | | <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable style="width: 200px" @keyup.enter="handleQuery" /> |
| | | <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" /> |
| | | </el-form-item> |
| | | <el-form-item label="手机号码" prop="phonenumber"> |
| | | <el-input |
| | | v-model="queryParams.phonenumber" |
| | | placeholder="请输入手机号码" |
| | | clearable |
| | | style="width: 200px" |
| | | @keyup.enter="handleQuery" |
| | | /> |
| | | <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable @keyup.enter="handleQuery" /> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button> |
| | | <el-button icon="Refresh" @click="resetQuery">重置</el-button> |
| | | <el-button icon="Refresh" @click="() => resetQuery()">重置</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-card> |
| | |
| | | </transition> |
| | | |
| | | <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)"> |
| | | {{ user.userName }} |
| | | {{ user.nickName }} |
| | | </el-tag> |
| | | </template> |
| | | |
| | |
| | | show-overflow |
| | | :data="userList" |
| | | :loading="loading" |
| | | :row-config="{ keyField: 'userId' }" |
| | | :checkbox-config="{ reserve: true, checkRowKeys: userIds }" |
| | | highlight-current-row |
| | | :row-config="{ keyField: 'userId', isHover: true }" |
| | | :checkbox-config="{ reserve: true, trigger: 'row', highlight: true, showHeader: prop.multiple }" |
| | | @checkbox-all="handleCheckboxAll" |
| | | @checkbox-change="handleCheckboxChange" |
| | | > |
| | |
| | | v-model:page="queryParams.pageNum" |
| | | v-model:limit="queryParams.pageSize" |
| | | :total="total" |
| | | @pagination="getList" |
| | | @pagination="pageList" |
| | | /> |
| | | </el-card> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <template #footer> |
| | | <el-button @click="userDialog.closeDialog">取消</el-button> |
| | | <el-button @click="close">取消</el-button> |
| | | <el-button type="primary" @click="confirm">确定</el-button> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | <script setup lang="ts"> |
| | | import api from '@/api/system/user'; |
| | | import { UserQuery, UserVO } from '@/api/system/user/types'; |
| | | import { DeptVO } from '@/api/system/dept/types'; |
| | | import { DeptTreeVO, DeptVO } from '@/api/system/dept/types'; |
| | | import { VxeTableInstance } from 'vxe-table'; |
| | | import useDialog from '@/hooks/useDialog'; |
| | | |
| | | interface PropType { |
| | | modelValue?: UserVO[]; |
| | | modelValue?: UserVO[] | UserVO | undefined; |
| | | multiple?: boolean; |
| | | data?: string | number | (string | number)[] | undefined; |
| | | } |
| | | 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 { 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 loading = ref(true); |
| | |
| | | const total = ref(0); |
| | | const dateRange = ref<[DateModelType, DateModelType]>(['', '']); |
| | | const deptName = ref(''); |
| | | const deptOptions = ref<DeptVO[]>([]); |
| | | const deptOptions = ref<DeptTreeVO[]>([]); |
| | | const selectUserList = ref<UserVO[]>([]); |
| | | |
| | | const deptTreeRef = ref<ElTreeInstance>(); |
| | |
| | | roleId: '' |
| | | }); |
| | | |
| | | /** 通过条件过滤节点 */ |
| | | const filterNode = (value: string, data: any) => { |
| | | if (!value) return true; |
| | | return data.label.indexOf(value) !== -1; |
| | | }; |
| | | const defaultSelectUserIds = computed(() => computedIds(prop.data)); |
| | | |
| | | /** 根据名称筛选部门树 */ |
| | | watchEffect( |
| | | () => { |
| | |
| | | ); |
| | | |
| | | const confirm = () => { |
| | | emit('update:modelValue', [...selectUserList.value]); |
| | | emit('update:modelValue', selectUserList.value); |
| | | emit('confirmCallBack', selectUserList.value); |
| | | userDialog.closeDialog(); |
| | | }; |
| | | |
| | | const computedIds = (data) => { |
| | | if (data instanceof Array) { |
| | | return data.map(item => String(item)); |
| | | } 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; |
| | | }; |
| | | |
| | | /** 查询部门下拉树结构 */ |
| | |
| | | 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) => { |
| | | queryParams.value.deptId = data.id; |
| | |
| | | getList(); |
| | | }; |
| | | /** 重置按钮操作 */ |
| | | const resetQuery = () => { |
| | | const resetQuery = (refresh = true) => { |
| | | dateRange.value = ['', '']; |
| | | queryFormRef.value?.resetFields(); |
| | | queryParams.value.pageNum = 1; |
| | | queryParams.value.deptId = undefined; |
| | | deptTreeRef.value?.setCurrentKey(undefined); |
| | | handleQuery(); |
| | | refresh && handleQuery(); |
| | | }; |
| | | |
| | | const handleCheckboxChange = (checked) => { |
| | | if (!prop.multiple && checked.checked) { |
| | | tableRef.value.setCheckboxRow(selectUserList.value, false); |
| | | selectUserList.value = []; |
| | | } |
| | | const row = checked.row; |
| | | if (checked.checked) { |
| | | selectUserList.value.push(row); |
| | |
| | | |
| | | const handleCloseTag = (user: UserVO) => { |
| | | const userId = user.userId; |
| | | // 使用split删除用户 |
| | | const index = selectUserList.value.findIndex((item) => item.userId === userId); |
| | | const rows = selectUserList.value[index]; |
| | | tableRef.value?.setCheckboxRow(rows, false); |
| | | selectUserList.value.splice(index, 1); |
| | | }; |
| | | watch( |
| | | () => prop.modelValue, |
| | | (newVal, oldValue) => { |
| | | Object.assign(selectUserList.value, newVal); |
| | | }, |
| | | { deep: true } |
| | | ); |
| | | |
| | | onMounted(() => { |
| | | getTreeSelect(); |
| | | getList(); |
| | | }); |
| | | 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( |
| | | () => userDialog.visible.value, |
| | | async (newValue: boolean) => { |
| | | if (newValue) { |
| | | await getTreeSelect(); // 初始化部门数据 |
| | | await getList(); // 初始化列表数据 |
| | | await initSelectUser(); |
| | | } else { |
| | | tableRef.value.clearCheckboxReserve(); |
| | | tableRef.value.clearCheckboxRow(); |
| | | resetQuery(false); |
| | | selectUserList.value = []; |
| | | } |
| | | } |
| | | ); |
| | | |
| | | defineExpose({ |
| | | open: userDialog.openDialog, |
| | |
| | | }); |
| | | </script> |
| | | |
| | | <style lang="scss" scoped></style> |
| | | <style lang="scss" scoped></style> |