赖素文
authored
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<template>
<div class="sys-container">
<form ref="form" label-width="80px">
<el-row :gutter="10">
<el-col :span="3.5">
<div class="sys-form-item bg-purple">
<div class="sys-form-item-text">用户编码:</div>
<div class="sys-form-item-input">
<el-input v-model="paramsQuery.queryConfig.UserCode" placeholder="请输入用户编码" />
</div>
</div>
</el-col>
<el-col :span="3.5">
<div class="sys-form-item bg-purple">
<div class="sys-form-item-text">用户名称:</div>
<div class="sys-form-item-input">
<el-input v-model="paramsQuery.queryConfig.UserName" placeholder="请输入用户名称" />
</div>
</div>
</el-col>
<el-col :span="4">
<div class="sys-form-item bg-purple">
<el-button icon="el-icon-search" @click="btnAction(1)" type="primary">查询</el-button>
|
赖素文
authored
|
25
|
<el-button icon="el-icon-refresh-right" @click="btnAction(0)">重置</el-button>
|
赖素文
authored
|
26
27
28
|
</div>
</el-col>
</el-row>
|
赖素文
authored
|
29
30
31
32
33
|
<div class="sys-pb-5">
<el-button type="primary" size="small" icon="el-icon-plus" @click="userEditOrAddOpen(null, 'add')">
新增
</el-button>
</div>
|
赖素文
authored
|
34
|
</form>
|
赖素文
authored
|
35
|
|
赖素文
authored
|
36
37
|
<!-- table -->
<div class="sys-table-border">
|
赖素文
authored
|
38
39
40
|
<el-table :data="tableData" ref="multipleTable" highlight-current-row style="width: 100%" height="520">
<el-table-column label="序号" width="60" type="index"
:index="(index) => (paramsQuery.PageNumber - 1) * paramsQuery.PerPageCount + index + 1" />
|
赖素文
authored
|
41
42
43
44
45
46
47
48
49
50
|
<el-table-column prop="id" label="id" v-if="false"></el-table-column>
<el-table-column prop="userCode" label="用户编码"> </el-table-column>
<el-table-column prop="userName" label="用户名称"> </el-table-column>
<el-table-column prop="department" label="部门"> </el-table-column>
<el-table-column prop="address" label="地址"> </el-table-column>
<el-table-column prop="phone" label="电话"> </el-table-column>
<el-table-column prop="remark" label="备注"> </el-table-column>
<el-table-column prop="created" label="创建时间" width="180"> </el-table-column>
<el-table-column prop="createdBy" label="创建人"> </el-table-column>
|
赖素文
authored
|
51
52
53
54
55
56
|
<el-table-column label="操作" width="120">
<template slot-scope="scope">
<el-button type="text" @click="userEditOrAddOpen(scope.row, 'edit')">编辑</el-button>
<el-button style="color: red;" type="text" @click="userDelete(scope.row, 'edit')">删除</el-button>
</template>
</el-table-column>
|
赖素文
authored
|
57
58
59
|
</el-table>
<div class="sys-pagination-container">
|
赖素文
authored
|
60
61
62
|
<el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange"
:current-page="paramsQuery.PageNumber" :page-size="paramsQuery.PerPageCount" :page-sizes="[20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper" :total="paramsQuery.PageTotal" />
|
赖素文
authored
|
63
64
|
</div>
</div>
|
赖素文
authored
|
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
<!-- dialog -->
<el-dialog :title="userDialog.title" :close-on-click-modal="false" :visible.sync="userDialog.visible" width="60%">
<el-form :model="userDialog.form" label-width="80px">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="编码">
<el-input v-model="userDialog.form.userCode" ref="userCode" autocomplete="off"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="名称">
<el-input v-model="userDialog.form.userName" ref="userName" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<!-- 第二行:密码 + 部门 -->
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="密码">
<el-input v-model="userDialog.form.password" type="password" ref="password" autocomplete="off"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="部门">
<el-input v-model="userDialog.form.department" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<!-- 第三行:电话 + 地址 -->
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="电话">
<el-input v-model="userDialog.form.phone" autocomplete="off"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="地址">
<el-input v-model="userDialog.form.address" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="权限">
<el-select v-model="roleSelectOpt.selectVal" multiple placeholder="请选择权限">
<el-option v-for="item in roleSelectOpt.data" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="禁用">
<el-switch v-model="userDialog.form.disable" active-color="#13ce66" inactive-color="#ff4949">
</el-switch>
</el-form-item>
</el-col>
</el-row>
<!-- 单列:备注 -->
<el-row>
<el-col :span="24">
<el-form-item label="备注">
<el-input v-model="userDialog.form.remark" type="textarea" :rows="2" autocomplete="off">
</el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="userAddOrEditSave">确 定</el-button>
<el-button @click="userDialog.visible = false">取 消</el-button>
</span>
</el-dialog>
|
赖素文
authored
|
144
145
146
|
</div>
</template>
<script>
|
赖素文
authored
|
147
|
import * as userApi from "@/api/systemPermission/user";
|
赖素文
authored
|
148
149
|
export default {
data() {
|
赖素文
authored
|
150
|
const defaultData = {
|
赖素文
authored
|
151
|
PageNumber: 1,
|
赖素文
authored
|
152
|
PerPageCount: 20,
|
赖素文
authored
|
153
154
155
156
157
158
|
queryConfig: {
UserCode: "",
UserName: "",
},
PageTotal: 0,
};
|
赖素文
authored
|
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
const userData = {
userCode: "",
userName: "",
password: "",
department: null,
phone: null,
remark: null,
address: "",
disable: false,
//权限数据
Roles: [],
Created: null,
CreatedBy: null,
Updated: null,
UpdatedBy: null,
Id: 0
};
|
赖素文
authored
|
178
179
|
return {
tableData: [],
|
赖素文
authored
|
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
paramsQuery: { ...defaultData },
defaultData: JSON.parse(JSON.stringify(defaultData)),
userDialog: {
visible: false,
flag: "add",
title: "新增",
form: { ...userData },
formDefaultData: JSON.parse(JSON.stringify(userData)),
},
//临时存储的数据
roleSelectOpt: {
data: [], // 处理后的数据(展示用)
originData: [], // 原始数据
selectVal: null,
}
|
赖素文
authored
|
196
197
198
|
};
},
methods: {
|
赖素文
authored
|
199
200
201
|
/**
* 查询或者搜索
*/
|
赖素文
authored
|
202
203
|
btnAction(flag) {
if (flag == 0) {
|
赖素文
authored
|
204
|
this.paramsQuery = JSON.parse(JSON.stringify(this.defaultData));
|
赖素文
authored
|
205
206
207
|
}
this.getData();
},
|
赖素文
authored
|
208
|
|
赖素文
authored
|
209
|
getData() {
|
赖素文
authored
|
210
211
|
userApi.getUserData(this.paramsQuery).then(response => {
this.paramsQuery.PageTotal = response.data.totalCount;
|
赖素文
authored
|
212
213
214
215
|
this.tableData = response.data.data;
});
},
|
赖素文
authored
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/**
* 获取用户权限数据
*/
getUserRoleList() {
userApi.getUserRole().then(res => {
if (res.code !== 'Success') return;
this.roleSelectOpt.data = this.getUserRoleDataHandle(res.data);
this.roleSelectOpt.originData = res.data;
})
},
/**
* 用户选项数据转换给组件格式数据
*/
getUserRoleDataHandle(data) {
var roleOptions = [];
data.forEach(element => {
roleOptions.push({
value: element.id,
label: element.roleName
})
});
return roleOptions
},
/**
* 新增或者编辑弹出框
*/
async userEditOrAddOpen(row, flag) {
debugger
if (this.roleSelectOpt.data.length == 0) {
this.$message.error("权限数据加载中...请稍后在操作,反复出现请联系管理员!");
return;
}
this.roleSelectOpt.selectVal = [];
this.userDialog.flag = flag;
if (flag == "add") {
this.userDialog.form = JSON.parse(JSON.stringify(this.userDialog.formDefaultData));
this.userDialog.title = "新增"
} else {
this.userDialog.title = `编辑,用户名【${row.userName}】`
var result = await userApi.getUserWithRoles({ UserCode: row.userCode })
const keys = result.data.roles.map(x => x.id);
this.roleSelectOpt.selectVal = keys;
this.userDialog.form = row;
}
this.userDialog.visible = true;
|
赖素文
authored
|
262
|
},
|
赖素文
authored
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
/**
* 用户新增或者编辑 保存操作
*/
userAddOrEditSave() {
debugger
if (this.userDialog.form.userCode == "" || this.userDialog.form.userCode == null) {
this.$message.error("用户编码不能为!");
this.$refs.userCode.focus();
return;
}
if (this.userDialog.form.userName == "" || this.userDialog.form.userName == null) {
this.$message.error("用户名称不能为!");
this.$refs.userName.focus();
return;
}
if (this.userDialog.form.password == "" || this.userDialog.form.password == null) {
this.$message.error("用户密码不能为!");
this.$refs.password.focus();
return;
}
var roleData = this.getSelectRoleVal();
if (roleData.length == 0) return;
this.userDialog.form.Roles = roleData;
if (this.userDialog.flag == "edit") {
userApi.editUser(this.userDialog.form).then(res => {
if (res.code !== 'Success') return;
this.userDialog.visible = false;
this.$message.success("业务数据操作成功!");
this.getData();
});
return
}
userApi.addUser(this.userDialog.form).then(res => {
if (res.code !== 'Success') return;
this.userDialog.visible = false;
this.$message.success("业务数据操作成功!");
this.getData();
});
},
//用户删除
userDelete(row) {
var title = `此操作将永久删除该数据,用户名【${row.userName}】,是否继续?`;
this.$confirm(title, '提示', { type: 'warning', })
.then(() => {
userApi.deleteUser(row).then(res => {
if (res.code !== 'Success') return;
this.$message.success("业务数据操作成功!");
this.userDialog.visible = false;
this.getData();
});
}).catch()
},
setCurrent(row) {
this.$refs.multipleTable.setCurrentRow(row);
},
//获取选中的权限,处理好符合后台提交数据格式
getSelectRoleVal() {
if (this.roleSelectOpt.selectVal.length == 0) {
this.$message.error("请选择权限数据!");
return [];
}
var result = [];
this.roleSelectOpt.selectVal.forEach(x => {
var tempVal = this.roleSelectOpt.originData.find(y => y.id == x);
result.push(tempVal)
});
return result;
},
//下一页
|
赖素文
authored
|
337
338
|
handleCurrentChange(page) {
debugger
|
赖素文
authored
|
339
340
341
342
343
344
|
this.paramsQuery.PageNumber = page;
this.getData();
},
handleSizeChange(val) {
this.paramsQuery.PerPageCount = val;
this.paramsQuery.PageNumber = 1;
|
赖素文
authored
|
345
346
347
348
|
this.getData();
},
},
mounted() {
|
赖素文
authored
|
349
|
this.getUserRoleList();
|
赖素文
authored
|
350
351
352
353
354
355
356
357
358
|
this.getData();
},
};
</script>
<style scoped lang="scss">
.sys-container {
width: 100%;
}
|
赖素文
authored
|
359
360
|
.sys-pb-5 {
padding-bottom: 5px !important;
|
赖素文
authored
|
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
}
.sys-form-item {
display: flex;
border-radius: 4px;
min-height: 46px;
margin-bottom: 10px;
align-items: center;
}
.sys-table-border {
border: 1px solid #e5e9f2;
}
.sys-pagination-container {
text-align: center;
|
赖素文
authored
|
378
379
380
381
|
}
.current-row {
background-color: #ecf5ff;
|
赖素文
authored
|
382
383
|
}
</style>
|