提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
|
|
3 |
<el-row :gutter="20"> |
|
4 |
<!-- 左侧部门树 --> |
|
5 |
<el-col :span="4" :xs="24"> |
|
6 |
<ContentWrap class="h-1/1"> |
|
7 |
<DeptTree @node-click="handleDeptNodeClick" /> |
|
8 |
</ContentWrap> |
|
9 |
</el-col> |
|
10 |
<el-col :span="20" :xs="24"> |
|
11 |
<!-- 搜索 --> |
|
12 |
<ContentWrap> |
|
13 |
<el-form |
|
14 |
class="-mb-15px" |
|
15 |
:model="queryParams" |
|
16 |
ref="queryFormRef" |
|
17 |
:inline="true" |
|
18 |
label-width="68px" |
|
19 |
> |
|
20 |
<el-form-item label="用户名称" prop="username"> |
|
21 |
<el-input |
|
22 |
v-model="queryParams.username" |
|
23 |
placeholder="请输入用户名称" |
|
24 |
clearable |
|
25 |
@keyup.enter="handleQuery" |
|
26 |
class="!w-240px" |
|
27 |
/> |
|
28 |
</el-form-item> |
|
29 |
<el-form-item label="手机号码" prop="mobile"> |
|
30 |
<el-input |
|
31 |
v-model="queryParams.mobile" |
|
32 |
placeholder="请输入手机号码" |
|
33 |
clearable |
|
34 |
@keyup.enter="handleQuery" |
|
35 |
class="!w-240px" |
|
36 |
/> |
|
37 |
</el-form-item> |
|
38 |
<el-form-item label="状态" prop="status"> |
|
39 |
<el-select |
|
40 |
v-model="queryParams.status" |
|
41 |
placeholder="用户状态" |
|
42 |
clearable |
|
43 |
class="!w-240px" |
|
44 |
> |
|
45 |
<el-option |
|
46 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
47 |
:key="dict.value" |
|
48 |
:label="dict.label" |
|
49 |
:value="dict.value" |
|
50 |
/> |
|
51 |
</el-select> |
|
52 |
</el-form-item> |
|
53 |
<el-form-item label="创建时间" prop="createTime"> |
|
54 |
<el-date-picker |
|
55 |
v-model="queryParams.createTime" |
|
56 |
value-format="YYYY-MM-DD HH:mm:ss" |
|
57 |
type="datetimerange" |
|
58 |
start-placeholder="开始日期" |
|
59 |
end-placeholder="结束日期" |
|
60 |
class="!w-240px" |
|
61 |
/> |
|
62 |
</el-form-item> |
|
63 |
<el-form-item> |
|
64 |
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button> |
|
65 |
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button> |
|
66 |
<el-button |
|
67 |
type="primary" |
|
68 |
plain |
|
69 |
@click="openForm('create')" |
|
70 |
v-hasPermi="['system:user:create']" |
|
71 |
> |
|
72 |
<Icon icon="ep:plus" /> 新增 |
|
73 |
</el-button> |
|
74 |
<el-button |
|
75 |
type="warning" |
|
76 |
plain |
|
77 |
@click="handleImport" |
|
78 |
v-hasPermi="['system:user:import']" |
|
79 |
> |
|
80 |
<Icon icon="ep:upload" /> 导入 |
|
81 |
</el-button> |
|
82 |
<el-button |
|
83 |
type="success" |
|
84 |
plain |
|
85 |
@click="handleExport" |
|
86 |
:loading="exportLoading" |
|
87 |
v-hasPermi="['system:user:export']" |
|
88 |
> |
|
89 |
<Icon icon="ep:download" />导出 |
|
90 |
</el-button> |
|
91 |
</el-form-item> |
|
92 |
</el-form> |
|
93 |
</ContentWrap> |
|
94 |
<ContentWrap> |
|
95 |
<el-table v-loading="loading" :data="list"> |
|
96 |
<el-table-column label="用户编号" align="center" key="id" prop="id" /> |
|
97 |
<el-table-column |
|
98 |
label="用户名称" |
|
99 |
align="center" |
|
100 |
prop="username" |
|
101 |
:show-overflow-tooltip="true" |
|
102 |
/> |
|
103 |
<el-table-column |
|
104 |
label="用户昵称" |
|
105 |
align="center" |
|
106 |
prop="nickname" |
|
107 |
:show-overflow-tooltip="true" |
|
108 |
/> |
|
109 |
<el-table-column |
|
110 |
label="部门" |
|
111 |
align="center" |
|
112 |
key="deptName" |
|
113 |
prop="deptName" |
|
114 |
:show-overflow-tooltip="true" |
|
115 |
/> |
|
116 |
<el-table-column label="手机号码" align="center" prop="mobile" width="120" /> |
|
117 |
<el-table-column label="状态" key="status"> |
|
118 |
<template #default="scope"> |
|
119 |
<el-switch |
|
120 |
v-model="scope.row.status" |
|
121 |
:active-value="0" |
|
122 |
:inactive-value="1" |
|
123 |
@change="handleStatusChange(scope.row)" |
|
124 |
/> |
|
125 |
</template> |
|
126 |
</el-table-column> |
|
127 |
<el-table-column |
|
128 |
label="创建时间" |
|
129 |
align="center" |
|
130 |
prop="createTime" |
|
131 |
:formatter="dateFormatter" |
|
132 |
width="180" |
|
133 |
/> |
|
134 |
<el-table-column label="操作" align="center" width="160"> |
|
135 |
<template #default="scope"> |
|
136 |
<div class="flex items-center justify-center"> |
|
137 |
<el-button |
|
138 |
type="primary" |
|
139 |
link |
|
140 |
@click="openForm('update', scope.row.id)" |
|
141 |
v-hasPermi="['system:user:update']" |
|
142 |
> |
|
143 |
<Icon icon="ep:edit" />修改 |
|
144 |
</el-button> |
|
145 |
<el-dropdown |
|
146 |
@command="(command) => handleCommand(command, scope.row)" |
|
147 |
v-hasPermi="[ |
|
148 |
'system:user:delete', |
|
149 |
'system:user:update-password', |
|
150 |
'system:permission:assign-user-role' |
|
151 |
]" |
|
152 |
> |
|
153 |
<el-button type="primary" link><Icon icon="ep:d-arrow-right" /> 更多</el-button> |
|
154 |
<template #dropdown> |
|
155 |
<el-dropdown-menu> |
|
156 |
<el-dropdown-item |
|
157 |
command="handleDelete" |
|
158 |
v-if="checkPermi(['system:user:delete'])" |
|
159 |
> |
|
160 |
<Icon icon="ep:delete" />删除 |
|
161 |
</el-dropdown-item> |
|
162 |
<el-dropdown-item |
|
163 |
command="handleResetPwd" |
|
164 |
v-if="checkPermi(['system:user:update-password'])" |
|
165 |
> |
|
166 |
<Icon icon="ep:key" />重置密码 |
|
167 |
</el-dropdown-item> |
|
168 |
<el-dropdown-item |
|
169 |
command="handleRole" |
|
170 |
v-if="checkPermi(['system:permission:assign-user-role'])" |
|
171 |
> |
|
172 |
<Icon icon="ep:circle-check" />分配角色 |
|
173 |
</el-dropdown-item> |
|
174 |
</el-dropdown-menu> |
|
175 |
</template> |
|
176 |
</el-dropdown> |
|
177 |
</div> |
|
178 |
</template> |
|
179 |
</el-table-column> |
|
180 |
</el-table> |
|
181 |
<Pagination |
|
182 |
:total="total" |
|
183 |
v-model:page="queryParams.pageNo" |
|
184 |
v-model:limit="queryParams.pageSize" |
|
185 |
@pagination="getList" |
|
186 |
/> |
|
187 |
</ContentWrap> |
|
188 |
</el-col> |
|
189 |
</el-row> |
|
190 |
|
|
191 |
<!-- 添加或修改用户对话框 --> |
|
192 |
<UserForm ref="formRef" @success="getList" /> |
|
193 |
<!-- 用户导入对话框 --> |
|
194 |
<UserImportForm ref="importFormRef" @success="getList" /> |
|
195 |
<!-- 分配角色 --> |
|
196 |
<UserAssignRoleForm ref="assignRoleFormRef" @success="getList" /> |
|
197 |
</template> |
|
198 |
<script lang="ts" setup> |
|
199 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
200 |
import { checkPermi } from '@/utils/permission' |
|
201 |
import { dateFormatter } from '@/utils/formatTime' |
|
202 |
import download from '@/utils/download' |
|
203 |
import { CommonStatusEnum } from '@/utils/constants' |
|
204 |
import * as UserApi from '@/api/system/user' |
|
205 |
import UserForm from './UserForm.vue' |
|
206 |
import UserImportForm from './UserImportForm.vue' |
|
207 |
import UserAssignRoleForm from './UserAssignRoleForm.vue' |
|
208 |
import DeptTree from './DeptTree.vue' |
|
209 |
|
|
210 |
defineOptions({ name: 'SystemUser' }) |
|
211 |
|
|
212 |
const message = useMessage() // 消息弹窗 |
|
213 |
const { t } = useI18n() // 国际化 |
|
214 |
|
|
215 |
const loading = ref(true) // 列表的加载中 |
|
216 |
const total = ref(0) // 列表的总页数 |
|
217 |
const list = ref([]) // 列表的数 |
|
218 |
const queryParams = reactive({ |
|
219 |
pageNo: 1, |
|
220 |
pageSize: 10, |
|
221 |
username: undefined, |
|
222 |
mobile: undefined, |
|
223 |
status: undefined, |
|
224 |
deptId: undefined, |
|
225 |
createTime: [] |
|
226 |
}) |
|
227 |
const queryFormRef = ref() // 搜索的表单 |
|
228 |
|
|
229 |
/** 查询列表 */ |
|
230 |
const getList = async () => { |
|
231 |
loading.value = true |
|
232 |
try { |
|
233 |
const data = await UserApi.getUserPage(queryParams) |
|
234 |
list.value = data.list |
|
235 |
total.value = data.total |
|
236 |
} finally { |
|
237 |
loading.value = false |
|
238 |
} |
|
239 |
} |
|
240 |
|
|
241 |
/** 搜索按钮操作 */ |
|
242 |
const handleQuery = () => { |
|
243 |
queryParams.pageNo = 1 |
|
244 |
getList() |
|
245 |
} |
|
246 |
|
|
247 |
/** 重置按钮操作 */ |
|
248 |
const resetQuery = () => { |
|
249 |
queryFormRef.value?.resetFields() |
|
250 |
handleQuery() |
|
251 |
} |
|
252 |
|
|
253 |
/** 处理部门被点击 */ |
|
254 |
const handleDeptNodeClick = async (row) => { |
|
255 |
queryParams.deptId = row.id |
|
256 |
await getList() |
|
257 |
} |
|
258 |
|
|
259 |
/** 添加/修改操作 */ |
|
260 |
const formRef = ref() |
|
261 |
const openForm = (type: string, id?: number) => { |
|
262 |
formRef.value.open(type, id) |
|
263 |
} |
|
264 |
|
|
265 |
/** 用户导入 */ |
|
266 |
const importFormRef = ref() |
|
267 |
const handleImport = () => { |
|
268 |
importFormRef.value.open() |
|
269 |
} |
|
270 |
|
|
271 |
/** 修改用户状态 */ |
|
272 |
const handleStatusChange = async (row: UserApi.UserVO) => { |
|
273 |
try { |
|
274 |
// 修改状态的二次确认 |
|
275 |
const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用' |
|
276 |
await message.confirm('确认要"' + text + '""' + row.username + '"用户吗?') |
|
277 |
// 发起修改状态 |
|
278 |
await UserApi.updateUserStatus(row.id, row.status) |
|
279 |
// 刷新列表 |
|
280 |
await getList() |
|
281 |
} catch { |
|
282 |
// 取消后,进行恢复按钮 |
|
283 |
row.status = |
|
284 |
row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
/** 导出按钮操作 */ |
|
289 |
const exportLoading = ref(false) |
|
290 |
const handleExport = async () => { |
|
291 |
try { |
|
292 |
// 导出的二次确认 |
|
293 |
await message.exportConfirm() |
|
294 |
// 发起导出 |
|
295 |
exportLoading.value = true |
|
296 |
const data = await UserApi.exportUser(queryParams) |
|
297 |
download.excel(data, '用户数据.xls') |
|
298 |
} catch { |
|
299 |
} finally { |
|
300 |
exportLoading.value = false |
|
301 |
} |
|
302 |
} |
|
303 |
|
|
304 |
/** 操作分发 */ |
|
305 |
const handleCommand = (command: string, row: UserApi.UserVO) => { |
|
306 |
switch (command) { |
|
307 |
case 'handleDelete': |
|
308 |
handleDelete(row.id) |
|
309 |
break |
|
310 |
case 'handleResetPwd': |
|
311 |
handleResetPwd(row) |
|
312 |
break |
|
313 |
case 'handleRole': |
|
314 |
handleRole(row) |
|
315 |
break |
|
316 |
default: |
|
317 |
break |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
/** 删除按钮操作 */ |
|
322 |
const handleDelete = async (id: number) => { |
|
323 |
try { |
|
324 |
// 删除的二次确认 |
|
325 |
await message.delConfirm() |
|
326 |
// 发起删除 |
|
327 |
await UserApi.deleteUser(id) |
|
328 |
message.success(t('common.delSuccess')) |
|
329 |
// 刷新列表 |
|
330 |
await getList() |
|
331 |
} catch {} |
|
332 |
} |
|
333 |
|
|
334 |
/** 重置密码 */ |
|
335 |
const handleResetPwd = async (row: UserApi.UserVO) => { |
|
336 |
try { |
|
337 |
// 重置的二次确认 |
|
338 |
const result = await message.prompt( |
|
339 |
'请输入"' + row.username + '"的新密码', |
|
340 |
t('common.reminder') |
|
341 |
) |
|
342 |
const password = result.value |
|
343 |
// 发起重置 |
|
344 |
await UserApi.resetUserPwd(row.id, password) |
|
345 |
message.success('修改成功,新密码是:' + password) |
|
346 |
} catch {} |
|
347 |
} |
|
348 |
|
|
349 |
/** 分配角色 */ |
|
350 |
const assignRoleFormRef = ref() |
|
351 |
const handleRole = (row: UserApi.UserVO) => { |
|
352 |
assignRoleFormRef.value.open(row) |
|
353 |
} |
|
354 |
|
|
355 |
/** 初始化 */ |
|
356 |
onMounted(() => { |
|
357 |
getList() |
|
358 |
}) |
|
359 |
</script> |