index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <div class="bf-permissiontree">
  3. <!-- 权限树 -->
  4. <div class="cont">
  5. <div class="paren_header">
  6. <p>{{ title }}</p>
  7. </div>
  8. <div class="paren_type">
  9. <ul>
  10. <li>
  11. <div class="log"></div>
  12. <p>时效规则有</p>
  13. </li>
  14. <li>
  15. <div class="log"></div>
  16. <p>数据规则有</p>
  17. </li>
  18. <li>
  19. <div class="log"></div>
  20. <p>显示及编辑权限</p>
  21. </li>
  22. <li>
  23. <div class="log"></div>
  24. <p>显示权限</p>
  25. </li>
  26. </ul>
  27. </div>
  28. <!-- <div class="paren_list">
  29. <ul>
  30. <li v-for="(item, index) in treeTitles" :key="index">
  31. <div
  32. class="up_type"
  33. :class="active === index ? 'up_types' : 'up_type'"
  34. @click="upActive(item, index)"
  35. >
  36. {{ item.AuthName }}
  37. </div>
  38. </li>
  39. </ul>
  40. </div> -->
  41. <div class="paren_cont">
  42. <el-scrollbar style="height: 100%">
  43. <!-- <el-tree :data="data" show-checkbox :check-strictly="true" @check-change="currentChange" @node-click="handleNodeClick" :defaultProps="defaultProps" :expand-on-click-node="false" node-key="AuthId" default-expand-all ref="tree" highlight-current> -->
  44. <el-tree :data="data" show-checkbox @check="currentChange" :default-expanded-keys="defaultExpandedKeys" @node-click="handleNodeClick" :defaultProps="defaultProps" node-key="auth_id" ref="tree" highlight-current>
  45. <span class="custom-tree-node" slot-scope="{ data }">
  46. {{ data.auth_name }}
  47. <div class="logup">
  48. <!-- <div class="one" v-if="data.AuthList && data.AuthList.ValidBegin"></div>
  49. <div class="two" v-if="data.AuthList && data.AuthList.Action == '1'"></div>
  50. <div class="four" v-if="data.AuthList && data.AuthList.Action == '2'"></div> -->
  51. <div class="three" v-if="
  52. data.AuthList &&
  53. (data.AuthList.EditCol || data.EditCol ||
  54. data.AuthList.DeleteRow || data.DeleteRow ||
  55. data.AuthList.EditRow || data.EditRow ||
  56. data.AuthList.NewCol || data.NewCol ||
  57. data.AuthList.QueryCol || data.QueryCol ||
  58. data.AuthList.QueryRow || data.QueryRow)
  59. "></div>
  60. </div>
  61. </span>
  62. </el-tree>
  63. </el-scrollbar>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. // import treeData from "@/views/authorityManagement/minixs/treeData";
  70. import { translateDataToTreeAll, deteleObject } from "@/utils/validate";
  71. import { GetAuthTree } from "@/api/apiAuthority";
  72. import { GetAuthTreeByGroup } from "@/api/AccountGroup";
  73. import { organizationUptree, postUptree } from "@/api/postInterface";
  74. import { GeneralDataReception, Query } from '@/api/dataIntegration';
  75. export default {
  76. props: {
  77. title: {
  78. type: String,
  79. default: "",
  80. },
  81. checkedKeys: {
  82. //已选中
  83. type: Array,
  84. default: () => [],
  85. },
  86. //查询类型:queryType: all/获取全部权限树;job/根据岗位获取权限树;origin/根据组织获取权限树;group/根据帐号组获取权限树;
  87. queryType: {
  88. type: String,
  89. default: "all",
  90. },
  91. //要查询的查询ID
  92. queryId: {
  93. type: String | Number,
  94. default: "",
  95. },
  96. queryIds: {
  97. type: Array,
  98. default: () => []
  99. },
  100. //要查询的查询ID
  101. isMainJob: {
  102. type: Boolean,
  103. default: true,
  104. },
  105. },
  106. data () {
  107. return {
  108. active: 0,
  109. data: [],
  110. treeTitles: [],
  111. defaultProps: {
  112. children: "children",
  113. label: "auth_name",
  114. },
  115. searchId: "",
  116. dataObj: {}, //上级权限指定树数据
  117. AuthArrList: [], //权限列表源数据
  118. AuthList: [], //权限规则列表
  119. checkedList: [], //选中的列表
  120. oldType: "",
  121. queryIdArr: [], //历史查询ID
  122. MainJobId: "",//主岗ID
  123. defaultExpandedKeys: [-1],
  124. treeChecks: [],
  125. };
  126. },
  127. watch: {
  128. checkedKeys: {
  129. handler (val) {
  130. this.checkedList = val;
  131. this.treeChecks = val;
  132. },
  133. deep: true,
  134. },
  135. "$store.state.auth.authList": {
  136. handler (val) {
  137. if (val && val.length) {
  138. this.AuthList = val;
  139. this.resetData();
  140. } else {
  141. this.getAuthList();
  142. }
  143. },
  144. immediate: true,
  145. deep: true,
  146. },
  147. queryId: {
  148. handler (val) {
  149. if (this.queryType == "job") {
  150. this.setDisabledAll();
  151. let ids = val.split(",");
  152. this.queryIdArr = [];
  153. this.$refs.tree.setCheckedKeys([]);
  154. if (this.isMainJob == true) {
  155. this.MainJobId = val;
  156. }
  157. if (this.MainJobId != "") {
  158. this.queryIdArr.push(this.MainJobId);
  159. }
  160. for (let i = 0; i < ids.length; i++) {
  161. if (_.indexOf(this.queryIdArr, ids[i]) == -1) {
  162. this.queryIdArr.push(ids[i]);
  163. }
  164. }
  165. for (let j = 0; j < this.queryIdArr.length; j++) {
  166. this.searchId = this.queryIdArr[j];
  167. this.getDefaultDataList();
  168. }
  169. } else {
  170. this.searchId = val;
  171. this.getDefaultDataList();
  172. }
  173. },
  174. deep: true,
  175. },
  176. queryIds: {
  177. handler () {
  178. this.getDefaultDataList()
  179. },
  180. deep: true
  181. },
  182. treeChecks: {
  183. handler (val) {
  184. if (val && val.length) {
  185. this.$refs.tree.setCheckedKeys(val);
  186. }
  187. },
  188. deep: true
  189. }
  190. },
  191. created () {
  192. this.getDataList();
  193. this.searchId = this.queryId;
  194. },
  195. methods: {
  196. getAuthList () {
  197. let arr = [];
  198. setTimeout(() => {
  199. arr = this.$store.getters.authList;
  200. if (arr && arr.length) {
  201. this.AuthList = arr;
  202. this.resetData();
  203. } else {
  204. this.getAuthList();
  205. }
  206. }, 100);
  207. },
  208. //获取权限列表
  209. getDataList () {
  210. Query({
  211. id: DATACONTENT_ID.authTreeId,
  212. dataContent: ['']
  213. }).then((result) => {
  214. // this.getDefaultDataList();
  215. this.setUnDisabledData(result.returnData.listValues);
  216. this.setData(result);
  217. });
  218. },
  219. async getDefaultDataList () {
  220. if (this.queryType == "all" && this.searchId != "") {
  221. //获取全部权限树
  222. Query({
  223. id: DATACONTENT_ID.authTreeId,
  224. dataContent: ['']
  225. }).then((result) => {
  226. this.setUnDisabledData(result.returnData.listValues);
  227. });
  228. } else if (this.queryType == "job") {
  229. //根据岗位获取权限树
  230. postUptree({ JobId: this.searchId }).then((result) => {
  231. this.setUnDisabledData(result.returnData.listValues);
  232. });
  233. } else if (this.queryType == "origin") {
  234. //根据组织获取权限树
  235. this.AuthList = [];
  236. this.$refs.tree.setCheckedKeys([])
  237. organizationUptree({ OrganId: this.searchId }).then((result) => {
  238. this.setUnDisabledData(result.returnData.listValues);
  239. });
  240. } else if (this.queryType == "group") {
  241. //根据帐号组获取权限树
  242. if (this.searchId) {
  243. GetAuthTreeByGroup({ GroupIds: [this.searchId] }).then((result) => {
  244. this.setUnDisabledData(result.returnData.listValues);
  245. });
  246. } else if (this.queryIds.length && this.queryIds[0] !== -1) {
  247. GetAuthTreeByGroup({ GroupIds: this.queryIds }).then((result) => {
  248. this.setUnDisabledData(result.returnData.listValues)
  249. })
  250. }
  251. }
  252. },
  253. setData (result) {
  254. if (result.code == 0 && result.returnData.listValues.length) {
  255. this.AuthArrList = [];
  256. result.returnData.listValues.forEach((item) => {
  257. item.flag = item.auth_status;
  258. item["AuthList"] = null;
  259. if (this.queryType != "all") {
  260. item["disabled"] = true;
  261. }
  262. });
  263. this.AuthArrList = _.cloneDeep(result.returnData.listValues);
  264. this.toTree();
  265. } else {
  266. this.$message.error(result.message);
  267. }
  268. },
  269. //数据转树形
  270. toTree () {
  271. this.data = [];
  272. this.dataObj = {};
  273. this.treeTitles = [];
  274. let arr = null;
  275. arr = translateDataToTreeAll(this.AuthArrList, "up_auth_id", "auth_id");
  276. let items = null;
  277. items = {
  278. auth_id: -1,
  279. auth_name: "所有权限",
  280. QueryTarget: 0,
  281. auth_status: 0,
  282. up_auth_id: -2,
  283. auth_type: 0,
  284. disabled: true,
  285. children: arr,
  286. };
  287. this.dataObj = _.cloneDeep(items);
  288. this.data = [items];
  289. let obj = null;
  290. obj = _.cloneDeep(items);
  291. let datas = null;
  292. datas = obj.children.filter((item) => item.auth_type == 1);
  293. datas.forEach((item) => {
  294. delete item.children;
  295. });
  296. delete obj.children;
  297. datas.unshift(obj);
  298. this.treeTitles = datas;
  299. if (this.$refs.tree) {
  300. this.$refs.tree.setCheckedKeys(this.checkedList);
  301. }
  302. },
  303. //数据切换
  304. upActive (item, index) {
  305. this.active = index;
  306. this.decompose([this.dataObj], item.auth_id);
  307. this.$refs.tree.setCheckedKeys(this.checkedList);
  308. },
  309. // 树节点选中
  310. currentChange () {
  311. this.checkedList = [];
  312. const datas = this.$refs.tree.getCheckedNodes();
  313. // const arr = this.$refs.tree.getCheckedNodes();
  314. // const half = this.$refs.tree.getHalfCheckedNodes();
  315. // const halfAll = half.filter(item => item.auth_id != -1 && item.auth_name != '所有权限');
  316. // const datas = halfAll.concat(arr);
  317. // if (this.treeChecks && this.treeChecks.length) {
  318. // const checks = [];
  319. // datas.forEach(item => {
  320. // checks.push(item.auth_id);
  321. // })
  322. // const handAll = [...checks, ...this.treeChecks].filter(t => {
  323. // return !(checks.includes(t) && this.treeChecks.includes(t));
  324. // })
  325. // setTimeout(() => {
  326. // handAll.map(item => {
  327. // this.$refs.tree.setChecked(item, false);
  328. // this.treeChecks = [];
  329. // })
  330. // }, 100);
  331. // }
  332. datas.forEach((item) => {
  333. // if(item.disabled==false){
  334. this.checkedList.push(item.auth_id);
  335. // }
  336. });
  337. this.setDataObj(datas);
  338. },
  339. // 选中后设置初始数据
  340. setDataObj (arr) {
  341. arr.forEach((item) => {
  342. if (!item.AuthList) {
  343. item.AuthList = {
  344. AuthId: item.auth_id,
  345. ValidBegin: "",
  346. ValidEnd: "",
  347. Action: "1",
  348. QueryRow: "",
  349. QueryCol: "",
  350. NewCol: "",
  351. EditRow: "",
  352. EditCol: "",
  353. DeleteRow: "",
  354. };
  355. }
  356. });
  357. this.$emit("getTreeData", arr);
  358. },
  359. //获取指定数据
  360. decompose (data, id) {
  361. for (let i = 0; i < data.length; i++) {
  362. if (data[i].auth_id == id) {
  363. this.data = [data[i]];
  364. } else if (data[i].children && data[i].children.length > 0) {
  365. this.decompose(data[i].children, id);
  366. }
  367. }
  368. },
  369. //获取权限规则 从新组合数据
  370. resetData () {
  371. if (this.AuthList) {
  372. this.AuthArrList.forEach((item1) => {
  373. item1["AuthList"] = null;
  374. this.AuthList.forEach((item2) => {
  375. if (item1.auth_id == item2.auth_id) {
  376. item1.AuthList = item2;
  377. }
  378. });
  379. });
  380. }
  381. this.toTree();
  382. },
  383. setUnDisabledData (data) {
  384. const ArrData = _.cloneDeep(data);
  385. this.AuthArrList.forEach((item1) => {
  386. if (this.queryType != "job") {
  387. item1.disabled = true;
  388. }
  389. ArrData.forEach((item2) => {
  390. if (item1.auth_id == item2.auth_id && item1.auth_type != 1) {
  391. item1.disabled = false;
  392. }
  393. });
  394. });
  395. this.toTree();
  396. },
  397. //获取点击目标
  398. handleNodeClick (data) {
  399. // this.toTree();
  400. const arr = this.$store.getters.authArrs;
  401. arr.push(data);
  402. const datas = _.unionBy(arr, "auth_id");
  403. const newDatas = _.cloneDeep(datas);
  404. this.$store.dispatch("auth/changeAuthMsg", newDatas);
  405. this.$store.dispatch("auth/changeAuthArrs", datas);
  406. this.$store.dispatch("auth/changeAuthId", data.auth_id);
  407. },
  408. async setDisabledAll () {
  409. this.AuthArrList.forEach(item => {
  410. item.disabled = true;
  411. })
  412. }
  413. },
  414. };
  415. </script>
  416. <style lang="scss">
  417. @import "./permissiontree.scss";
  418. </style>