zhanghua
2022-10-20 bb036407bcc0f26a9a0f246aca100d87db2f6e76
src/views/systemSetting/baseSetting/role/updateUser/index.vue
@@ -1,35 +1,20 @@
<template>
    <div class="updateUser">
        <header>
            <div class="headerTitle">{{updateFlag ? '修改角色信息' :'查看角色信息'}}</div>
        </header>
        <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="status">
                        <el-select v-model="role.status" placeholder="请选择角色类型" :disabled="!updateFlag">
                            <el-option v-for="item in typeList" :key="item.name" :label="item.name" :value="item.value"
                                :disabled="item.disabled">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- 角色描述 -->
                    <el-form-item class="optionItem" label="角色描述:" prop="description">
                        <el-input 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">
                        <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>
@@ -37,85 +22,92 @@
<script>
export default {
    data() {
        const validateNickname = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写用户名称"));
            }
        };
        const validatePass = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写登录密码"));
            } else {
                const rep = /^\w+$/;
                if (!rep.test(value)) {
                    callback(new Error("密码只能是以数字、26个英文字母或者下划线组成的字符串"));
                }
            }
        };
        const validateTruename = (rule, value, callback) => {
            if (!value) {
                callback(new Error("请填写用户姓名"));
            } else {
                const rep = /^[\u4E00-\u9FA5]{2,4}$/;
                if (!rep.test(value)) {
                    callback("请输入正确的用户姓名");
                }
            }
        };
        return {
            role: {
                id:'',
                name: '',
                status: '',
                sort: '',
                description: '',
            },
            createRoleRules: {
                name: [
                    { required: true, trigger: "blur", validator: validateNickname },
                ],
                status: [
                    { required: false, trigger: "blur", validator: validatePass },
                ],
                description: [
                    { required: false, trigger: "blur", validator: validateTruename },
                ],
            roleList: [],
            defaultProps: {
                children: 'children',
                label: 'title'
            },
            roleList: [
                { name: '角色1', value: 1 }, { name: '角色2', value: 2 }
            ],
            typeList: []
            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.$axios.get('')
        // 获取用户类型列表
        // this.$axios.get('sccg/admin/list',{userType:0}).then(res=>{
        //     console.log(res);
        // })
        // 获取全部部门列表
        this.$axios.get('sccg/depart/page').then(res => {
            that.typeList = res.data.records;
        })
        this.getRoleMenus(this.userInfo.id);
        this.getMenuList();
    },
    methods: {
        handleUser() {
            const { role } = this;
            this.$axios.post('/sccg/role/update/'+role.id, {
                id:role.id,
                status: role.status,
                description:role.description,
                name:role.name
            }).then(res => {
                this.$emit('changeDialog',{dialogUpdate:false});
                this.getUserList();
        // 获取系统菜单
        getMenuList() {
            this.$axios({
                method: 'get',
                url: 'sccg/menu/treeList',
            })
                .then(res => {
                    this.roleList = res.data;
                })
        },
        // 树形控件复选框点击事件
        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);
                        this.$emit('changeDialog', { flag: false });
                        this.getUserList();
                    } 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']
    props: ['userInfo', 'updateFlag', 'getUserList', 'changeDialog']
}
</script>
<style lang="scss" scoped>
@@ -123,77 +115,75 @@
    border-radius: 1px;
    background-color: #09152f;
    header {
        display: flex;
        justify-content: center;
        height: 60px;
        line-height: 60px;
        padding: 0 20px;
        border: 1px solid #fff;
        .headerTitle {
            color: #4b9bb7;
            font-weight: 600;
        }
        .headerTip span {
            color: #ff3b6c;
        }
        .headerTip label {
            color: #4b9bb7;
        }
    }
    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;
            margin-top: 50px    ;
            .el-form-item__content {
                width: 400px;
            .my-tree {
                height: 200px;
                overflow: hidden;
                background-color: #17324c;
                position: relative;
                border-radius: 4px;
                .el-select {
                .my-tree__wrap {
                    overflow-y: scroll;
                    height: 200px;
                }
                .my-tree__bottom {
                    position: absolute;
                    left: 0px;
                    bottom: 0px;
                    background-color: #09152f;
                    width: 100%;
                    height: 20px;
                    border-bottom-left-radius: 4px;
                }
                .my-tree__right {
                    position: absolute;
                    right: 0px;
                    top: 0px;
                    background-color: #09152f;
                    width: 20px;
                    height: 100%;
                }
            }
            .optionHandleSp {
                display: flex;
                .areaNumber,
                .moreNumber {
                    flex: 1;
                }
                .telNumber {
                    flex: 2;
                }
            }
            .optionBtn {
                display: flex;
                margin-top: 20px;
                .btn {
                    padding: 12px 50px;
                }
            }
        }
    }
    &::v-deep .el-textarea__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
    ::v-deep .el-input__inner {
        background-color: #09152f;
        border: 1px solid #17324c;
    }
}
.updateUser::v-deep .el-form-item__label {
    color: #4b9bb7;
}
.selection {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
.updateUser::v-deep .el-input__inner {
    background-color: #09152f;
    border: 1px solid #17324c;
    .el-button {
        padding: 10px 20px;
        border-radius: 4px;
    }
    .save {
        background-color: #409eff;
        color: #fff;
    }
    .cancel {
        background-color: #09152f;
        color: #4b9bb7;
    }
}
</style>