|
@@ -0,0 +1,145 @@
|
|
1
|
+<template>
|
|
2
|
+ <div class="root">
|
|
3
|
+ <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="add-ruleForm">
|
|
4
|
+ <el-form-item label="角色名称" prop="roleName">
|
|
5
|
+ <el-input :disabled="true" v-model="ruleForm.roleName"/>
|
|
6
|
+ </el-form-item>
|
|
7
|
+ <el-form-item label="角色描述" prop="description">
|
|
8
|
+ <el-input :disabled="true" v-model="ruleForm.description"/>
|
|
9
|
+ </el-form-item>
|
|
10
|
+ <el-form-item label="资源权限" prop="menuArray">
|
|
11
|
+ <el-tree
|
|
12
|
+ ref="tree"
|
|
13
|
+ :data="menuList"
|
|
14
|
+ show-checkbox
|
|
15
|
+ node-key="id"
|
|
16
|
+ :default-expanded-keys="ruleForm.menuArray"
|
|
17
|
+ :default-checked-keys="ruleForm.menuArray"
|
|
18
|
+ :props="defaultProps">
|
|
19
|
+ </el-tree>
|
|
20
|
+ </el-form-item>
|
|
21
|
+ <el-form-item>
|
|
22
|
+ <el-button type="primary" @click="goEditRole">去修改</el-button>
|
|
23
|
+ </el-form-item>
|
|
24
|
+ </el-form>
|
|
25
|
+ </div>
|
|
26
|
+</template>
|
|
27
|
+
|
|
28
|
+<script>
|
|
29
|
+import { mapState, mapActions, mapMutations } from 'vuex'
|
|
30
|
+import waves from '@/directive/waves' // Waves directive
|
|
31
|
+import { parseTime } from '@/utils'
|
|
32
|
+
|
|
33
|
+export default {
|
|
34
|
+ computed: {
|
|
35
|
+ ...mapState('role', {
|
|
36
|
+ menuList: s => s.menuList
|
|
37
|
+ })
|
|
38
|
+ },
|
|
39
|
+ data() {
|
|
40
|
+ return {
|
|
41
|
+ ruleForm: {
|
|
42
|
+ id: '',
|
|
43
|
+ roleName: '',
|
|
44
|
+ description: '',
|
|
45
|
+ menuArray: []
|
|
46
|
+ },
|
|
47
|
+ rules: {
|
|
48
|
+ roleName: [
|
|
49
|
+ { required: true, message: '请输入角色名称', trigger: 'blur' }
|
|
50
|
+ ],
|
|
51
|
+ menuArray: [
|
|
52
|
+ { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
|
|
53
|
+ ]
|
|
54
|
+ },
|
|
55
|
+ defaultProps: {
|
|
56
|
+ children: 'children',
|
|
57
|
+ label: 'menuName',
|
|
58
|
+ disabled: () => true
|
|
59
|
+ }
|
|
60
|
+ }
|
|
61
|
+ },
|
|
62
|
+ created(){
|
|
63
|
+ this.ruleForm.id = this.$route.params.id
|
|
64
|
+ this.getDataById()
|
|
65
|
+ this.getMenuList()
|
|
66
|
+ },
|
|
67
|
+ methods: {
|
|
68
|
+ ...mapMutations('role', {
|
|
69
|
+ }),
|
|
70
|
+ ...mapActions('role', [
|
|
71
|
+ 'FetchMenuList',
|
|
72
|
+ 'UpdateRoleInfo',
|
|
73
|
+ 'GetRoleInfo'
|
|
74
|
+ ]),
|
|
75
|
+ submitForm(formName) { // 提交
|
|
76
|
+ // 获取选中的树形节点 key
|
|
77
|
+ this.ruleForm.menuArray = this.$refs.tree.getCheckedKeys()
|
|
78
|
+ console.log(this.ruleForm.menuArray)
|
|
79
|
+ this.$refs[formName].validate((valid) => {
|
|
80
|
+ if (valid) {
|
|
81
|
+ this.updateRole()
|
|
82
|
+ } else {
|
|
83
|
+ console.log('error submit!!')
|
|
84
|
+ return false
|
|
85
|
+ }
|
|
86
|
+ })
|
|
87
|
+ },
|
|
88
|
+ getMenuList() {
|
|
89
|
+ this.FetchMenuList().then(() => {
|
|
90
|
+ }).catch(() => {
|
|
91
|
+ console.log('get list error')
|
|
92
|
+ })
|
|
93
|
+ },
|
|
94
|
+ resetForm(formName) { // 重置
|
|
95
|
+ this.$refs[formName].resetFields()
|
|
96
|
+ },
|
|
97
|
+ updateRole() {
|
|
98
|
+ // 加载框
|
|
99
|
+ const loading = this.$loading({
|
|
100
|
+ lock: true,
|
|
101
|
+ text: 'Loading',
|
|
102
|
+ spinner: 'el-icon-loading',
|
|
103
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
104
|
+ })
|
|
105
|
+ this.UpdateRoleInfo(this.ruleForm).then((res) => {
|
|
106
|
+ if (res.code === '0') {
|
|
107
|
+ this.$message({
|
|
108
|
+ message: res.message,
|
|
109
|
+ type: 'success'
|
|
110
|
+ })
|
|
111
|
+ this.$router.push({ name: 'role-index' })
|
|
112
|
+ loading.close()
|
|
113
|
+ return
|
|
114
|
+ }
|
|
115
|
+ this.$message.error(res.message)
|
|
116
|
+ loading.close()
|
|
117
|
+ }).catch(() => {
|
|
118
|
+ loading.close()
|
|
119
|
+ console.log('error updateRole')
|
|
120
|
+ })
|
|
121
|
+ },
|
|
122
|
+ goEditRole(){
|
|
123
|
+ this.$router.push({ name: 'role-edit', params: { id: this.ruleForm.id }})
|
|
124
|
+ },
|
|
125
|
+ getDataById() {
|
|
126
|
+ this.GetRoleInfo(this.ruleForm.id).then((res) => {
|
|
127
|
+ this.ruleForm.roleName = res.data.roleName
|
|
128
|
+ this.ruleForm.description = res.data.description
|
|
129
|
+ this.ruleForm.menuArray = res.data.menuArray
|
|
130
|
+ }).catch(() => {
|
|
131
|
+ console.log('error init role')
|
|
132
|
+ })
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+}
|
|
136
|
+</script>
|
|
137
|
+
|
|
138
|
+<style scoped>
|
|
139
|
+.add-ruleForm{
|
|
140
|
+ width: 800px;
|
|
141
|
+ margin-left: auto;
|
|
142
|
+ margin-right: auto;
|
|
143
|
+ margin-top: 50px;
|
|
144
|
+}
|
|
145
|
+</style>
|