|
@@ -0,0 +1,547 @@
|
|
1
|
+<template>
|
|
2
|
+ <div class="p-2 auto-overflow-y">
|
|
3
|
+ <el-row :gutter="20">
|
|
4
|
+ <!-- 部门树-->
|
|
5
|
+ <el-col :lg="4" :xs="24" style="">
|
|
6
|
+ <el-card shadow="hover" class="h-800px">
|
|
7
|
+ <el-input v-model="deptName" placeholder="请输入部门名称" prefix-icon="Search" clearable />
|
|
8
|
+ <el-tree
|
|
9
|
+ ref="deptTreeRef"
|
|
10
|
+ class="mt-2 w-full h-800px overflow-auto inline-block"
|
|
11
|
+ node-key="id"
|
|
12
|
+ :data="deptOptions"
|
|
13
|
+ :props="{ label: 'label', children: 'children' }"
|
|
14
|
+ :expand-on-click-node="false"
|
|
15
|
+ :filter-node-method="filterNode"
|
|
16
|
+ highlight-current
|
|
17
|
+ default-expand-all
|
|
18
|
+ @node-click="handleNodeClick"
|
|
19
|
+ />
|
|
20
|
+ </el-card>
|
|
21
|
+ </el-col>
|
|
22
|
+ <el-col :lg="20" :xs="24">
|
|
23
|
+ <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
|
24
|
+ <div v-show="showSearch" class="mb-[5px]">
|
|
25
|
+ <el-card shadow="hover">
|
|
26
|
+ <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="auto" class="-mb-25px -mt-5px">
|
|
27
|
+ <el-form-item label="用户姓名" prop="realName">
|
|
28
|
+ <el-input v-model="queryParams.realName" placeholder="请输入用户姓名" clearable @keyup.enter="handleQuery" />
|
|
29
|
+ </el-form-item>
|
|
30
|
+ <el-form-item label="手机号码" prop="phone">
|
|
31
|
+ <el-input v-model="queryParams.phone" placeholder="请输入手机号码" clearable @keyup.enter="handleQuery" />
|
|
32
|
+ </el-form-item>
|
|
33
|
+ <el-form-item>
|
|
34
|
+ <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
|
35
|
+ <el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
|
36
|
+ </el-form-item>
|
|
37
|
+ </el-form>
|
|
38
|
+ </el-card>
|
|
39
|
+ </div>
|
|
40
|
+ </transition>
|
|
41
|
+ <el-card shadow="hover">
|
|
42
|
+ <template #header>
|
|
43
|
+ <el-row :gutter="10">
|
|
44
|
+ <el-col :span="1.5">
|
|
45
|
+ <el-button v-has-permi="['system:user:add']" type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
|
|
46
|
+ </el-col>
|
|
47
|
+ <el-col :span="1.5">
|
|
48
|
+ <el-button v-has-permi="['system:user:add']" type="success" plain :disabled="single" icon="Edit" @click="handleUpdate()">
|
|
49
|
+ 修改
|
|
50
|
+ </el-button>
|
|
51
|
+ </el-col>
|
|
52
|
+ <el-col :span="1.5">
|
|
53
|
+ <el-button v-has-permi="['system:user:delete']" type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete()">
|
|
54
|
+ 删除
|
|
55
|
+ </el-button>
|
|
56
|
+ </el-col>
|
|
57
|
+ <el-col :span="1.5">
|
|
58
|
+ <el-dropdown class="mt-[1px]">
|
|
59
|
+ <el-button plain type="info">
|
|
60
|
+ 更多
|
|
61
|
+ <el-icon class="el-icon--right"><arrow-down /></el-icon
|
|
62
|
+ ></el-button>
|
|
63
|
+ <template #dropdown>
|
|
64
|
+ <el-dropdown-menu>
|
|
65
|
+ <el-dropdown-item icon="Download" @click="importTemplate">下载模板</el-dropdown-item>
|
|
66
|
+ <el-dropdown-item icon="Top" @click="handleImport"> 导入数据</el-dropdown-item>
|
|
67
|
+ <el-dropdown-item icon="Download" @click="handleExport"> 导出数据</el-dropdown-item>
|
|
68
|
+ </el-dropdown-menu>
|
|
69
|
+ </template>
|
|
70
|
+ </el-dropdown>
|
|
71
|
+ </el-col>
|
|
72
|
+ <right-toolbar v-model:showSearch="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
|
|
73
|
+ </el-row>
|
|
74
|
+ </template>
|
|
75
|
+ <el-table v-loading="loading" :data="userList" height="calc(100vh - 22rem)" @selection-change="handleSelectionChange">
|
|
76
|
+ <el-table-column type="selection" width="50" align="center" />
|
|
77
|
+ <el-table-column v-if="columns[0].visible" key="userId" label="用户编号" align="center" prop="userId" />
|
|
78
|
+ <el-table-column v-if="columns[1].visible" key="userName" label="用户名称" align="center" prop="userName" :show-overflow-tooltip="true" />
|
|
79
|
+ <el-table-column v-if="columns[2].visible" key="nickName" label="用户昵称" align="center" prop="nickName" :show-overflow-tooltip="true" />
|
|
80
|
+ <el-table-column v-if="columns[3].visible" key="deptName" label="部门" align="center" prop="deptName" :show-overflow-tooltip="true" />
|
|
81
|
+ <el-table-column v-if="columns[4].visible" key="phonenumber" label="手机号码" align="center" prop="phonenumber" width="120" />
|
|
82
|
+ <el-table-column v-if="columns[5].visible" key="status" label="状态" align="center">
|
|
83
|
+ <template #default="scope">
|
|
84
|
+ <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
|
|
85
|
+ </template>
|
|
86
|
+ </el-table-column>
|
|
87
|
+
|
|
88
|
+ <el-table-column v-if="columns[6].visible" label="创建时间" align="center" prop="createTime" width="160">
|
|
89
|
+ <template #default="scope">
|
|
90
|
+ <span>{{ scope.row.createTime }}</span>
|
|
91
|
+ </template>
|
|
92
|
+ </el-table-column>
|
|
93
|
+
|
|
94
|
+ <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
|
|
95
|
+ <template #default="scope">
|
|
96
|
+ <el-tooltip v-if="scope.row.userId !== 1" content="修改" placement="top">
|
|
97
|
+ <el-button v-hasPermi="['system:user:edit']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
|
|
98
|
+ </el-tooltip>
|
|
99
|
+ <el-tooltip v-if="scope.row.userId !== 1" content="删除" placement="top">
|
|
100
|
+ <el-button v-hasPermi="['system:user:remove']" link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
|
|
101
|
+ </el-tooltip>
|
|
102
|
+
|
|
103
|
+ <el-tooltip v-if="scope.row.userId !== 1" content="重置密码" placement="top">
|
|
104
|
+ <el-button v-hasPermi="['system:user:resetPwd']" link type="primary" icon="Key" @click="handleResetPwd(scope.row)"></el-button>
|
|
105
|
+ </el-tooltip>
|
|
106
|
+
|
|
107
|
+ <el-tooltip v-if="scope.row.userId !== 1" content="分配角色" placement="top">
|
|
108
|
+ <el-button v-hasPermi="['system:user:edit']" link type="primary" icon="CircleCheck" @click="handleAuthRole(scope.row)"></el-button>
|
|
109
|
+ </el-tooltip>
|
|
110
|
+ </template>
|
|
111
|
+ </el-table-column>
|
|
112
|
+ </el-table>
|
|
113
|
+ <pagination
|
|
114
|
+ v-show="total > 0"
|
|
115
|
+ v-model:page="queryParams.pageNum"
|
|
116
|
+ v-model:limit="queryParams.pageSize"
|
|
117
|
+ :total="total"
|
|
118
|
+ @pagination="getList"
|
|
119
|
+ />
|
|
120
|
+ </el-card>
|
|
121
|
+ </el-col>
|
|
122
|
+ </el-row>
|
|
123
|
+ <!-- 添加或修改用户配置对话框 -->
|
|
124
|
+ <user-detail-form ref="userDetailFormRef" apped-to-body @success="getList" />
|
|
125
|
+ <!-- 用户导入对话框 -->
|
|
126
|
+ <el-dialog v-model="upload.open" :title="upload.title" width="400px" append-to-body>
|
|
127
|
+ <el-upload
|
|
128
|
+ ref="uploadRef"
|
|
129
|
+ :limit="1"
|
|
130
|
+ accept=".xlsx, .xls"
|
|
131
|
+ :headers="upload.headers"
|
|
132
|
+ :action="upload.url + '?updateSupport=' + upload.updateSupport"
|
|
133
|
+ :disabled="upload.isUploading"
|
|
134
|
+ :on-progress="handleFileUploadProgress"
|
|
135
|
+ :on-success="handleFileSuccess"
|
|
136
|
+ :auto-upload="false"
|
|
137
|
+ drag
|
|
138
|
+ >
|
|
139
|
+ <el-icon class="el-icon--upload">
|
|
140
|
+ <i-ep-upload-filled />
|
|
141
|
+ </el-icon>
|
|
142
|
+ <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
|
143
|
+ <template #tip>
|
|
144
|
+ <div class="text-center el-upload__tip">
|
|
145
|
+ <div class="el-upload__tip"><el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据</div>
|
|
146
|
+ <span>仅允许导入xls、xlsx格式文件。</span>
|
|
147
|
+ <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
|
|
148
|
+ </div>
|
|
149
|
+ </template>
|
|
150
|
+ </el-upload>
|
|
151
|
+ <template #footer>
|
|
152
|
+ <div class="dialog-footer">
|
|
153
|
+ <el-button type="primary" @click="submitFileForm">确 定</el-button>
|
|
154
|
+ <el-button @click="upload.open = false">取 消</el-button>
|
|
155
|
+ </div>
|
|
156
|
+ </template>
|
|
157
|
+ </el-dialog>
|
|
158
|
+ </div>
|
|
159
|
+</template>
|
|
160
|
+
|
|
161
|
+<script setup name="User" lang="ts">
|
|
162
|
+import api from '@/api/system/right/user';
|
|
163
|
+import { UserForm, UserQuery, UserVO } from '@/api/system/right/user/types';
|
|
164
|
+import { DeptVO } from '@/api/system/dept/types';
|
|
165
|
+import { RoleVO } from '@/api/system/role/types';
|
|
166
|
+import { PostVO } from '@/api/system/params/post/types';
|
|
167
|
+import { treeselect } from '@/api/system/dept';
|
|
168
|
+import { globalHeaders } from '@/utils/request';
|
|
169
|
+import { to } from 'await-to-js';
|
|
170
|
+import UserDetailForm from '@/views/system/right/user/UserDetailForm.vue';
|
|
171
|
+
|
|
172
|
+const router = useRouter();
|
|
173
|
+const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
174
|
+const { sys_normal_disable, sys_user_sex } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_sex'));
|
|
175
|
+const userList = ref<UserVO[]>();
|
|
176
|
+const loading = ref(true);
|
|
177
|
+const showSearch = ref(true);
|
|
178
|
+const ids = ref<Array<number | string>>([]);
|
|
179
|
+const single = ref(true);
|
|
180
|
+const multiple = ref(true);
|
|
181
|
+const total = ref(0);
|
|
182
|
+const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
|
|
183
|
+const deptName = ref('');
|
|
184
|
+const deptOptions = ref<DeptVO[]>([]);
|
|
185
|
+const initPassword = ref<string>('');
|
|
186
|
+const postOptions = ref<PostVO[]>([]);
|
|
187
|
+const roleOptions = ref<RoleVO[]>([]);
|
|
188
|
+/*** 用户导入参数 */
|
|
189
|
+const upload = reactive<ImportOption>({
|
|
190
|
+ // 是否显示弹出层(用户导入)
|
|
191
|
+ open: false,
|
|
192
|
+ // 弹出层标题(用户导入)
|
|
193
|
+ title: '',
|
|
194
|
+ // 是否禁用上传
|
|
195
|
+ isUploading: false,
|
|
196
|
+ // 是否更新已经存在的用户数据
|
|
197
|
+ updateSupport: 0,
|
|
198
|
+ // 设置上传的请求头部
|
|
199
|
+ headers: globalHeaders(),
|
|
200
|
+ // 上传的地址
|
|
201
|
+ url: import.meta.env.VITE_APP_BASE_API + '/system/user/importData'
|
|
202
|
+});
|
|
203
|
+// 列显隐信息
|
|
204
|
+const columns = ref<FieldOption[]>([
|
|
205
|
+ { key: 0, label: `用户编号`, visible: false, children: [] },
|
|
206
|
+ { key: 1, label: `用户名称`, visible: true, children: [] },
|
|
207
|
+ { key: 2, label: `用户昵称`, visible: true, children: [] },
|
|
208
|
+ { key: 3, label: `部门`, visible: true, children: [] },
|
|
209
|
+ { key: 4, label: `手机号码`, visible: true, children: [] },
|
|
210
|
+ { key: 5, label: `状态`, visible: true, children: [] },
|
|
211
|
+ { key: 6, label: `创建时间`, visible: true, children: [] }
|
|
212
|
+]);
|
|
213
|
+const deptTreeRef = ref<ElTreeInstance>();
|
|
214
|
+// 查询客体ref
|
|
215
|
+const queryFormRef = ref<ElFormInstance>();
|
|
216
|
+const userFormRef = ref<ElFormInstance>();
|
|
217
|
+const uploadRef = ref<ElUploadInstance>();
|
|
218
|
+const formDialogRef = ref<ElDialogInstance>();
|
|
219
|
+
|
|
220
|
+const dialog = reactive<DialogOption>({
|
|
221
|
+ visible: false,
|
|
222
|
+ title: ''
|
|
223
|
+});
|
|
224
|
+
|
|
225
|
+const initFormData: UserForm = {
|
|
226
|
+ userId: undefined,
|
|
227
|
+ deptId: undefined,
|
|
228
|
+ userName: '',
|
|
229
|
+ nickName: undefined,
|
|
230
|
+ password: '',
|
|
231
|
+ phonenumber: undefined,
|
|
232
|
+ email: undefined,
|
|
233
|
+ sex: undefined,
|
|
234
|
+ status: '0',
|
|
235
|
+ remark: '',
|
|
236
|
+ postIds: [],
|
|
237
|
+ roleIds: []
|
|
238
|
+};
|
|
239
|
+
|
|
240
|
+const initData: PageData<UserForm, UserQuery> = {
|
|
241
|
+ form: { ...initFormData },
|
|
242
|
+ queryParams: {
|
|
243
|
+ pageNum: 1,
|
|
244
|
+ pageSize: 10,
|
|
245
|
+ userName: '',
|
|
246
|
+ realName: '',
|
|
247
|
+ phone: '',
|
|
248
|
+ status: '',
|
|
249
|
+ deptId: '',
|
|
250
|
+ roleId: ''
|
|
251
|
+ },
|
|
252
|
+ rules: {
|
|
253
|
+ userName: [
|
|
254
|
+ { required: true, message: '用户名称不能为空', trigger: 'blur' },
|
|
255
|
+ {
|
|
256
|
+ min: 2,
|
|
257
|
+ max: 20,
|
|
258
|
+ message: '用户名称长度必须介于 2 和 20 之间',
|
|
259
|
+ trigger: 'blur'
|
|
260
|
+ }
|
|
261
|
+ ],
|
|
262
|
+ nickName: [{ required: true, message: '用户昵称不能为空', trigger: 'blur' }],
|
|
263
|
+ password: [
|
|
264
|
+ { required: true, message: '用户密码不能为空', trigger: 'blur' },
|
|
265
|
+ {
|
|
266
|
+ min: 5,
|
|
267
|
+ max: 20,
|
|
268
|
+ message: '用户密码长度必须介于 5 和 20 之间',
|
|
269
|
+ trigger: 'blur'
|
|
270
|
+ },
|
|
271
|
+ { pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符:< > " \' \\\ |', trigger: 'blur' }
|
|
272
|
+ ],
|
|
273
|
+ email: [
|
|
274
|
+ {
|
|
275
|
+ type: 'email',
|
|
276
|
+ message: '请输入正确的邮箱地址',
|
|
277
|
+ trigger: ['blur', 'change']
|
|
278
|
+ }
|
|
279
|
+ ],
|
|
280
|
+ phonenumber: [
|
|
281
|
+ {
|
|
282
|
+ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
|
283
|
+ message: '请输入正确的手机号码',
|
|
284
|
+ trigger: 'blur'
|
|
285
|
+ }
|
|
286
|
+ ],
|
|
287
|
+ roleIds: [{ required: true, message: '用户角色不能为空', trigger: 'blur' }]
|
|
288
|
+ }
|
|
289
|
+};
|
|
290
|
+const data = reactive<PageData<UserForm, UserQuery>>(initData);
|
|
291
|
+
|
|
292
|
+const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data);
|
|
293
|
+
|
|
294
|
+/** 通过条件过滤节点 */
|
|
295
|
+const filterNode = (value: string, data: any) => {
|
|
296
|
+ if (!value) return true;
|
|
297
|
+ return data.label.indexOf(value) !== -1;
|
|
298
|
+};
|
|
299
|
+/** 根据名称筛选部门树 */
|
|
300
|
+watchEffect(
|
|
301
|
+ () => {
|
|
302
|
+ deptTreeRef.value?.filter(deptName.value);
|
|
303
|
+ },
|
|
304
|
+ {
|
|
305
|
+ flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
|
|
306
|
+ }
|
|
307
|
+);
|
|
308
|
+
|
|
309
|
+/** 查询部门下拉树结构 */
|
|
310
|
+const getTreeSelect = async () => {
|
|
311
|
+ const res = await api.deptTreeSelect();
|
|
312
|
+ deptOptions.value = res.data;
|
|
313
|
+};
|
|
314
|
+
|
|
315
|
+/** 查询用户列表 */
|
|
316
|
+const getList = async () => {
|
|
317
|
+ loading.value = true;
|
|
318
|
+ const res = await api.listUser(proxy?.addDateRange(queryParams.value, dateRange.value));
|
|
319
|
+ loading.value = false;
|
|
320
|
+ userList.value = res.rows;
|
|
321
|
+ total.value = res.total;
|
|
322
|
+};
|
|
323
|
+
|
|
324
|
+/** 节点单击事件 */
|
|
325
|
+const handleNodeClick = (data: DeptVO) => {
|
|
326
|
+ queryParams.value.deptId = data.id;
|
|
327
|
+ handleQuery();
|
|
328
|
+};
|
|
329
|
+
|
|
330
|
+/** 搜索按钮操作 */
|
|
331
|
+const handleQuery = () => {
|
|
332
|
+ queryParams.value.pageNum = 1;
|
|
333
|
+ getList();
|
|
334
|
+};
|
|
335
|
+/** 重置按钮操作 */
|
|
336
|
+const resetQuery = () => {
|
|
337
|
+ dateRange.value = ['', ''];
|
|
338
|
+ queryFormRef.value?.resetFields();
|
|
339
|
+ queryParams.value.pageNum = 1;
|
|
340
|
+ queryParams.value.deptId = undefined;
|
|
341
|
+ deptTreeRef.value?.setCurrentKey(undefined);
|
|
342
|
+ handleQuery();
|
|
343
|
+};
|
|
344
|
+
|
|
345
|
+/** 删除按钮操作 */
|
|
346
|
+const handleDelete = async (row?: UserVO) => {
|
|
347
|
+ const userIds = row?.userId || ids.value;
|
|
348
|
+ const [err] = await to(proxy?.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?') as any);
|
|
349
|
+ if (!err) {
|
|
350
|
+ await api.delUser(userIds);
|
|
351
|
+ await getList();
|
|
352
|
+ proxy?.$modal.msgSuccess('删除成功');
|
|
353
|
+ }
|
|
354
|
+};
|
|
355
|
+
|
|
356
|
+/** 用户状态修改 */
|
|
357
|
+const handleStatusChange = async (row: UserVO) => {
|
|
358
|
+ let text = row.status === '0' ? '启用' : '停用';
|
|
359
|
+ try {
|
|
360
|
+ await proxy?.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?');
|
|
361
|
+ await api.changeUserStatus(row.userId, row.status);
|
|
362
|
+ proxy?.$modal.msgSuccess(text + '成功');
|
|
363
|
+ } catch (err) {
|
|
364
|
+ row.status = row.status === '0' ? '1' : '0';
|
|
365
|
+ }
|
|
366
|
+};
|
|
367
|
+/** 跳转角色分配 */
|
|
368
|
+const handleAuthRole = (row: UserVO) => {
|
|
369
|
+ const userId = row.userId;
|
|
370
|
+ router.push('/system/user-auth/role/' + userId);
|
|
371
|
+};
|
|
372
|
+
|
|
373
|
+/** 重置密码按钮操作 */
|
|
374
|
+const handleResetPwd = async (row: UserVO) => {
|
|
375
|
+ const [err, res] = await to(
|
|
376
|
+ ElMessageBox.prompt('请输入"' + row.userName + '"的新密码', '提示', {
|
|
377
|
+ confirmButtonText: '确定',
|
|
378
|
+ cancelButtonText: '取消',
|
|
379
|
+ closeOnClickModal: false,
|
|
380
|
+ inputPattern: /^.{5,20}$/,
|
|
381
|
+ inputErrorMessage: '用户密码长度必须介于 5 和 20 之间',
|
|
382
|
+ inputValidator: (value) => {
|
|
383
|
+ if (/<|>|"|'|\||\\/.test(value)) {
|
|
384
|
+ return '不能包含非法字符:< > " \' \\\ |';
|
|
385
|
+ }
|
|
386
|
+ }
|
|
387
|
+ })
|
|
388
|
+ );
|
|
389
|
+ if (!err && res) {
|
|
390
|
+ await api.resetUserPwd(row.userId, res.value);
|
|
391
|
+ proxy?.$modal.msgSuccess('修改成功,新密码是:' + res.value);
|
|
392
|
+ }
|
|
393
|
+};
|
|
394
|
+
|
|
395
|
+/** 选择条数 */
|
|
396
|
+const handleSelectionChange = (selection: UserVO[]) => {
|
|
397
|
+ ids.value = selection.map((item) => item.userId);
|
|
398
|
+ single.value = selection.length != 1;
|
|
399
|
+ multiple.value = !selection.length;
|
|
400
|
+};
|
|
401
|
+
|
|
402
|
+/** 导入按钮操作 */
|
|
403
|
+const handleImport = () => {
|
|
404
|
+ upload.title = '用户导入';
|
|
405
|
+ upload.open = true;
|
|
406
|
+};
|
|
407
|
+/** 导出按钮操作 */
|
|
408
|
+const handleExport = () => {
|
|
409
|
+ proxy?.download(
|
|
410
|
+ 'system/user/export',
|
|
411
|
+ {
|
|
412
|
+ ...queryParams.value
|
|
413
|
+ },
|
|
414
|
+ `user_${new Date().getTime()}.xlsx`
|
|
415
|
+ );
|
|
416
|
+};
|
|
417
|
+/** 下载模板操作 */
|
|
418
|
+const importTemplate = () => {
|
|
419
|
+ proxy?.download('system/user/importTemplate', {}, `user_template_${new Date().getTime()}.xlsx`);
|
|
420
|
+};
|
|
421
|
+
|
|
422
|
+/**文件上传中处理 */
|
|
423
|
+const handleFileUploadProgress = () => {
|
|
424
|
+ upload.isUploading = true;
|
|
425
|
+};
|
|
426
|
+/** 文件上传成功处理 */
|
|
427
|
+const handleFileSuccess = (response: any, file: UploadFile) => {
|
|
428
|
+ upload.open = false;
|
|
429
|
+ upload.isUploading = false;
|
|
430
|
+ uploadRef.value?.handleRemove(file);
|
|
431
|
+ ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
|
|
432
|
+ dangerouslyUseHTMLString: true
|
|
433
|
+ });
|
|
434
|
+ getList();
|
|
435
|
+};
|
|
436
|
+
|
|
437
|
+/** 提交上传文件 */
|
|
438
|
+function submitFileForm() {
|
|
439
|
+ uploadRef.value?.submit();
|
|
440
|
+}
|
|
441
|
+
|
|
442
|
+/** 初始化部门数据 */
|
|
443
|
+const initTreeData = async () => {
|
|
444
|
+ // 判断部门的数据是否存在,存在不获取,不存在则获取
|
|
445
|
+ if (deptOptions.value === undefined) {
|
|
446
|
+ const { data } = await treeselect();
|
|
447
|
+ deptOptions.value = data;
|
|
448
|
+ }
|
|
449
|
+};
|
|
450
|
+
|
|
451
|
+/** 重置操作表单 */
|
|
452
|
+const reset = () => {
|
|
453
|
+ form.value = { ...initFormData };
|
|
454
|
+ userFormRef.value?.resetFields();
|
|
455
|
+};
|
|
456
|
+/** 取消按钮 */
|
|
457
|
+const cancel = () => {
|
|
458
|
+ dialog.visible = false;
|
|
459
|
+ reset();
|
|
460
|
+};
|
|
461
|
+
|
|
462
|
+/** 增加/修改按钮操作 */
|
|
463
|
+const userDetailFormRef = ref();
|
|
464
|
+const handleOpenDetail = async (cmd: string, row?: UserVO) => {
|
|
465
|
+ const userId = row?.userId || ids.value[0];
|
|
466
|
+ const realNames = row?.realName || names.value;
|
|
467
|
+ userDetailFormRef?.value.open(cmd, userId);
|
|
468
|
+};
|
|
469
|
+/** 新增按钮操作 */
|
|
470
|
+// const handleAdd = async () => {
|
|
471
|
+// reset();
|
|
472
|
+// const { data } = await api.getUser();
|
|
473
|
+// dialog.visible = true;
|
|
474
|
+// dialog.title = '新增用户';
|
|
475
|
+// await initTreeData();
|
|
476
|
+// postOptions.value = data.posts;
|
|
477
|
+// roleOptions.value = data.roles;
|
|
478
|
+// form.value.password = initPassword.value.toString();
|
|
479
|
+// };
|
|
480
|
+
|
|
481
|
+/** 修改按钮操作 */
|
|
482
|
+// const handleUpdate = async (row?: UserForm) => {
|
|
483
|
+// reset();
|
|
484
|
+// const userId = row?.userId || ids.value[0];
|
|
485
|
+// const { data } = await api.getUser(userId);
|
|
486
|
+// dialog.visible = true;
|
|
487
|
+// dialog.title = '修改用户';
|
|
488
|
+// await initTreeData();
|
|
489
|
+// Object.assign(form.value, data.user);
|
|
490
|
+// postOptions.value = data.posts;
|
|
491
|
+// roleOptions.value = data.roles;
|
|
492
|
+// form.value.postIds = data.postIds;
|
|
493
|
+// form.value.roleIds = data.roleIds;
|
|
494
|
+// form.value.password = '';
|
|
495
|
+// };
|
|
496
|
+
|
|
497
|
+/** 提交按钮 */
|
|
498
|
+const submitForm = () => {
|
|
499
|
+ userFormRef.value?.validate(async (valid: boolean) => {
|
|
500
|
+ if (valid) {
|
|
501
|
+ form.value.userId ? await api.updateUser(form.value) : await api.addUser(form.value);
|
|
502
|
+ proxy?.$modal.msgSuccess('操作成功');
|
|
503
|
+ dialog.visible = false;
|
|
504
|
+ await getList();
|
|
505
|
+ }
|
|
506
|
+ });
|
|
507
|
+};
|
|
508
|
+
|
|
509
|
+/**
|
|
510
|
+ * 关闭用户弹窗
|
|
511
|
+ */
|
|
512
|
+const closeDialog = () => {
|
|
513
|
+ dialog.visible = false;
|
|
514
|
+ resetForm();
|
|
515
|
+};
|
|
516
|
+
|
|
517
|
+/**
|
|
518
|
+ * 重置表单
|
|
519
|
+ */
|
|
520
|
+const resetForm = () => {
|
|
521
|
+ userFormRef.value?.resetFields();
|
|
522
|
+ userFormRef.value?.clearValidate();
|
|
523
|
+
|
|
524
|
+ form.value.id = undefined;
|
|
525
|
+ form.value.status = '1';
|
|
526
|
+};
|
|
527
|
+onMounted(() => {
|
|
528
|
+ getTreeSelect(); // 初始化部门数据
|
|
529
|
+ getList(); // 初始化列表数据
|
|
530
|
+ proxy?.getConfigKey('sys.user.initPassword').then((response) => {
|
|
531
|
+ initPassword.value = response.data;
|
|
532
|
+ });
|
|
533
|
+});
|
|
534
|
+
|
|
535
|
+async function handleDeptChange(value: number | string) {
|
|
536
|
+ const response = await optionselect(value);
|
|
537
|
+ postOptions.value = response.data;
|
|
538
|
+ form.value.postIds = [];
|
|
539
|
+}
|
|
540
|
+</script>
|
|
541
|
+
|
|
542
|
+<style lang="scss" scoped>
|
|
543
|
+.el-tree > :nth-child(n + 1) {
|
|
544
|
+ display: inline-block;
|
|
545
|
+ min-width: 100%;
|
|
546
|
+}
|
|
547
|
+</style>
|