¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div> |
| | | <el-dialog v-model="userDialog.visible.value" :title="userDialog.title.value" width="80%" append-to-body> |
| | | <el-row :gutter="20"> |
| | | <!-- é¨é¨æ --> |
| | | <el-col :lg="4" :xs="24" style=""> |
| | | <el-card shadow="hover"> |
| | | <el-input v-model="deptName" placeholder="请è¾å
¥é¨é¨åç§°" prefix-icon="Search" clearable /> |
| | | <el-tree |
| | | ref="deptTreeRef" |
| | | class="mt-2" |
| | | node-key="id" |
| | | :data="deptOptions" |
| | | :props="{ label: 'label', children: 'children' }" |
| | | :expand-on-click-node="false" |
| | | :filter-node-method="filterNode" |
| | | highlight-current |
| | | default-expand-all |
| | | @node-click="handleNodeClick" |
| | | /> |
| | | </el-card> |
| | | </el-col> |
| | | <el-col :lg="20" :xs="24"> |
| | | <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-item label="ç¨æ·åç§°" prop="userName"> |
| | | <el-input v-model="queryParams.userName" placeholder="请è¾å
¥ç¨æ·åç§°" clearable style="width: 200px" @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-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" icon="Search" @click="handleQuery">æç´¢</el-button> |
| | | <el-button icon="Refresh" @click="resetQuery">éç½®</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-card> |
| | | </div> |
| | | </transition> |
| | | |
| | | <el-card shadow="hover"> |
| | | <template #header> |
| | | <el-tag v-for="user in selectUserList" :key="user.userId" closable style="margin: 2px" @close="handleCloseTag(user)"> |
| | | {{ user.userName }} |
| | | </el-tag> |
| | | </template> |
| | | |
| | | <vxe-table |
| | | ref="tableRef" |
| | | height="400px" |
| | | border |
| | | show-overflow |
| | | :data="userList" |
| | | :loading="loading" |
| | | :row-config="{ keyField: 'userId' }" |
| | | :checkbox-config="{ reserve: true, checkRowKeys: userIds }" |
| | | highlight-current-row |
| | | @checkbox-all="handleCheckboxAll" |
| | | @checkbox-change="handleCheckboxChange" |
| | | > |
| | | <vxe-column type="checkbox" width="50" align="center" /> |
| | | <vxe-column key="userId" title="ç¨æ·ç¼å·" align="center" field="userId" /> |
| | | <vxe-column key="userName" title="ç¨æ·åç§°" align="center" field="userName" /> |
| | | <vxe-column key="nickName" title="ç¨æ·æµç§°" align="center" field="nickName" /> |
| | | <vxe-column key="deptName" title="é¨é¨" align="center" field="deptName" /> |
| | | <vxe-column key="phonenumber" title="ææºå·ç " align="center" field="phonenumber" width="120" /> |
| | | <vxe-column key="status" title="ç¶æ" align="center"> |
| | | <template #default="scope"> |
| | | <dict-tag :options="sys_normal_disable" :value="scope.row.status"></dict-tag> |
| | | </template> |
| | | </vxe-column> |
| | | |
| | | <vxe-column title="å建æ¶é´" align="center" width="160"> |
| | | <template #default="scope"> |
| | | <span>{{ scope.row.createTime }}</span> |
| | | </template> |
| | | </vxe-column> |
| | | </vxe-table> |
| | | |
| | | <pagination |
| | | v-show="total > 0" |
| | | v-model:page="queryParams.pageNum" |
| | | v-model:limit="queryParams.pageSize" |
| | | :total="total" |
| | | @pagination="getList" |
| | | /> |
| | | </el-card> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | | <template #footer> |
| | | <el-button @click="userDialog.closeDialog">åæ¶</el-button> |
| | | <el-button type="primary" @click="confirm">ç¡®å®</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <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 { VxeTableInstance } from 'vxe-table'; |
| | | import useDialog from '@/hooks/useDialog'; |
| | | |
| | | interface PropType { |
| | | modelValue?: UserVO[]; |
| | | } |
| | | const prop = withDefaults(defineProps<PropType>(), { |
| | | modelValue: () => [] |
| | | }); |
| | | const emit = defineEmits(['update:modelValue']); |
| | | |
| | | 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 showSearch = ref(true); |
| | | const total = ref(0); |
| | | const dateRange = ref<[DateModelType, DateModelType]>(['', '']); |
| | | const deptName = ref(''); |
| | | const deptOptions = ref<DeptVO[]>([]); |
| | | const selectUserList = ref<UserVO[]>([]); |
| | | |
| | | const deptTreeRef = ref<ElTreeInstance>(); |
| | | const queryFormRef = ref<ElFormInstance>(); |
| | | const tableRef = ref<VxeTableInstance<UserVO>>(); |
| | | |
| | | const userDialog = useDialog({ |
| | | title: 'ç¨æ·éæ©' |
| | | }); |
| | | |
| | | const queryParams = ref<UserQuery>({ |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | userName: '', |
| | | phonenumber: '', |
| | | status: '', |
| | | deptId: '', |
| | | roleId: '' |
| | | }); |
| | | |
| | | /** éè¿æ¡ä»¶è¿æ»¤èç¹ */ |
| | | const filterNode = (value: string, data: any) => { |
| | | if (!value) return true; |
| | | return data.label.indexOf(value) !== -1; |
| | | }; |
| | | /** æ ¹æ®åç§°çéé¨é¨æ */ |
| | | watchEffect( |
| | | () => { |
| | | deptTreeRef.value?.filter(deptName.value); |
| | | }, |
| | | { |
| | | flush: 'post' // watchEffectä¼å¨DOMæè½½æè
æ´æ°ä¹åå°±ä¼è§¦åï¼æ¤å±æ§æ§å¶å¨DOMå
ç´ æ´æ°åè¿è¡ |
| | | } |
| | | ); |
| | | |
| | | const confirm = () => { |
| | | emit('update:modelValue', [...selectUserList.value]); |
| | | userDialog.closeDialog(); |
| | | }; |
| | | |
| | | /** æ¥è¯¢é¨é¨ä¸ææ ç»æ */ |
| | | const getTreeSelect = async () => { |
| | | const res = await api.deptTreeSelect(); |
| | | deptOptions.value = res.data; |
| | | }; |
| | | |
| | | /** æ¥è¯¢ç¨æ·å表 */ |
| | | const getList = async () => { |
| | | loading.value = true; |
| | | const res = await api.listUser(proxy?.addDateRange(queryParams.value, dateRange.value)); |
| | | loading.value = false; |
| | | userList.value = res.rows; |
| | | total.value = res.total; |
| | | }; |
| | | |
| | | /** èç¹åå»äºä»¶ */ |
| | | const handleNodeClick = (data: DeptVO) => { |
| | | queryParams.value.deptId = data.id; |
| | | handleQuery(); |
| | | }; |
| | | |
| | | /** æç´¢æé®æä½ */ |
| | | const handleQuery = () => { |
| | | queryParams.value.pageNum = 1; |
| | | getList(); |
| | | }; |
| | | /** éç½®æé®æä½ */ |
| | | const resetQuery = () => { |
| | | dateRange.value = ['', '']; |
| | | queryFormRef.value?.resetFields(); |
| | | queryParams.value.pageNum = 1; |
| | | queryParams.value.deptId = undefined; |
| | | deptTreeRef.value?.setCurrentKey(undefined); |
| | | handleQuery(); |
| | | }; |
| | | |
| | | const handleCheckboxChange = (checked) => { |
| | | const row = checked.row; |
| | | if (checked.checked) { |
| | | selectUserList.value.push(row); |
| | | } else { |
| | | selectUserList.value = selectUserList.value.filter((item) => { |
| | | return item.userId !== row.userId; |
| | | }); |
| | | } |
| | | }; |
| | | const handleCheckboxAll = (checked) => { |
| | | const rows = userList.value; |
| | | if (checked.checked) { |
| | | rows.forEach((row) => { |
| | | if (!selectUserList.value.some((item) => item.userId === row.userId)) { |
| | | selectUserList.value.push(row); |
| | | } |
| | | }); |
| | | } else { |
| | | selectUserList.value = selectUserList.value.filter((item) => { |
| | | return !rows.some((row) => row.userId === item.userId); |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | const handleCloseTag = (user: UserVO) => { |
| | | const userId = user.userId; |
| | | 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(); |
| | | }); |
| | | |
| | | defineExpose({ |
| | | open: userDialog.openDialog, |
| | | close: userDialog.closeDialog |
| | | }); |
| | | </script> |
| | | |
| | | <style lang="scss" scoped></style> |