index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <div class="processPermission" v-loading="loading">
  3. <div class="processPermission_show_box" v-if="powers.some((i) => i == '001') && currentCompany">
  4. <ul class="role-list fl">
  5. <p class="role-list__title">角色列表</p>
  6. <p
  7. v-if="roleList.length == 0"
  8. style="line-height: 60px; text-align: center; color: #909399"
  9. >
  10. 暂无数据
  11. </p>
  12. <li
  13. v-for="(item, index) in roleList"
  14. :key="'role' + index"
  15. class="role-list__item"
  16. :class="{ active: item.id == roleActive.id }"
  17. @click="!isBtnDisabled && switchRoleHandle(item)"
  18. >
  19. {{ item.role_name }}
  20. <i v-if="isBtnDisabled && item.id == roleActive.id" class="el-icon-loading" />
  21. </li>
  22. </ul>
  23. <div class="rule-view fr">
  24. <div class="rule-list" v-if="roleList.length > 0">
  25. <el-row v-for="(item, index) in perActionList" :key="'menu' + item.id + index">
  26. <el-col class="title" :span="24">
  27. <span>{{ item.process_name }}</span>
  28. </el-col>
  29. <el-col class="main clear" :span="24">
  30. <div class="main-title fl">
  31. <el-checkbox
  32. v-model="item.checkAll"
  33. @change="handleCheckAllChange($event, index, item)"
  34. :indeterminate="indeterminateCheck(item)"
  35. :disabled="!powers.some((it) => it == '008')"
  36. >全选</el-checkbox
  37. >
  38. </div>
  39. <div class="main-item fl">
  40. <el-checkbox-group
  41. v-model="item.checkList"
  42. @change="handleCheckedGroupChange($event, index, item)"
  43. :disabled="!powers.some((it) => it == '008')"
  44. >
  45. <el-checkbox
  46. @change="handleCheckedChange($event, subitem.id, index, item)"
  47. v-for="(subitem, subIndex) in item.child"
  48. :key="'checkItem' + subitem.id"
  49. :label="subitem.id"
  50. >{{ subitem.status_name }}</el-checkbox
  51. >
  52. </el-checkbox-group>
  53. </div>
  54. </el-col>
  55. </el-row>
  56. </div>
  57. <p
  58. v-else
  59. style="line-height: 60px;margin-top: 50px ;text-align: center; color: #909399"
  60. >
  61. 暂无数据
  62. </p>
  63. </div>
  64. <div class="rule-bottom fr" v-if="roleList.length > 0">
  65. <el-button
  66. size="small"
  67. type="primary"
  68. v-if="powers.some((i) => i == '008')"
  69. :disabled="isBtnDisabled"
  70. @click="save()"
  71. >提 交</el-button
  72. >
  73. </div>
  74. </div>
  75. <div class="select-wrapper" v-else-if="!currentCompany">
  76. <i class="el-icon-warning" />
  77. 请在右上角选择一家公司
  78. </div>
  79. <div v-else>
  80. <no-auth></no-auth>
  81. </div>
  82. </div>
  83. </template>
  84. <script>
  85. import asyncRequest from "@/apis/service/interest/processPermission";
  86. import companyHelper from "@/mixins/companyHelper.js";
  87. import resToken from "@/mixins/resToken";
  88. export default {
  89. name: "processPermission",
  90. mixins: [resToken,companyHelper],
  91. data() {
  92. return {
  93. loading:false,
  94. ruleForm: {},
  95. // 按钮是否可点击
  96. isBtnDisabled: false,
  97. // 当前角色
  98. roleActive: {},
  99. processPermissionChange: [],
  100. // 角色列表
  101. roleList: [],
  102. rules: [],
  103. // 功能权限列表
  104. perActionList: [],
  105. processPermission: [], // 功能数据
  106. private_data: [], //私有数据菜单ID
  107. private_field: [],
  108. };
  109. },
  110. computed: {
  111. powers() {
  112. const { btnList } = this.$store.getters;
  113. const tran = btnList.find((item) => item.menu_route === "processPermission") || {};
  114. const { action } = tran ?? {};
  115. return action ?? [];
  116. },
  117. indeterminateCheck() {
  118. return (item) => {
  119. // 选中子节点的数量
  120. const selectItemLength = item.child.filter(
  121. (filitem) =>
  122. item.checkList.findIndex((finditem) => finditem === filitem.id) > -1
  123. ).length;
  124. // 未选中子节点的数量
  125. const noSlectItemLength = item.child.filter(
  126. (filitem) =>
  127. item.checkList.findIndex((finditem) => finditem === filitem.id) == -1
  128. ).length;
  129. // // 当前节点的index
  130. // 存在选中子节点且存在未选中子节点为中间态
  131. return selectItemLength > 0 && noSlectItemLength > 0;
  132. };
  133. },
  134. },
  135. mounted() {
  136. this.initperActionList();
  137. },
  138. methods: {
  139. onCompanyChange(){
  140. this.initperActionList();
  141. },
  142. // 全选/全不选
  143. handleCheckAllChange(checkAll, index, item) {
  144. this.perActionList[index].checkAll = checkAll;
  145. this.$set(this.perActionList, index, item);
  146. this.perActionList[index].child.forEach((element) => {
  147. const findindex = this.perActionList[index].checkList.findIndex(
  148. (findItem) => findItem === element.id
  149. );
  150. if (checkAll && findindex == -1) {
  151. this.perActionList[index].checkList.push(element.id);
  152. } else if (!checkAll && findindex > -1) {
  153. this.perActionList[index].checkList.splice(findindex, 1);
  154. }
  155. });
  156. },
  157. // 复选框组内的选中/不选中
  158. handleCheckedGroupChange(event, index, item) {
  159. this.perActionList[index].checkAll = this.perActionList[index].child.every(
  160. (evitem) =>
  161. this.perActionList[index].checkList.findIndex(
  162. (finditem) => finditem === evitem.id
  163. ) > -1
  164. );
  165. this.$set(this.perActionList, index, item);
  166. },
  167. // 多选框选中/不选中
  168. handleCheckedChange(checked, id, index, item) {
  169. if (checked) {
  170. this.perActionList[index].checkList.indexOf(id) == -1 &&
  171. this.perActionList[index].checkList.push(id);
  172. } else {
  173. const find = this.perActionList[index].checkList.findIndex((e) => e == id);
  174. if (find > -1) {
  175. this.perActionList[index].checkList.splice(find, 1);
  176. }
  177. this.perActionList[index].checkAll = false;
  178. }
  179. this.$set(this.perActionList, index, item);
  180. // console.log(this.perActionList[index]);
  181. },
  182. // 切换角色
  183. switchRoleHandle(item) {
  184. this.roleActive = Object.assign({}, item);
  185. this.$nextTick(async () => {
  186. await this.refreshRoleDetail(item.id);
  187. });
  188. },
  189. // 保存
  190. async save() {
  191. let arr = [];
  192. this.perActionList.forEach((x) => {
  193. arr.push(...x.checkList);
  194. });
  195. if (arr.length === 0) {
  196. this.$message.warning("请选择节点!");
  197. } else {
  198. const model = {
  199. roleid: this.roleActive.id,
  200. action_data: arr,
  201. };
  202. const loadding = this.$loading();
  203. const { code, data, message } = await asyncRequest.update(model);
  204. if (code === 0) {
  205. this.$notify.success({
  206. title: "保存成功!",
  207. message: "",
  208. });
  209. } else if (code >= 100 && code <= 104) {
  210. await this.logout();
  211. } else {
  212. this.$message.warning(message);
  213. }
  214. loadding.close();
  215. }
  216. },
  217. // 刷新角色详情
  218. async refreshRoleDetail(roleid) {
  219. if (this.isBtnDisabled) return;
  220. this.isBtnDisabled = true;
  221. const { code, data, message } = await asyncRequest.detail({ roleid: roleid });
  222. if (code === 0) {
  223. const { action_data } = data ?? {};
  224. this.ruleForm = data;
  225. this.action_data_list = action_data ?? [];
  226. this.refreshRoleCheckAllStatus();
  227. } else if (code >= 100 && code <= 104) {
  228. await this.logout();
  229. } else {
  230. this.$message.warning(message);
  231. }
  232. this.isBtnDisabled = false;
  233. },
  234. // 初始化功能权限列表
  235. async initperActionList() {
  236. this.loading = true
  237. if(!this.currentCompany){
  238. this.$message.warning("请在右上角选择一家公司");
  239. return
  240. }
  241. const { code, data, message } = await asyncRequest.actionList({});
  242. if (code === 0) {
  243. this.rules = data;
  244. await this.initRoleList();
  245. } else if (code >= 100 && code <= 104) {
  246. this.rules = [];
  247. await this.logout();
  248. } else {
  249. this.rules = [];
  250. this.$message.warning(message);
  251. }
  252. this.loading = false
  253. },
  254. // 初始化角色列表
  255. async initRoleList() {
  256. const res = await asyncRequest.getRole({companyNo: this.currentCompany});
  257. if (res && res.code === 0 && res.data) {
  258. this.roleList = [].concat(res.data);
  259. if (this.roleList.length > 0) {
  260. await this.switchRoleHandle(this.roleList[0]);
  261. } else if (res && res.code >= 100 && res.code <= 104) {
  262. await this.logout();
  263. } else {
  264. this.$message.warning(res.message);
  265. }
  266. }
  267. },
  268. // 刷新选择状态
  269. refreshRoleCheckAllStatus() {
  270. const list = JSON.parse(JSON.stringify(this.rules));
  271. let arr = list.filter((item) => item.child && item.child.length > 0);
  272. arr = arr.map((x) => {
  273. x.checkAll = false;
  274. x.checkList = [];
  275. x.child.map((y) => {
  276. y.id += "";
  277. return y;
  278. });
  279. return x;
  280. });
  281. this.perActionList = arr;
  282. console.log(this.perActionList);
  283. console.log(this.action_data_list);
  284. this.perActionList.forEach((x, xi) => {
  285. if (x.child && x.child.length > 0) {
  286. x.child.forEach((y, yi) => {
  287. const Aindex = this.action_data_list.findIndex((a) => String(a) === String(y.id));
  288. if (Aindex !== -1) {
  289. x.checkList.push(this.action_data_list[Aindex]);
  290. }
  291. if (x.child.length === x.checkList.length) {
  292. x.checkAll = true;
  293. }
  294. });
  295. }
  296. this.$set(this.perActionList, xi, x);
  297. });
  298. },
  299. },
  300. };
  301. </script>
  302. <style lang="scss" scoped>
  303. @import "~@/styles/mixin.scss";
  304. .processPermission {
  305. position: relative;
  306. width: 100%;
  307. height: 100%;
  308. overflow: hidden;
  309. .select-wrapper{
  310. position: fixed;
  311. top: 50%;
  312. left: calc(50% + 80px);
  313. transform: translate(-50%,-50%);
  314. }
  315. .processPermission_show_box {
  316. // position: relative;
  317. // height: calc(100% - 50px);
  318. // min-height: calc(100% - 50px);
  319. display: relative;
  320. width: 100%;
  321. height: calc(100vh - 50px);
  322. overflow: hidden;
  323. text-align: left;
  324. //左侧
  325. .role-list {
  326. height: 100%;
  327. overflow-y: auto;
  328. width: 200px;
  329. padding: 8px 16px;
  330. min-height: 100%;
  331. flex-shrink: 0;
  332. border-right: 2px solid #dfe6ec;
  333. @include scrollBar();
  334. &::after {
  335. content: "";
  336. position: absolute;
  337. top: 0;
  338. right: 0;
  339. height: 100%;
  340. width: 2px;
  341. background-color: #e4e7ed;
  342. z-index: 1;
  343. }
  344. .role-list__title {
  345. color: #b4b6c0;
  346. line-height: 32px;
  347. }
  348. .role-list__item {
  349. position: relative;
  350. white-space: nowrap;
  351. text-overflow: ellipsis;
  352. overflow: hidden;
  353. height: 32px;
  354. line-height: 32px;
  355. padding-left: 8px;
  356. color: rgb(48, 49, 51);
  357. cursor: pointer;
  358. i {
  359. position: absolute;
  360. right: 0;
  361. line-height: 32px;
  362. }
  363. }
  364. .role-list__item.active {
  365. color: #6954f0;
  366. background: #f7f7f7;
  367. }
  368. }
  369. //右侧
  370. .rule-view {
  371. height: calc(100% - 50px);
  372. width: calc(100% - 200px);
  373. overflow-y: auto;
  374. @include scrollBar();
  375. .rule-list {
  376. border-right: 1px solid #dfe6ec;
  377. .title {
  378. padding: 18px 18px 12px 18px;
  379. border-bottom: 1px dashed #dfe6ec;
  380. font-size: 15px;
  381. color: #000;
  382. }
  383. .main {
  384. padding: 18px 18px 12px 18px;
  385. border-bottom: 1px solid #dfe6ec;
  386. }
  387. .main-title {
  388. width: 80px;
  389. }
  390. .main-item {
  391. width: calc(100% - 80px);
  392. }
  393. }
  394. }
  395. .rule-bottom {
  396. padding: 10px 18px 8px 0;
  397. background: #fff;
  398. width: calc(100% - 200px);
  399. position: absolute;
  400. text-align: right;
  401. bottom: 0;
  402. right: 0;
  403. &::before {
  404. content: "";
  405. position: absolute;
  406. top: 0;
  407. right: 0;
  408. height: 2px;
  409. width: 100%;
  410. background-color: #e4e7ed;
  411. z-index: 1;
  412. }
  413. }
  414. }
  415. }
  416. </style>