authorityRoleEdit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 16:31:31
  4. * @LastEditTime: 2022-03-15 16:39:51
  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="请输入角色名称" maxlength="32" v-model="form.name"></el-input>
  31. </el-form-item>
  32. <el-form-item label="描述">
  33. <el-input style="width: 640px" maxlength="200" placeholder="请输入描述" v-model="form.app"></el-input>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. </div>
  38. <div class="power-content flex-wrap">
  39. <div class="r24 flex1 part">
  40. <Permissiontree @getTreeData="getTreeData" :checkedKeys="checkedKeys" title="权限树" />
  41. </div>
  42. <div :class="isClass ? '':'r24'" class="flex1 part">
  43. <Rulesofcompetency :authList="authList" :authTo="authTo" title="权限规则" />
  44. </div>
  45. <div v-is="['role_edit_mutually_exclusive','role_edit_mutually_exclusive_list']" class="flex1 part">
  46. <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="互斥角色" />
  47. <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="互斥角色已有权限列表" />
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import Permissionlist from "@/components/permissionlist";
  54. import Rulesofcompetency from "@/components/rulesofcompetency";
  55. import Permissiontree from "@/components/permissiontree";
  56. import Rolelist from "@/components/rolelist";
  57. import { RoleDetails, EditRole, RoleAuths } from "@/api/apiAuthority";
  58. import roleData from "../minixs/roleData";
  59. import { checkPermission } from '@/utils/add-is-class';
  60. import { lengthValidator } from '@/utils/validate'
  61. export default {
  62. name: "AuthorityRoleEdit",
  63. components: { Permissionlist, Rulesofcompetency, Permissiontree, Rolelist },
  64. mixins: [roleData],
  65. data () {
  66. return {
  67. radio: 1,
  68. form: {
  69. //应用表单
  70. name: "",
  71. id: "",
  72. app: "",
  73. },
  74. rules: {
  75. //表单验证
  76. name: [
  77. { required: true, message: "请输入角色名称", trigger: "blur" },
  78. { validator: lengthValidator, max: 32, message: '最多输入32个字符', trigger: ['change', 'blur'] }
  79. ],
  80. app: [
  81. { validator: lengthValidator, max: 128, message: '最多输入128个字符', trigger: ['change', 'blur'] }
  82. ],
  83. },
  84. loading: false,
  85. permission: false,
  86. treeData: [],
  87. arrs: [],
  88. checkedKeys: [],
  89. RoleList: [],
  90. radioCheck: [],
  91. checkedBoxs: [],
  92. defRoleId: [],
  93. roleId: null,
  94. Status: null,
  95. authTo: {},
  96. authList: [],
  97. authId: [],
  98. type: null, //参数类型
  99. roleType: ''
  100. };
  101. },
  102. created () {
  103. //this.getAuthTree();
  104. const { RoleId, Status } = this.$route.query;
  105. this.roleId = RoleId;
  106. this.Status = Status;
  107. this.roleDetails(RoleId);
  108. },
  109. mounted () {
  110. this.roleType = 'onlyRole';
  111. },
  112. computed: {
  113. isClass () {
  114. const le = checkPermission(['role_add_mutually_exclusive', 'role_add_mutually_exclusive_list']);
  115. return le;
  116. }
  117. },
  118. methods: {
  119. //角色明细
  120. async roleDetails (id) {
  121. try {
  122. this.loading = true;
  123. const res = await RoleDetails({
  124. RoleId: id,
  125. });
  126. if (res.code === 0) {
  127. const { RoleName, RoleDesc, AuthList, RoleStatus, DefRoleList } =
  128. res.returnData;
  129. this.form.name = RoleName;
  130. this.form.app = RoleDesc;
  131. this.radio = RoleStatus;
  132. if (AuthList && AuthList.length) {
  133. AuthList.forEach((item) => {
  134. this.authId.push(item.AuthId);
  135. });
  136. this.checkedKeys = this.authId;
  137. this.authList = _.cloneDeep(AuthList);
  138. this.authTo = AuthList[0];
  139. }
  140. if (DefRoleList && DefRoleList.length) {
  141. this.checkedBoxs = DefRoleList;
  142. DefRoleList.forEach(item => {
  143. item.RoleId = item.DefRoleId
  144. })
  145. this.radioCheck = DefRoleList;
  146. this.roleAuths(DefRoleList[0].DefRoleId);
  147. }
  148. this.loading = false;
  149. } else {
  150. this.$message.error(res.message);
  151. this.loading = false;
  152. }
  153. } catch (error) {
  154. console.log("出错了", error);
  155. this.loading = false;
  156. }
  157. },
  158. //删除
  159. removeRole () {
  160. this.deleteRole(this.roleId);
  161. },
  162. //获取权限树回调
  163. getTreeData (arr) {
  164. this.treeData = arr;
  165. },
  166. //获取权限规则回调
  167. getData (obj) {
  168. this.authTo = obj;
  169. },
  170. //互斥角色选中回调
  171. checkChange (arr) {
  172. const arrs = [];
  173. arr.forEach((item) => {
  174. const obj = {
  175. DefRoleId: item.RoleId,
  176. IsSelected: 1,
  177. DefRoleName: item.RoleName,
  178. };
  179. arrs.push(obj);
  180. });
  181. this.checkedBoxs = arrs;
  182. },
  183. //互斥角色点击回调
  184. checkClick (item) {
  185. this.roleAuths(item.RoleId);
  186. },
  187. async roleAuths (id) {
  188. try {
  189. let params = {
  190. RoleId: id,
  191. };
  192. this.permission = true;
  193. const res = await RoleAuths(params);
  194. if (res.code === 0) {
  195. this.RoleList = res.returnData;
  196. this.permission = false;
  197. } else {
  198. this.$message.error(res.message);
  199. this.permission = false;
  200. }
  201. } catch (error) {
  202. console.log("出错了", error);
  203. this.permission = false;
  204. }
  205. },
  206. //保存
  207. saveBtn (formName) {
  208. this.$refs[formName].validate((valid) => {
  209. if (valid) {
  210. this.editRole();
  211. } else {
  212. console.log("error submit!!");
  213. return false;
  214. }
  215. });
  216. },
  217. //确认保存
  218. async editRole () {
  219. try {
  220. const datas = [];
  221. this.treeData.forEach((item) => {
  222. datas.push(item.AuthList);
  223. });
  224. const res = await EditRole({
  225. RoleName: this.form.name,
  226. RoleDesc: this.form.app,
  227. DefRoleList: this.checkedBoxs,
  228. AuthList: datas,
  229. RoleStatus: this.radio,
  230. RoleId: this.roleId,
  231. });
  232. if (res.code === 0) {
  233. this.$message.success(res.message);
  234. this.$store.dispatch("tagsView/delView", this.$route);
  235. this.$router.push("/role");
  236. } else {
  237. this.$message.error(res.message);
  238. }
  239. } catch (error) {
  240. console.log("出错了", error);
  241. }
  242. },
  243. },
  244. };
  245. </script>
  246. <style lang="scss" scoped>
  247. @import "../css/role.scss";
  248. </style>