authorityRoleEdit.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-11-29 16:31:31
  4. * @LastEditTime: 2022-02-08 11:06:41
  5. * @LastEditors: Please set LastEditors
  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 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 v-loading="loading" element-loading-text="数据加载中" @getTreeData="getTreeData" :checkedKeys="checkedKeys" title="权限树" />
  41. </div>
  42. <div class="r24 flex1 part">
  43. <Rulesofcompetency v-loading="loading" element-loading-text="数据加载中" :authList="authList" :authTo="authTo" title="权限规则" />
  44. </div>
  45. <div class="flex1 part">
  46. <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="互斥角色" />
  47. <Permissionlist v-loading="permission" element-loading-text="数据加载中" :check="true" :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. export default {
  60. name: "AuthorityRoleEdit",
  61. components: { Permissionlist, Rulesofcompetency, Permissiontree, Rolelist },
  62. mixins: [roleData],
  63. data () {
  64. return {
  65. radio: 1,
  66. form: {
  67. //应用表单
  68. name: "",
  69. id: "",
  70. app: "",
  71. },
  72. rules: {
  73. //表单验证
  74. name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
  75. },
  76. loading: false,
  77. permission: false,
  78. treeData: [],
  79. arrs: [],
  80. checkedKeys: [],
  81. RoleList: [],
  82. radioCheck: [],
  83. checkedBoxs: [],
  84. defRoleId: [],
  85. roleId: null,
  86. Status: null,
  87. authTo: {},
  88. authList: [],
  89. authId: [],
  90. type: null, //参数类型
  91. };
  92. },
  93. watch: {
  94. arrs: {
  95. handler (arr) {
  96. arr.forEach((item) => {
  97. item.name = item.RoleName;
  98. });
  99. this.checkedKeys = this.authId;
  100. this.arrs = arr;
  101. this.loading = false;
  102. },
  103. deep: true,
  104. },
  105. defRoleId: {
  106. handler (arr) {
  107. const datas = [];
  108. const arrs = [];
  109. this.arrs.forEach((item, index) => {
  110. arr.forEach((p) => {
  111. if (item.RoleId === p.DefRoleId) {
  112. const obj = {
  113. DefRoleId: item.RoleId,
  114. IsSelected: item.IsDef,
  115. DefRoleName: item.RoleName,
  116. };
  117. arrs.push(obj);
  118. datas.push(index);
  119. }
  120. });
  121. });
  122. this.radioCheck = datas;
  123. this.checkedBoxs = arrs;
  124. },
  125. deep: true,
  126. },
  127. },
  128. created () {
  129. //this.getAuthTree();
  130. const { RoleId, Status } = this.$route.query;
  131. this.roleId = RoleId;
  132. this.Status = Status;
  133. this.roleDetails(RoleId);
  134. },
  135. methods: {
  136. //角色明细
  137. async roleDetails (id) {
  138. try {
  139. this.loading = true;
  140. const res = await RoleDetails({
  141. RoleId: id,
  142. });
  143. if (res.code === 0) {
  144. const { RoleName, RoleDesc, AuthList, RoleStatus, DefRoleList } =
  145. res.returnData;
  146. this.form.name = RoleName;
  147. this.form.app = RoleDesc;
  148. this.radio = RoleStatus;
  149. if (AuthList && AuthList.length) {
  150. AuthList.forEach((item) => {
  151. this.authId.push(item.AuthId);
  152. });
  153. this.authList = _.cloneDeep(AuthList);
  154. this.authTo = AuthList[0];
  155. }
  156. if (DefRoleList && DefRoleList.length) {
  157. this.defRoleId = DefRoleList;
  158. this.roleAuths(DefRoleList[0].DefRoleId);
  159. }
  160. this.loading = false;
  161. } else {
  162. this.$message.error(res.message);
  163. this.loading = false;
  164. }
  165. } catch (error) {
  166. console.log("出错了", error);
  167. this.loading = false;
  168. }
  169. },
  170. //删除
  171. removeRole () {
  172. this.deleteRole(this.roleId);
  173. },
  174. //获取权限树回调
  175. getTreeData (arr) {
  176. this.treeData = arr;
  177. },
  178. //获取权限规则回调
  179. getData (obj) {
  180. this.authTo = obj;
  181. },
  182. //互斥角色选中回调
  183. checkChange (arr) {
  184. const datas = [];
  185. const arrs = [];
  186. this.arrs.forEach((item, index) => {
  187. arr.forEach((p) => {
  188. if (index === p) {
  189. datas.push(item);
  190. }
  191. });
  192. });
  193. datas.forEach((item) => {
  194. const obj = {
  195. DefRoleId: item.RoleId,
  196. IsSelected: 1,
  197. DefRoleName: item.RoleName,
  198. };
  199. arrs.push(obj);
  200. });
  201. this.checkedBoxs = arrs;
  202. },
  203. //互斥角色点击回调
  204. checkClick (item) {
  205. this.roleAuths(item.RoleId);
  206. },
  207. async roleAuths (id) {
  208. try {
  209. let params = {
  210. RoleId: id,
  211. };
  212. this.permission = true;
  213. const res = await RoleAuths(params);
  214. if (res.code === 0) {
  215. this.RoleList = res.returnData;
  216. this.permission = false;
  217. } else {
  218. this.$message.error(res.message);
  219. this.permission = false;
  220. }
  221. } catch (error) {
  222. console.log("出错了", error);
  223. this.permission = false;
  224. }
  225. },
  226. //保存
  227. saveBtn (formName) {
  228. this.$refs[formName].validate((valid) => {
  229. if (valid) {
  230. this.editRole();
  231. } else {
  232. console.log("error submit!!");
  233. return false;
  234. }
  235. });
  236. },
  237. //确认保存
  238. async editRole () {
  239. try {
  240. const datas = [];
  241. this.treeData.forEach((item) => {
  242. datas.push(item.AuthList);
  243. });
  244. const res = await EditRole({
  245. RoleName: this.form.name,
  246. RoleDesc: this.form.app,
  247. DefRoleList: this.checkedBoxs,
  248. AuthList: datas,
  249. RoleStatus: this.radio,
  250. RoleId: this.roleId,
  251. });
  252. if (res.code === 0) {
  253. this.$message.success(res.message);
  254. this.$store.dispatch("tagsView/delView", this.$route);
  255. this.$router.push("/role");
  256. } else {
  257. this.$message.error(res.message);
  258. }
  259. } catch (error) {
  260. console.log("出错了", error);
  261. }
  262. },
  263. },
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. @import "../css/role.scss";
  268. </style>