123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <!--
- * @Author: your name
- * @Date: 2021-11-29 16:31:31
- * @LastEditTime: 2022-02-08 11:06:41
- * @LastEditors: Please set LastEditors
- * @Description: 新增/编辑角色
- * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\authorityRoleStatus.vue
- -->
- <template>
- <div class="authorityPower">
- <!--新增权限项-->
- <div class="addApp-form">
- <div class="addApp-form-title flex">
- <div class="title">
- 编辑角色
- <!-- <span class="isqy">
- <span>是否启用</span>
- <el-radio v-model="radio" :label="1">是</el-radio>
- <el-radio v-model="radio" :label="0">否</el-radio>
- </span> -->
- </div>
- <div class="btn">
- <!-- <el-button class="r24" @click="removeRole" type="danger">删除</el-button> -->
- <el-button @click="saveBtn('form')" type="primary">保存</el-button>
- </div>
- </div>
- <div class="addApp-form-content dialog-public-background">
- <el-form :inline="true" ref="form" :rules="rules" class="form" :model="form">
- <el-form-item prop="name" label="角色名称">
- <el-input placeholder="请输入角色名称" maxlength="32" v-model="form.name"></el-input>
- </el-form-item>
- <el-form-item label="描述">
- <el-input style="width: 640px" maxlength="200" placeholder="请输入描述" v-model="form.app"></el-input>
- </el-form-item>
- </el-form>
- </div>
- </div>
- <div class="power-content flex-wrap">
- <div class="r24 flex1 part">
- <Permissiontree v-loading="loading" element-loading-text="数据加载中" @getTreeData="getTreeData" :checkedKeys="checkedKeys" title="权限树" />
- </div>
- <div class="r24 flex1 part">
- <Rulesofcompetency v-loading="loading" element-loading-text="数据加载中" :authList="authList" :authTo="authTo" title="权限规则" />
- </div>
- <div class="flex1 part">
- <Rolelist v-loading="loading" element-loading-text="数据加载中" @checkChange="checkChange" @checkClick="checkClick" :dataList="arrs" :checkBoxList="radioCheck" :active="true" class="hucRole" :number="8" style="height: 280px; overflow: hidden" title="互斥角色" />
- <Permissionlist v-loading="permission" element-loading-text="数据加载中" :check="true" :RoleList="RoleList" class="hucPower" style="margin-top: 24px" title="互斥角色已有权限列表" />
- </div>
- </div>
- </div>
- </template>
- <script>
- import Permissionlist from "@/components/permissionlist";
- import Rulesofcompetency from "@/components/rulesofcompetency";
- import Permissiontree from "@/components/permissiontree";
- import Rolelist from "@/components/rolelist";
- import { RoleDetails, EditRole, RoleAuths } from "@/api/apiAuthority";
- import roleData from "../minixs/roleData";
- export default {
- name: "AuthorityRoleEdit",
- components: { Permissionlist, Rulesofcompetency, Permissiontree, Rolelist },
- mixins: [roleData],
- data () {
- return {
- radio: 1,
- form: {
- //应用表单
- name: "",
- id: "",
- app: "",
- },
- rules: {
- //表单验证
- name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
- },
- loading: false,
- permission: false,
- treeData: [],
- arrs: [],
- checkedKeys: [],
- RoleList: [],
- radioCheck: [],
- checkedBoxs: [],
- defRoleId: [],
- roleId: null,
- Status: null,
- authTo: {},
- authList: [],
- authId: [],
- type: null, //参数类型
- };
- },
- watch: {
- arrs: {
- handler (arr) {
- arr.forEach((item) => {
- item.name = item.RoleName;
- });
- this.checkedKeys = this.authId;
- this.arrs = arr;
- this.loading = false;
- },
- deep: true,
- },
- defRoleId: {
- handler (arr) {
- const datas = [];
- const arrs = [];
- this.arrs.forEach((item, index) => {
- arr.forEach((p) => {
- if (item.RoleId === p.DefRoleId) {
- const obj = {
- DefRoleId: item.RoleId,
- IsSelected: item.IsDef,
- DefRoleName: item.RoleName,
- };
- arrs.push(obj);
- datas.push(index);
- }
- });
- });
- this.radioCheck = datas;
- this.checkedBoxs = arrs;
- },
- deep: true,
- },
- },
- created () {
- //this.getAuthTree();
- const { RoleId, Status } = this.$route.query;
- this.roleId = RoleId;
- this.Status = Status;
- this.roleDetails(RoleId);
- },
- methods: {
- //角色明细
- async roleDetails (id) {
- try {
- this.loading = true;
- const res = await RoleDetails({
- RoleId: id,
- });
- if (res.code === 0) {
- const { RoleName, RoleDesc, AuthList, RoleStatus, DefRoleList } =
- res.returnData;
- this.form.name = RoleName;
- this.form.app = RoleDesc;
- this.radio = RoleStatus;
- if (AuthList && AuthList.length) {
- AuthList.forEach((item) => {
- this.authId.push(item.AuthId);
- });
- this.authList = _.cloneDeep(AuthList);
- this.authTo = AuthList[0];
- }
- if (DefRoleList && DefRoleList.length) {
- this.defRoleId = DefRoleList;
- this.roleAuths(DefRoleList[0].DefRoleId);
- }
- this.loading = false;
- } else {
- this.$message.error(res.message);
- this.loading = false;
- }
- } catch (error) {
- console.log("出错了", error);
- this.loading = false;
- }
- },
- //删除
- removeRole () {
- this.deleteRole(this.roleId);
- },
- //获取权限树回调
- getTreeData (arr) {
- this.treeData = arr;
- },
- //获取权限规则回调
- getData (obj) {
- this.authTo = obj;
- },
- //互斥角色选中回调
- checkChange (arr) {
- const datas = [];
- const arrs = [];
- this.arrs.forEach((item, index) => {
- arr.forEach((p) => {
- if (index === p) {
- datas.push(item);
- }
- });
- });
- datas.forEach((item) => {
- const obj = {
- DefRoleId: item.RoleId,
- IsSelected: 1,
- DefRoleName: item.RoleName,
- };
- arrs.push(obj);
- });
- this.checkedBoxs = arrs;
- },
- //互斥角色点击回调
- checkClick (item) {
- this.roleAuths(item.RoleId);
- },
- async roleAuths (id) {
- try {
- let params = {
- RoleId: id,
- };
- this.permission = true;
- const res = await RoleAuths(params);
- if (res.code === 0) {
- this.RoleList = res.returnData;
- this.permission = false;
- } else {
- this.$message.error(res.message);
- this.permission = false;
- }
- } catch (error) {
- console.log("出错了", error);
- this.permission = false;
- }
- },
- //保存
- saveBtn (formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.editRole();
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- //确认保存
- async editRole () {
- try {
- const datas = [];
- this.treeData.forEach((item) => {
- datas.push(item.AuthList);
- });
- const res = await EditRole({
- RoleName: this.form.name,
- RoleDesc: this.form.app,
- DefRoleList: this.checkedBoxs,
- AuthList: datas,
- RoleStatus: this.radio,
- RoleId: this.roleId,
- });
- if (res.code === 0) {
- this.$message.success(res.message);
- this.$store.dispatch("tagsView/delView", this.$route);
- this.$router.push("/role");
- } else {
- this.$message.error(res.message);
- }
- } catch (error) {
- console.log("出错了", error);
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- @import "../css/role.scss";
- </style>
|