add.vue
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
<template>
<div class="permission-add">
<zp-page-edit :back="true" @back="$router.back()">
<div slot="header">
{{ header }}
</div>
<el-form
:model="info"
:rules="rules"
ref="form"
label-width="100px"
class="form"
>
<el-form-item label="用户名:" prop="username">
<el-input type="text" v-model="info.username"></el-input>
</el-form-item>
<el-form-item label="密码:" prop="pwd">
<el-input type="password" v-model="info.pwd"></el-input>
</el-form-item>
<el-form-item label="权限:" prop="roles">
<el-select
v-model="info.roles"
multiple
placeholder="请选择"
class="block"
>
<el-option
v-for="item in roles"
:key="item.value"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button
type="primary"
@click="handleSubmit('form')"
:loading="loading"
>立即创建</el-button
>
</el-form-item>
</el-form>
</zp-page-edit>
</div>
</template>
<script>
export default {
name: "permissionAdd",
components: {},
data() {
return {
header: "添加管理员",
info: {
username: "",
pwd: "",
avatar: "",
roles: ["default"],
},
roles: [
{ label: "超级管理员", value: "admin" },
{ label: "普通管理员", value: "default" },
],
loading: false,
rules: {
username: [
{ required: true, message: "请填写用户名", trigger: "blur" },
],
pwd: [{ required: true, message: "请填写密码", trigger: "blur" }],
roles: [
{
required: true,
message: "请选择权限",
trigger: "change",
type: "array",
},
],
},
};
},
methods: {
handleSubmit(formName) {
this.loading = true;
this.$refs[formName].validate(async (valid) => {
if (valid) {
try {
await this.$store.dispatch("addUser", this.info);
this.loading = false;
this.$router.push("/permission/list");
this.$message.success("新增成功");
} catch (e) {
this.$message.error("新增失败");
this.loading = false;
}
} else {
console.log("error submit!!");
this.loading = false;
return false;
}
});
},
},
};
</script>
<style lang="less" scoped>
</style>