From 797cc9c1a5c90f413d46c5cb88e1ee5e3a84b071 Mon Sep 17 00:00:00 2001
From: “dzb” <2632970487@qq.com>
Date: 星期二, 04 十月 2022 11:51:05 +0800
Subject: [PATCH] 修改用户只能分配单一角色
---
src/views/systemSetting/baseSetting/role/updateUser/index.vue | 230 ++++++++++++++++++++++++++++-----------------------------
1 files changed, 114 insertions(+), 116 deletions(-)
diff --git a/src/views/systemSetting/baseSetting/role/updateUser/index.vue b/src/views/systemSetting/baseSetting/role/updateUser/index.vue
index be1e238..5905a11 100644
--- a/src/views/systemSetting/baseSetting/role/updateUser/index.vue
+++ b/src/views/systemSetting/baseSetting/role/updateUser/index.vue
@@ -2,36 +2,20 @@
<div class="updateUser">
<main>
<div class="mainContent">
- <el-form ref="user" label-width="140px" autoComplete="on" :model="role" :rules="createRoleRules"
- label-position="right">
- <!-- 瑙掕壊鍚嶇О -->
- <el-form-item class="optionItem" label="瑙掕壊鍚嶇О:" prop="name">
- <el-input v-model="role.name" placeholder="璇峰~鍐欒鑹插悕绉�" :disabled="!updateFlag"></el-input>
- </el-form-item>
- <!-- 瑙掕壊绫诲瀷 -->
- <el-form-item class="optionItems" label="瑙掕壊绫诲瀷:" prop="sort">
- <!-- <el-input v-model="role.sort" placeholder="璇烽�夋嫨瑙掕壊绫诲瀷" :disabled="!updateFlag"></el-input> -->
- <el-select v-model="role.sort" placeholder="璇烽�夋嫨瑙掕壊绫诲瀷">
- <!-- v-for="item in roleList" :key="item.id" :label="item.departName"
- :value="item.id" -->
- <el-option :value="treeId" :label="treeLabel">
- <el-tree :data="roleList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
- </el-option>
- </el-select>
- </el-form-item>
- <!-- 瑙掕壊鎻忚堪 -->
- <el-form-item class="optionItem" label="瑙掕壊鎻忚堪:" prop="description">
- <el-input type="textarea" v-model="role.description" placeholder="璇疯緭鍏ユ弿杩板唴瀹�200瀛椾互鍐�"
- :disabled="!updateFlag"></el-input>
- </el-form-item>
- <el-form-item v-if="updateFlag">
- <div class="optionBtn">
- <el-button type="primary" class="btn submit" @click.native.prevent="handleUser">纭
- </el-button>
- </div>
- </el-form-item>
- </el-form>
-
+ <div class="my-tree">
+ <div class="my-tree__wrap">
+ <!-- @node-click="handleNodeClick" -->
+ <el-tree ref="tree" :data="roleList" :props="defaultProps" show-checkbox
+ @check="handleCheck" :default-checked-keys="checkedIds" default-expand-all node-key="id">
+ </el-tree>
+ </div>
+ <div class="my-tree__bottom"></div>
+ <div class="my-tree__right"></div>
+ </div>
+ <div class="selection">
+ <el-button class="cancel" @click="resetRole">鍙栨秷</el-button>
+ <el-button class="save" @click="saveRole">淇濆瓨</el-button>
+ </div>
</div>
</main>
</div>
@@ -39,65 +23,26 @@
<script>
export default {
data() {
- const validateNickname = (rule, value, callback) => {
- if (!value) {
- callback(new Error("璇峰~鍐欒鑹插悕绉�"));
- } else {
- callback();
- }
- };
- const validatePass = (rule, value, callback) => {
- if (!value) {
- callback();
- } else {
- // const rep = /^\w+$/;
- // if (!rep.test(value)) {
- // callback(new Error("瀵嗙爜鍙兘鏄互鏁板瓧銆�26涓嫳鏂囧瓧姣嶆垨鑰呬笅鍒掔嚎缁勬垚鐨勫瓧绗︿覆"));
- // }
- callback();
- }
- };
- const validateTruename = (rule, value, callback) => {
- if (value) {
- callback();
- } else {
- // const rep = /^[\u4E00-\u9FA5]{2,4}$/;
- // if (!rep.test(value)) {
- // callback("璇疯緭鍏ユ纭殑鐢ㄦ埛濮撳悕");
- // }
- callback();
- }
- };
return {
role: {
name: '',
sort: '',
description: '',
},
- createRoleRules: {
- name: [
- { required: true, trigger: "blur", validator: validateNickname },
- ],
- sort: [
- { required: false, trigger: "blur", validator: validatePass },
- ],
- description: [
- { required: false, trigger: "blur", validator: validateTruename },
- ],
- },
roleList: [],
defaultProps: {
children: 'children',
label: 'title'
},
- treeLabel:'',
- treeId:23
+ treeLabel: '',
+ treeId: 23,
+ checkedIds: [],
+ resCheckedIds: [],
}
},
created() {
const that = this;
- this.userInfo.status ? this.userInfo.status = 1 : this.userInfo.status = 0;
- this.role = JSON.parse(JSON.stringify(that.userInfo));
+ this.getRoleMenus(this.userInfo.id);
this.getMenuList();
},
methods: {
@@ -129,16 +74,64 @@
})
.then(res => {
this.roleList = res.data;
- console.log(res);
})
},
// 鐐瑰嚮鏍戣妭鐐�
- handleNodeClick({title,id}) {
+ handleNodeClick({ title, id }) {
// console.log(obj);
this.role.sort = title;
this.treeLabel = title;
this.treeId = id;
+ },
+ // 鏍戝舰鎺т欢澶嶉�夋鐐瑰嚮浜嬩欢
+ handleCheck(data, checked) {
+ console.log(checked.checkedKeys);
+ this.checkedIds = checked.checkedKeys;
+ console.log(this.checkedIds);
+ },
+ // 淇濆瓨role
+ saveRole() {
+ this.resCheckedIds = [];
+ const {userInfo} = this;
+ this.resCheckedIds = this.checkedIds;
+ this.$axios({
+ method:'post',
+ url:'sccg/role/allocMenu?roleId='+userInfo.id + '&menuIds=' + this.checkedIds,
+ })
+ .then(res=>{
+ if(res.code === 200){
+ this.$message({
+ type:'success',
+ message:'淇敼瑙掕壊鏉冮檺鎴愬姛',
+ })
+ this.getRoleMenus(userInfo.id);
+ }else{
+ this.$message({
+ type:'warning',
+ message:res.message
+ })
+ }
+ })
+ // this.$emit('changeDialog',{dialogUpdate:false});
+ },
+ // 娑堥櫎role
+ resetRole() {
+ this.resCheckedIds = [];
+ this.$emit('changeDialog',{dialogUpdate:false});
+ },
+ // 鑾峰彇瑙掕壊鑿滃崟
+ getRoleMenus(roleId){
+ this.$axios({
+ method:'get',
+ url:`sccg/role/listMenu/${roleId}`
+ })
+ .then(res=>{
+ this.checkedIds = [];
+ res.data.forEach(item=>{
+ this.checkedIds.push(item.id);
+ })
+ })
}
},
props: ['userInfo', 'updateFlag', 'getUserList', 'changeDialog']
@@ -148,49 +141,39 @@
.updateUser {
border-radius: 1px;
background-color: #09152f;
-
main {
- // border: 1px solid #fff;
text-align: left;
- padding: 0 55px;
+ padding: 50px 55px;
background-color: #09152f;
- padding-bottom: 50px;
-
.mainContent {
- display: flex;
- justify-content: center;
- padding-top: 50px;
-
- .el-form-item__content {
- width: 400px;
-
- .el-select {
+ .my-tree {
+ height: 200px;
+ overflow: hidden;
+ background-color: #17324c;
+ position: relative;
+ border-radius: 4px;
+ .my-tree__wrap{
+ overflow: scroll;
+ height: 200px;
+ }
+ .my-tree__bottom{
+ position: absolute;
+ left: 0px;
+ bottom: 0px;
+ background-color: #17324c;
width: 100%;
+ height: 20px;
+ border-bottom-left-radius: 4px;
+ }
+ .my-tree__right{
+ position: absolute;
+ right: 0px;
+ top: 0px;
+ background-color: #17324c;
+ width: 20px;
+ height: 100%;
}
}
-
- .optionHandleSp {
- display: flex;
-
- .areaNumber,
- .moreNumber {
- flex: 1;
- }
-
- .telNumber {
- flex: 2;
- }
- }
-
- .optionBtn {
- display: flex;
- margin-top: 20px;
-
- .btn {
- padding: 12px 50px;
- }
- }
-
}
}
@@ -199,14 +182,29 @@
border: 1px solid #17324c;
}
- ::v-deep .el-form-item__label {
- color: #4b9bb7;
- }
-
::v-deep .el-input__inner {
background-color: #09152f;
border: 1px solid #17324c;
}
}
+.selection {
+ margin-top: 10px;
+ display: flex;
+ justify-content: space-between;
+ .el-button {
+ padding: 10px 20px;
+ border-radius: 4px;
+ }
+
+ .save {
+ background-color: #409eff;
+ color: #fff;
+ }
+
+ .cancel {
+ background-color: #09152f;
+ color: #4b9bb7;
+ }
+}
</style>
\ No newline at end of file
--
Gitblit v1.8.0