From d3d72f843e27fa365d12dbcc804402f5c0f9d019 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 16 Jan 2025 23:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E5=B0=8F=E5=8C=BA=20=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/user/UserList.vue | 176 +++++++++++++++++++++++++++++++++--- 1 file changed, 161 insertions(+), 15 deletions(-) diff --git a/src/views/user/UserList.vue b/src/views/user/UserList.vue index 29cefe5..80b7430 100644 --- a/src/views/user/UserList.vue +++ b/src/views/user/UserList.vue @@ -8,6 +8,16 @@
+ + + + +
@@ -125,6 +143,29 @@ + + + + + + + + + @@ -199,10 +240,16 @@ export default defineComponent({ key: 'create_time', width: 180, }, + { + title: '所属小区', + dataIndex: 'community_name', + key: 'community_name', + width: 200 + }, { title: '操作', key: 'action', - width: 120, + width: 200, fixed: 'right' } ] @@ -215,7 +262,8 @@ export default defineComponent({ // 添加筛选表单 const filterForm = ref({ - role: undefined + role: undefined, + phone: undefined }) // 获取用户列表数据 @@ -225,9 +273,17 @@ export default defineComponent({ const params = { skip: (pagination.value.current - 1) * pagination.value.pageSize, limit: pagination.value.pageSize, - role: filterForm.value.role // 添加角色筛选参数 + role: filterForm.value.role, + phone: filterForm.value.phone // 添加手机号参数 } + // 移除空值参数 + Object.keys(params).forEach(key => { + if (params[key] === undefined || params[key] === '') { + delete params[key] + } + }) + const res = await getUserList(params) if (res.code === 200) { tableData.value = res.data.items @@ -272,11 +328,25 @@ export default defineComponent({ return colorMap[role] || 'default' } + // 共用的状态 + const currentUserId = ref(null) + // 角色编辑相关状态 const roleModalVisible = ref(false) const rolesSaving = ref(false) const selectedRoles = ref([]) - const currentUserId = ref(null) + + // 密码重置相关状态 + const passwordModalVisible = ref(false) + const newPassword = ref('') + const passwordInput = ref(null) + + // 小区相关状态 + const communityModalVisible = ref(false) + const communitySaving = ref(false) + const communityLoading = ref(false) + const selectedCommunityId = ref(undefined) + const communityOptions = ref([]) // 可选角色列表 const availableRoles = [ @@ -285,7 +355,7 @@ export default defineComponent({ { label: '配送员', value: 'deliveryman' } ] - // 打开角色编辑模态框 + // 角色编辑处理函数 const handleEditRoles = (record) => { currentUserId.value = record.userid selectedRoles.value = record.roles || ['user'] @@ -326,11 +396,10 @@ export default defineComponent({ } } - // 取消角色修改 + // 修改取消处理函数 const handleRolesCancel = () => { roleModalVisible.value = false - selectedRoles.value = [] - currentUserId.value = null + resetStates() } // 处理筛选变化 @@ -346,16 +415,14 @@ export default defineComponent({ // 重置按钮点击 const handleReset = () => { - filterForm.value.role = undefined + filterForm.value = { + role: undefined, + phone: undefined + } pagination.value.current = 1 fetchData() } - // 密码重置相关状态 - const passwordModalVisible = ref(false) - const newPassword = ref('') - const passwordInput = ref(null) - // 生成随机密码 const generatePassword = () => { const chars = '0123456789abcdefghijklmnopqrstuvwxyz' @@ -407,10 +474,72 @@ export default defineComponent({ const handleClosePasswordModal = () => { passwordModalVisible.value = false newPassword.value = '' + resetStates() + } + + // 获取小区列表 + const fetchCommunityList = async () => { + try { + communityLoading.value = true + const res = await request.get('/api/community') + if (res.code === 200 && res.data) { + communityOptions.value = res.data.items || [] + } + } catch (error) { + console.error('获取小区列表失败:', error) + message.error('获取小区列表失败') + } finally { + communityLoading.value = false + } + } + + // 小区编辑处理函数 + const handleEditCommunity = (record) => { + currentUserId.value = record.userid + selectedCommunityId.value = record.community_id + communityModalVisible.value = true + + if (communityOptions.value.length === 0) { + fetchCommunityList() + } + } + + // 保存小区修改 + const handleCommunitySave = async () => { + try { + communitySaving.value = true + await request.put('/api/user/community', { + user_id: currentUserId.value, + community_id: selectedCommunityId.value + }) + + message.success('修改成功') + communityModalVisible.value = false + fetchData() // 刷新列表 + } catch (error) { + console.error('修改所属小区失败:', error) + message.error('修改失败') + } finally { + communitySaving.value = false + } + } + + // 修改取消处理函数 + const handleCommunityCancel = () => { + communityModalVisible.value = false + resetStates() + } + + // 重置状态的函数 + const resetStates = () => { + currentUserId.value = null + selectedRoles.value = [] + selectedCommunityId.value = undefined } onMounted(() => { fetchData() + fetchCommunityList() // 预加载小区列表 }) return { @@ -438,7 +567,16 @@ export default defineComponent({ passwordInput, handleResetPassword, handleCopyPassword, - handleClosePasswordModal + handleClosePasswordModal, + communityModalVisible, + communitySaving, + communityLoading, + selectedCommunityId, + communityOptions, + handleEditCommunity, + handleCommunitySave, + handleCommunityCancel, + currentUserId } } }) @@ -519,4 +657,12 @@ export default defineComponent({ font-size: 16px; text-align: center; } + +:deep(.ant-select) { + width: 100% !important; +} + +:deep(.ant-input) { + width: 200px !important; +} \ No newline at end of file