Browse Source

编辑用户角色及添加角色问题修改

GR 3 years ago
parent
commit
84d9248e12

+ 2 - 1
src/utils/service/role.js

@@ -27,10 +27,11 @@ export function UpdateRoleAuthority(roleId, authorityArr) {
   return axios.post('role/updateRoleAuthority', qs.stringify(data))
 }
 
-export function AddRole(roleName) {
+export function AddRole(roleName, authorityArr) {
   let data = {
     roleName,
     roleDes: roleName,
+    authorityArr: JSON.stringify(authorityArr),
     token: getCookie("m_token")
   }
   return axios.post('role/addRole', qs.stringify(data))

+ 6 - 6
src/views/userManage/AuthManageEdit.vue

@@ -14,7 +14,7 @@
           </el-col>
         </el-row>
       </el-form>
-      <div class="tree" v-if="!isNew">
+      <div class="tree">
         <div class="main-title">角色权限</div>
         <el-row>
           <el-col :span="4" v-for="(item, index) in treeData" :key="item[0].authorityId">
@@ -93,11 +93,11 @@
         })
       },
       save() {
+        let checkedTemp = []
+        for(let i=0; i<this.treeData.length; i++) {
+          checkedTemp.push(...this.$refs[`tree-${i}`][0].getCheckedKeys())
+        }
         if(!this.isNew) {
-          let checkedTemp = []
-          for(let i=0; i<this.treeData.length; i++) {
-            checkedTemp.push(...this.$refs[`tree-${i}`][0].getCheckedKeys())
-          }
           UpdateRoleAuthority(this.$route.params.id, checkedTemp).then(res => {
             if(res.code == 200) {
               this.$message({type: 'success', message: '保存成功'})
@@ -111,7 +111,7 @@
         }else {
           this.$refs.ruleForm.validate((valid) => {
             if (valid) {
-              AddRole(this.form.roleName).then(res => {
+              AddRole(this.form.roleName, checkedTemp).then(res => {
                 if(res.code == 200) {
                   this.$message({type: 'success', message: '角色添加成功'})
                   this.$router.push({

+ 8 - 7
src/views/userManage/UserListDetail.vue

@@ -38,7 +38,7 @@
           </el-col>
           <el-col :span="6">
             <el-form-item label="用户角色">
-              <el-select v-model="form.roleId" :disabled="isDetail" multiple collapse-tags placeholder="无">
+              <el-select v-model="form.role" multiple collapse-tags placeholder="无">
                 <el-option v-for="item in roleArr" :key="item.roleId" :label="item.roleName" :value="item.roleId"/>
               </el-select>
             </el-form-item>
@@ -68,7 +68,7 @@
     },
     methods: {
       save() {
-        UpdateUserRole(this.$route.params.id, this.form.roleId).then(res => {
+        UpdateUserRole(this.$route.params.id, this.form.role).then(res => {
           if (res.code == 200) {
             this.$message({type: 'success', message: '保存成功'});
             this.$router.push({
@@ -99,11 +99,12 @@
       getUserInfo() {
         GetUserInfoById(this.$route.params.id).then(res => {
           if(res.code == 200) {
-            let formTemp = res.data.Rows[0]
-            if(res.data.Rows[0].roleId) {
-              formTemp.roleId = [res.data.Rows[0].roleId]
-            }else {
-              formTemp.roleId = []
+            let formTemp = JSON.parse(JSON.stringify(res.data))
+            formTemp.role = []
+            if(res.data.role[0]) {
+              res.data.role.forEach(i => {
+                formTemp.role.push(i.roleId)
+              })
             }
             this.form = formTemp
           }