table-column-auth.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!--
  2. 表权限 - 标签授权、人员授权、机构授权 -公用
  3. @Author: linqian
  4. @Date: 2021-04-19 15:46
  5. -->
  6. <template>
  7. <div>
  8. <div v-if="subId">
  9. <div style="height: calc(100vh - 22rem)">
  10. <dg-scrollbar :key="key">
  11. <set-auth-tree
  12. :ref="'authTree_'+index"
  13. :tab="tab"
  14. v-for="(item, index) in authData"
  15. :key="index"
  16. :treeData="item"
  17. :reactTree="reactTree"
  18. @getSelectNodes="getSelectNodes"
  19. @checkChange="checkChange"
  20. ></set-auth-tree>
  21. </dg-scrollbar>
  22. </div>
  23. </div>
  24. <div v-else>
  25. <p v-if="subType == 'BUSINESS'">请选择标签。</p>
  26. <p v-else-if="subType == 'ORG'">请选择机构。</p>
  27. <p v-else>请选择人员。</p>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import * as api from "@/api/data-auth.js";
  33. import setAuthTree from "./set-auth-tree";
  34. import checkList from "./check-list";
  35. export default {
  36. props: {
  37. subId: String,
  38. subType: String,
  39. saveApi: String,
  40. tab: String,
  41. reactTree:Boolean,
  42. singleAuthData: Array
  43. },
  44. components: {
  45. setAuthTree
  46. },
  47. data() {
  48. return {
  49. authData: [],
  50. showCheckListBtn: false,
  51. saveAuthVoList: {},
  52. key:0
  53. };
  54. },
  55. computed: {},
  56. watch: {
  57. singleAuthData: {
  58. deep: true,
  59. handler(val) {
  60. if (this.reactTree) {
  61. let _authData = this.$lodash.cloneDeep(this.authData);
  62. for (let i = 0; i < val.length; i++) {
  63. const { id, tickedDatas } = val[i];
  64. for (let j = 0; j < _authData.length; j++) {
  65. let element = _authData[j];
  66. if (element.id == id) {
  67. element.selectNodes = tickedDatas.map((item) => {
  68. const { dataId, dataType, dataCode, classifyCode } = item;
  69. return {
  70. dataId,
  71. classifyCode,
  72. dataCode
  73. };
  74. });
  75. }
  76. }
  77. }
  78. this.authData = _authData;
  79. this.key++
  80. console.log("authData",this.authData);
  81. }
  82. }
  83. }
  84. },
  85. methods: {
  86. handleViewAuthList() {
  87. const vm = this;
  88. const layer = this.$dgLayer({
  89. title: "授权清单",
  90. content: checkList,
  91. props: {
  92. type: vm.tab,
  93. authTree: vm.authTree
  94. },
  95. on: {
  96. success(params) {
  97. layer.close(layer.dialogIndex);
  98. }
  99. },
  100. cancel: function (index, layero) {
  101. // 关闭对应弹窗的ID
  102. layer.close(index);
  103. return false;
  104. },
  105. area: ["1150px", "850px"]
  106. });
  107. },
  108. /**
  109. * @description: 重置授权
  110. */
  111. handleReset() {
  112. this.$emit("submitReset", this.tab)
  113. },
  114. /**
  115. * @description: 保存授权
  116. */
  117. handleSave() {
  118. // 保存的树节点
  119. // let authVoList = [];
  120. // for (const key in this.saveAuthVoList) {
  121. // const element = this.saveAuthVoList[key];
  122. // authVoList = [...authVoList, ...element];
  123. // }
  124. // // 数组去重
  125. // let obj = {};
  126. // const _authVoList = authVoList.reduce((cur, next) => {
  127. // obj[next.dataId] ? "" : (obj[next.dataId] = true && cur.push(next));
  128. // return cur;
  129. // }, []);
  130. // return _authVoList
  131. let attr = []
  132. for (let i = 0; i < this.authData.length; i++) {
  133. const selectNode = this.$refs['authTree_'+i][0].$refs.authTree.getCheckedNodes(true);
  134. attr = [...attr, ...selectNode]
  135. }
  136. console.log("attr",attr)
  137. return attr.map(item => {
  138. return {
  139. dataId: item.id,
  140. dataCode: item.code,
  141. classifyCode: item.classifyCode
  142. }
  143. })
  144. },
  145. // 获取勾选的节点
  146. getSelectNodes({ type, selectNodes }) {
  147. this.saveAuthVoList[type] = selectNodes;
  148. },
  149. checkChange(vo) {
  150. this.$emit("checkChange", vo)
  151. },
  152. // 查询单个主体相关数据权限
  153. getSubDataAuth() {
  154. return new Promise((resolve) => {
  155. const { subId, subType } = this;
  156. const params = {
  157. authType: this.tab,
  158. subId,
  159. subType
  160. };
  161. api.getSubDataAuth(params).then((res) => {
  162. resolve(res.data.content);
  163. });
  164. });
  165. },
  166. getAllDataTree() {
  167. // 获取表权限
  168. return new Promise((resolve) => {
  169. api.getAllDataTree({ attrType: this.tab }).then((res) => {
  170. resolve(res.data.content);
  171. });
  172. });
  173. },
  174. async initAuthTree() {
  175. if (this.subId) {
  176. const singleAuthData = await this.getSubDataAuth();
  177. let authTree = await this.getAllDataTree();
  178. if (singleAuthData.length > 0) {
  179. this.showCheckListBtn = true;
  180. for (let i = 0; i < singleAuthData.length; i++) {
  181. const { id, tickedDatas } = singleAuthData[i];
  182. for (let j = 0; j < authTree.length; j++) {
  183. let element = authTree[j];
  184. if (element.id == id) {
  185. this.saveAuthVoList[id] = element.selectNodes = tickedDatas.map((item) => {
  186. const { dataId, dataType, dataCode, classifyCode } = item;
  187. return {
  188. dataId,
  189. classifyCode,
  190. dataCode
  191. };
  192. });
  193. }
  194. }
  195. }
  196. } else {
  197. this.showCheckListBtn = false;
  198. }
  199. console.log("saveAuthVoList", this.saveAuthVoList);
  200. this.authData = authTree;
  201. }
  202. }
  203. },
  204. created() {
  205. console.log("初始化");
  206. this.initAuthTree();
  207. },
  208. mounted() {}
  209. };
  210. </script>
  211. <style lang='scss'>
  212. </style>