authorityRoleEdit.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 16:31:31
  4. * @LastEditTime: 2022-04-07 11:04:34
  5. * @LastEditors: your name
  6. * @Description: 新增/编辑角色
  7. * @FilePath: \Foshan4A2.0\src\views\authorityManagement\components\authorityRoleStatus.vue
  8. -->
  9. <template>
  10. <div class="authorityPower">
  11. <!--新增权限项-->
  12. <div class="addApp-form">
  13. <div class="addApp-form-title flex">
  14. <div class="title">
  15. 编辑角色
  16. <!-- <span class="isqy">
  17. <span>是否启用</span>
  18. <el-radio v-model="radio" :label="1">是</el-radio>
  19. <el-radio v-model="radio" :label="0">否</el-radio>
  20. </span> -->
  21. </div>
  22. <div v-is="['role_edit_save']" class="btn">
  23. <!-- <el-button class="r24" @click="removeRole" type="danger">删除</el-button> -->
  24. <el-button @click="saveBtn('form')" type="primary">保存</el-button>
  25. </div>
  26. </div>
  27. <div class="addApp-form-content dialog-public-background">
  28. <el-form :inline="true" ref="form" :rules="rules" class="form" :model="form">
  29. <el-form-item prop="name" label="角色名称">
  30. <el-input placeholder="请输入角色名称" v-model.trim="form.name"></el-input>
  31. </el-form-item>
  32. <el-form-item prop="desc" label="描述">
  33. <el-input style="width: 1270px" placeholder="请输入描述" v-model.trim="form.desc"></el-input>
  34. </el-form-item>
  35. </el-form>
  36. <div class="orgXf flex-wrap">
  37. <div class="orgXf_title">选择下发应用</div>
  38. <div class="orgXf_content">
  39. <el-checkbox-group v-model="checkList">
  40. <el-col v-for="(item,index) in checkArr" :key="index" class="orgXf_content_list" :span="3">
  41. <el-checkbox :label="item.appId">{{item.appName}}</el-checkbox>
  42. </el-col>
  43. </el-checkbox-group>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="power-content flex-wrap">
  49. <div class="r24 flex1 part">
  50. <Permissiontree v-loading="loading" element-loading-text="加载中" @getTreeData="getTreeData" :checkedKeys="checkedKeys" title="权限树" />
  51. </div>
  52. <div :class="isClass ? '':'r24'" class="flex1 part">
  53. <Rulesofcompetency :authList="authList" :authTo="authTo" title="权限规则" />
  54. </div>
  55. <div v-is="['role_edit_mutually_exclusive','role_edit_mutually_exclusive_list']" class="flex1 part">
  56. <Rolelist v-is="['role_edit_mutually_exclusive']" @checkChange="checkChange" @checkClick="checkClick" :roleType="roleType" needType="1" :needId="roleId" :checkBoxList="radioCheck" :active="true" class="hucRole" :imageSize="80" :number="8" style="height: 280px; overflow: hidden" title="互斥角色" />
  57. <Permissionlist v-is="['role_edit_mutually_exclusive_list']" v-loading="permission" element-loading-text="数据加载中" :check="true" :imageSize="80" :RoleList="RoleList" class="hucPower" style="margin-top: 24px" title="互斥角色已有权限列表" />
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import Permissionlist from "@/components/permissionlist";
  64. import Rulesofcompetency from "@/components/rulesofcompetency";
  65. import Permissiontree from "@/components/permissiontree";
  66. import Rolelist from "@/components/rolelist";
  67. import { RoleDetails, EditRole, RoleAuths } from "@/api/apiAuthority";
  68. import roleData from "../minixs/roleData";
  69. import capData from "../../organizationManagement/minixs/roleData";
  70. import { checkPermission } from '@/utils/add-is-class';
  71. import { lengthValidator } from '@/utils/validate'
  72. export default {
  73. name: "AuthorityRoleEdit",
  74. components: { Permissionlist, Rulesofcompetency, Permissiontree, Rolelist },
  75. mixins: [roleData, capData],
  76. data () {
  77. return {
  78. radio: 1,
  79. form: {
  80. //应用表单
  81. name: "",
  82. id: "",
  83. desc: "",
  84. },
  85. rules: {
  86. //表单验证
  87. name: [
  88. { required: true, message: "请输入角色名称", trigger: "blur" },
  89. { validator: lengthValidator, max: 128, message: '长度在 1 到 128 个字符', trigger: ['change', 'blur'] }
  90. ],
  91. desc: [
  92. { validator: lengthValidator, max: 256, message: '长度在 1 到 256 个字符', trigger: ['change', 'blur'] }
  93. ],
  94. },
  95. loading: false,
  96. permission: false,
  97. treeData: [],
  98. arrs: [],
  99. checkedKeys: [],
  100. RoleList: [],
  101. RelationUsers: [],
  102. radioCheck: [],
  103. checkedBoxs: [],
  104. defRoleId: [],
  105. roleId: null,
  106. Status: null,
  107. authTo: {},
  108. authList: [],
  109. authId: [],
  110. type: null, //参数类型
  111. roleType: '',
  112. };
  113. },
  114. created () {
  115. //this.getAuthTree();
  116. const { RoleId, Status } = this.$route.query;
  117. this.roleId = RoleId;
  118. this.Status = Status;
  119. this.getSendSystem();
  120. this.roleDetails(RoleId);
  121. },
  122. mounted () {
  123. this.roleType = 'onlyRole';
  124. },
  125. computed: {
  126. isClass () {
  127. const le = checkPermission(['role_add_mutually_exclusive', 'role_add_mutually_exclusive_list']);
  128. return le;
  129. }
  130. },
  131. methods: {
  132. //角色明细
  133. async roleDetails (id) {
  134. try {
  135. this.loading = true;
  136. const res = await RoleDetails({
  137. RoleId: id,
  138. });
  139. if (res.code === 0) {
  140. const { RoleName, RoleDesc, AuthList, RoleStatus, DefRoleList, RelationUsers, Apps } =
  141. res.returnData;
  142. this.form.name = RoleName;
  143. this.form.desc = RoleDesc;
  144. this.radio = RoleStatus;
  145. this.checkList = Apps ?? [];
  146. if (AuthList && AuthList.length) {
  147. AuthList.forEach((item) => {
  148. this.authId.push(item.AuthId);
  149. });
  150. this.checkedKeys = this.authId;
  151. this.authList = _.cloneDeep(AuthList);
  152. this.authTo = AuthList[0];
  153. }
  154. if (DefRoleList && DefRoleList.length) {
  155. this.checkedBoxs = DefRoleList;
  156. DefRoleList.forEach(item => {
  157. item.RoleId = item.DefRoleId
  158. })
  159. this.radioCheck = DefRoleList;
  160. this.roleAuths(DefRoleList[0].DefRoleId);
  161. }
  162. this.RelationUsers = RelationUsers
  163. this.loading = false;
  164. } else {
  165. this.$message.error(res.message);
  166. this.loading = false;
  167. }
  168. } catch (error) {
  169. console.log("出错了", error);
  170. this.loading = false;
  171. }
  172. },
  173. //删除
  174. removeRole () {
  175. this.deleteRole(this.roleId);
  176. },
  177. //获取权限树回调
  178. getTreeData (arr) {
  179. this.treeData = arr;
  180. },
  181. //获取权限规则回调
  182. getData (obj) {
  183. this.authTo = obj;
  184. },
  185. //互斥角色选中回调
  186. checkChange (arr) {
  187. const arrs = [];
  188. arr.forEach((item) => {
  189. const obj = {
  190. DefRoleId: item.RoleId,
  191. IsSelected: 1,
  192. DefRoleName: item.RoleName,
  193. };
  194. arrs.push(obj);
  195. });
  196. this.checkedBoxs = arrs;
  197. },
  198. //互斥角色点击回调
  199. checkClick (item) {
  200. this.roleAuths(item.RoleId);
  201. },
  202. async roleAuths (id) {
  203. try {
  204. let params = {
  205. RoleId: id,
  206. };
  207. this.permission = true;
  208. const res = await RoleAuths(params);
  209. if (res.code === 0) {
  210. this.RoleList = res.returnData;
  211. this.permission = false;
  212. } else {
  213. this.$message.error(res.message);
  214. this.permission = false;
  215. }
  216. } catch (error) {
  217. console.log("出错了", error);
  218. this.permission = false;
  219. }
  220. },
  221. //保存
  222. saveBtn (formName) {
  223. this.$refs[formName].validate((valid) => {
  224. if (valid) {
  225. this.editRole();
  226. } else {
  227. console.log("error submit!!");
  228. return false;
  229. }
  230. });
  231. },
  232. //确认保存
  233. async editRole () {
  234. try {
  235. const datas = [];
  236. this.treeData.forEach((item) => {
  237. item.AuthList && datas.push(item.AuthList);
  238. });
  239. const res = await EditRole({
  240. RoleName: this.form.name,
  241. RoleDesc: this.form.desc,
  242. DefRoleList: this.checkedBoxs,
  243. AuthList: datas,
  244. RoleStatus: this.radio,
  245. RoleId: this.roleId,
  246. RelationUsers: this.RelationUsers,
  247. Apps: this.checkList
  248. });
  249. if (res.code === 0) {
  250. this.$message.success(res.message);
  251. this.$store.dispatch("tagsView/delView", this.$route);
  252. this.$router.push("/role");
  253. } else {
  254. this.$message.error(res.message);
  255. }
  256. } catch (error) {
  257. console.log("出错了", error);
  258. }
  259. },
  260. },
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. @import "../css/role.scss";
  265. .orgXf {
  266. margin-top: 20px;
  267. &_title {
  268. margin-right: 40px;
  269. font-size: 14px;
  270. color: #606266;
  271. font-weight: 600;
  272. }
  273. &_content {
  274. flex: 1;
  275. &_list {
  276. margin-bottom: 20px;
  277. }
  278. }
  279. }
  280. </style>