index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="bf-permissiontree">
  3. <!-- 权限树 -->
  4. <div class="cont">
  5. <div class="paren_header">
  6. <p class="manageTitle">{{ 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 class="icon-gz">
  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.edit_col_condition || data.edit_col_condition ||
  54. data.AuthList.delete_row_condition || data.delete_row_condition ||
  55. data.AuthList.edit_row_condition || data.edit_row_condition ||
  56. data.AuthList.new_col_condition || data.new_col_condition ||
  57. data.AuthList.query_col_conditon || data.query_col_conditon ||
  58. data.AuthList.query_row_condition || data.query_row_condition)
  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. setTimeout(() => {
  139. this.AuthList = val;
  140. this.resetData();
  141. if (this.$store.getters.authId) {
  142. this.defaultExpandedKeys = [this.$store.getters.authId]
  143. }
  144. }, 150);
  145. } else {
  146. this.getAuthList();
  147. }
  148. },
  149. immediate: true,
  150. deep: true,
  151. },
  152. queryId: {
  153. handler (val) {
  154. if (this.queryType == "job") {
  155. this.setDisabledAll();
  156. let ids = val.split(",");
  157. this.queryIdArr = [];
  158. this.$refs.tree.setCheckedKeys([]);
  159. if (this.isMainJob == true) {
  160. this.MainJobId = val;
  161. }
  162. if (this.MainJobId != "") {
  163. this.queryIdArr.push(this.MainJobId);
  164. }
  165. for (let i = 0; i < ids.length; i++) {
  166. if (_.indexOf(this.queryIdArr, ids[i]) == -1) {
  167. this.queryIdArr.push(ids[i]);
  168. }
  169. }
  170. for (let j = 0; j < this.queryIdArr.length; j++) {
  171. this.searchId = this.queryIdArr[j];
  172. this.getDefaultDataList();
  173. }
  174. } else {
  175. this.searchId = val;
  176. this.getDefaultDataList();
  177. }
  178. },
  179. deep: true,
  180. },
  181. queryIds: {
  182. handler () {
  183. this.getDefaultDataList()
  184. },
  185. deep: true
  186. },
  187. treeChecks: {
  188. handler (val) {
  189. if (val && val.length) {
  190. this.$refs.tree.setCheckedKeys(val);
  191. }
  192. },
  193. deep: true
  194. }
  195. },
  196. created () {
  197. this.getDataList();
  198. this.searchId = this.queryId;
  199. },
  200. methods: {
  201. getAuthList () {
  202. let arr = [];
  203. setTimeout(() => {
  204. arr = this.$store.getters.authList;
  205. if (arr && arr.length) {
  206. this.AuthList = arr;
  207. this.resetData();
  208. if (this.$store.getters.authId) {
  209. this.defaultExpandedKeys = [this.$store.getters.authId]
  210. }
  211. } else {
  212. this.getAuthList();
  213. }
  214. }, 100);
  215. },
  216. //获取权限列表
  217. getDataList () {
  218. Query({
  219. id: DATACONTENT_ID.authTreeId,
  220. dataContent: ['']
  221. }).then((result) => {
  222. // this.getDefaultDataList();
  223. this.setUnDisabledData(result.returnData.listValues);
  224. this.setData(result);
  225. });
  226. },
  227. async getDefaultDataList () {
  228. if (this.queryType == "all" && this.searchId != "") {
  229. //获取全部权限树
  230. Query({
  231. id: DATACONTENT_ID.authTreeId,
  232. dataContent: ['']
  233. }).then((result) => {
  234. this.setUnDisabledData(result.returnData.listValues);
  235. });
  236. } else if (this.queryType == "job") {
  237. //根据岗位获取权限树
  238. postUptree({ JobId: this.searchId }).then((result) => {
  239. this.setUnDisabledData(result.returnData.listValues);
  240. });
  241. } else if (this.queryType == "origin") {
  242. //根据组织获取权限树
  243. this.AuthList = [];
  244. this.$refs.tree.setCheckedKeys([])
  245. organizationUptree({ OrganId: this.searchId }).then((result) => {
  246. this.setUnDisabledData(result.returnData.listValues);
  247. });
  248. } else if (this.queryType == "group") {
  249. //根据帐号组获取权限树
  250. if (this.searchId) {
  251. GetAuthTreeByGroup({ GroupIds: [this.searchId] }).then((result) => {
  252. this.setUnDisabledData(result.returnData.listValues);
  253. });
  254. } else if (this.queryIds.length && this.queryIds[0] !== -1) {
  255. GetAuthTreeByGroup({ GroupIds: this.queryIds }).then((result) => {
  256. this.setUnDisabledData(result.returnData.listValues)
  257. })
  258. }
  259. }
  260. },
  261. setData (result) {
  262. if (result.code == 0 && result.returnData.listValues.length) {
  263. this.AuthArrList = [];
  264. result.returnData.listValues.forEach((item) => {
  265. item.flag = item.auth_status;
  266. item["AuthList"] = null;
  267. if (this.queryType != "all") {
  268. item["disabled"] = true;
  269. }
  270. });
  271. this.AuthArrList = _.cloneDeep(result.returnData.listValues);
  272. this.toTree();
  273. } else {
  274. this.$message.error(result.message);
  275. }
  276. },
  277. //数据转树形
  278. toTree () {
  279. this.data = [];
  280. const arr = translateDataToTreeAll(
  281. this.AuthArrList,
  282. "up_auth_id",
  283. "auth_id"
  284. )
  285. const items = {
  286. auth_id: -1,
  287. auth_name: "所有权限",
  288. auth_status: 0,
  289. up_auth_id: -2,
  290. auth_type: 0,
  291. children: arr,
  292. };
  293. this.data = [items]
  294. },
  295. //数据切换
  296. upActive (item, index) {
  297. this.active = index;
  298. this.decompose([this.dataObj], item.auth_id);
  299. this.$refs.tree.setCheckedKeys(this.checkedList);
  300. },
  301. // 树节点选中
  302. currentChange () {
  303. this.checkedList = [];
  304. const datas = this.$refs.tree.getCheckedNodes();
  305. // const arr = this.$refs.tree.getCheckedNodes();
  306. // const half = this.$refs.tree.getHalfCheckedNodes();
  307. // const halfAll = half.filter(item => item.auth_id != -1 && item.auth_name != '所有权限');
  308. // const datas = halfAll.concat(arr);
  309. // if (this.treeChecks && this.treeChecks.length) {
  310. // const checks = [];
  311. // datas.forEach(item => {
  312. // checks.push(item.auth_id);
  313. // })
  314. // const handAll = [...checks, ...this.treeChecks].filter(t => {
  315. // return !(checks.includes(t) && this.treeChecks.includes(t));
  316. // })
  317. // setTimeout(() => {
  318. // handAll.map(item => {
  319. // this.$refs.tree.setChecked(item, false);
  320. // this.treeChecks = [];
  321. // })
  322. // }, 100);
  323. // }
  324. datas.forEach((item) => {
  325. // if(item.disabled==false){
  326. this.checkedList.push(item.auth_id);
  327. // }
  328. });
  329. this.setDataObj(datas);
  330. },
  331. // 选中后设置初始数据
  332. setDataObj (arr) {
  333. arr.forEach((item) => {
  334. if (!item.AuthList) {
  335. item.AuthList = {
  336. query_row_condition: "",
  337. query_col_conditon: "",
  338. delete_row_condition: "",
  339. new_col_condition: "",
  340. edit_row_condition: "",
  341. edit_col_condition: ""
  342. };
  343. }
  344. });
  345. this.$emit("getTreeData", arr);
  346. },
  347. //获取指定数据
  348. decompose (data, id) {
  349. for (let i = 0; i < data.length; i++) {
  350. if (data[i].auth_id == id) {
  351. this.data = [data[i]];
  352. } else if (data[i].children && data[i].children.length > 0) {
  353. this.decompose(data[i].children, id);
  354. }
  355. }
  356. },
  357. //获取权限规则 从新组合数据
  358. resetData () {
  359. if (this.AuthList) {
  360. this.AuthArrList.forEach((item1) => {
  361. item1["AuthList"] = null;
  362. this.AuthList.forEach((item2) => {
  363. if (item1.auth_id == item2.auth_id) {
  364. item1.AuthList = item2;
  365. }
  366. });
  367. });
  368. }
  369. this.toTree();
  370. },
  371. setUnDisabledData (data) {
  372. const ArrData = _.cloneDeep(data);
  373. this.AuthArrList.forEach((item1) => {
  374. if (this.queryType != "job") {
  375. item1.disabled = true;
  376. }
  377. ArrData.forEach((item2) => {
  378. if (item1.auth_id == item2.auth_id && item1.auth_type != 1) {
  379. item1.disabled = false;
  380. }
  381. });
  382. });
  383. this.toTree();
  384. },
  385. //获取点击目标
  386. handleNodeClick (data) {
  387. // this.toTree();
  388. const arr = this.$store.getters.authArrs;
  389. arr.push(data);
  390. const datas = _.unionBy(arr, "auth_id");
  391. const newDatas = _.cloneDeep(datas);
  392. this.$store.dispatch("auth/changeAuthMsg", newDatas);
  393. this.$store.dispatch("auth/changeAuthArrs", datas);
  394. this.$store.dispatch("auth/changeAuthId", data.auth_id);
  395. },
  396. async setDisabledAll () {
  397. this.AuthArrList.forEach(item => {
  398. item.disabled = true;
  399. })
  400. }
  401. },
  402. };
  403. </script>
  404. <style lang="scss">
  405. @import "./permissiontree.scss";
  406. </style>