page-role.component.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute, RouterOutlet } from '@angular/router';
  3. import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
  4. import _Role from '../../../schemas/_Role';
  5. // import { TranslateService } from '@ngx-translate/core';
  6. import * as Parse from 'parse';
  7. import { CommonModule } from '@angular/common';
  8. import { Department } from '../../../schemas/Department';
  9. import { NzSpaceModule } from 'ng-zorro-antd/space';
  10. import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
  11. import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
  12. import { CommonCompModule } from '../../../services/common.modules';
  13. import { NzModalModule } from 'ng-zorro-antd/modal';
  14. import {
  15. NzFormatEmitEvent,
  16. NzTreeModule,
  17. NzTreeNode,
  18. } from 'ng-zorro-antd/tree';
  19. import {
  20. NzContextMenuService,
  21. NzDropdownMenuComponent,
  22. } from 'ng-zorro-antd/dropdown';
  23. import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
  24. import { NzEmptyModule } from 'ng-zorro-antd/empty';
  25. import { NzRadioModule } from 'ng-zorro-antd/radio';
  26. import { NzMessageService } from 'ng-zorro-antd/message';
  27. interface nodes {
  28. title: string;
  29. key: string;
  30. isLeaf?: boolean;
  31. isParent?: boolean;
  32. children?: Array<any>;
  33. }
  34. interface depart {
  35. name: string;
  36. id?: string;
  37. code?: string;
  38. desc?: string;
  39. parent?: object | any;
  40. branch: string;
  41. }
  42. @Component({
  43. selector: 'app-page-role',
  44. templateUrl: './page-role.component.html',
  45. styleUrls: ['./page-role.component.scss'],
  46. imports: [
  47. CommonModule,
  48. CommonCompModule,
  49. RouterOutlet,
  50. CompTableListComponent,
  51. NzSpaceModule,
  52. NzPageHeaderModule,
  53. NzBreadCrumbModule,
  54. NzTreeModule,
  55. NzCheckboxModule,
  56. NzEmptyModule,
  57. NzModalModule,
  58. NzRadioModule,
  59. ],
  60. standalone: true,
  61. })
  62. export class PageRoleComponent implements OnInit {
  63. @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
  64. // _Role = _Role
  65. Department = Department;
  66. user: Parse.User | undefined;
  67. className: string | undefined;
  68. queryParams: any | undefined;
  69. fieldsArray: Array<any> | undefined;
  70. searchValue: string = ''; //搜索内容
  71. nodes: Array<nodes | any> = [];
  72. currentDepart: nodes | any = null;
  73. profiles: Array<any> = [];
  74. checkedShowFilter: boolean = false;
  75. checkedAll: boolean = false; //全选
  76. indeterminate = false;
  77. loading = false;
  78. isVisible: boolean = false;
  79. activatedNode: NzTreeNode | any; //当前选择节点
  80. editType: string = 'add'; //弹窗类型
  81. activeDepart?: Parse.Object; //当前编辑部门
  82. editObject: depart = {
  83. name: '',
  84. code: '',
  85. desc: '',
  86. parent: {},
  87. branch: '',
  88. };
  89. parentMap: Array<any> = [];
  90. parentList: Array<any> = [];
  91. constructor(
  92. private route: ActivatedRoute,
  93. private activeRoute: ActivatedRoute,
  94. private nzContextMenuService: NzContextMenuService,
  95. private message: NzMessageService,
  96. ) {
  97. this.user = Parse.User.current();
  98. this.className = this.Department.className;
  99. this.fieldsArray = this.Department.fieldsArray;
  100. this.queryParams = {
  101. where: {
  102. // user:this.user?.toPointer(),
  103. isDeleted: { $ne: true },
  104. },
  105. };
  106. }
  107. ngOnInit(): void {
  108. this.activeRoute.paramMap.subscribe(async (params) => {
  109. // let isDeleted = params.get('isDeleted');
  110. // if (isDeleted) {
  111. // this.queryParams.where['isDeleted'] = { $eq: true };
  112. // } else {
  113. // this.queryParams.where['isDeleted'] = { $ne: true };
  114. // }
  115. // this.list?.ngOnInit();
  116. this.nodes = await this.getDepart();
  117. });
  118. }
  119. async getDepart(
  120. parent?: string,
  121. searchValue?: string
  122. ): Promise<Array<nodes>> {
  123. let nodes: any = [];
  124. let query = new Parse.Query('Department');
  125. query.equalTo('parent', parent ? parent : undefined);
  126. searchValue && query.contains('name', searchValue);
  127. query.notEqualTo('isDeleted', true);
  128. query.select('code', 'name', 'branch', 'parent','type');
  129. query.descending('createdAt');
  130. query.limit(2000);
  131. let res = await query.find();
  132. res.forEach((item) => {
  133. nodes.push({
  134. title: item.get('name'),
  135. key: item.id,
  136. children: [],
  137. isParent: item.get('type') =='单位' ? true : false, //是否是最下级
  138. isLeaf: false,
  139. });
  140. });
  141. return nodes;
  142. }
  143. //添加成员
  144. addMember() {
  145. this.message.warning('权限灰度中')
  146. }
  147. //展开/合并
  148. async nzEvent(event: NzFormatEmitEvent): Promise<void> {
  149. console.log(event);
  150. let node: any = event.node;
  151. if (event.eventName === 'expand') {
  152. if (node.origin.isParent) {
  153. node.addChildren([]);
  154. return;
  155. }
  156. if (node?._children.length <= 0) {
  157. let data = await this.getDepart(node.key);
  158. node.addChildren(data);
  159. }
  160. console.log(this.nodes);
  161. } else {
  162. if (node.origin.isParent) {
  163. this.currentDepart = node.origin;
  164. this.getProfile();
  165. }
  166. }
  167. }
  168. async getProfile() {
  169. this.profiles = [];
  170. this.loading = true;
  171. let queryParams = {
  172. where : {
  173. "$or": [{
  174. "user": {
  175. "$inQuery": {
  176. "where": {
  177. "$or": [{
  178. "companyName": { "$eq": this.currentDepart.title}
  179. },
  180. ]
  181. },
  182. "className": "_User"
  183. }
  184. }
  185. }]
  186. }
  187. }
  188. let query = Parse.Query.fromJSON('Profile',queryParams);
  189. query.include('user');
  190. query.notEqualTo('identity', '国家级管理员');
  191. let r = await query.find();
  192. let profiles: any[] = [];
  193. r.forEach((item) => {
  194. let _item = item.toJSON();
  195. _item['checked'] = false;
  196. profiles.push(_item);
  197. });
  198. this.profiles = profiles;
  199. this.loading = false;
  200. }
  201. //搜索触发
  202. onSearch(event: NzFormatEmitEvent) {
  203. console.log(event);
  204. }
  205. contextMenu(
  206. $event: MouseEvent,
  207. menu: NzDropdownMenuComponent,
  208. node?: any
  209. ): void {
  210. console.log(node);
  211. this.activatedNode = node;
  212. this.nzContextMenuService.create($event, menu);
  213. }
  214. //删除部门
  215. onDelDepart() {
  216. this.message.warning('权限灰度中')
  217. }
  218. onAllChecked(checked: boolean): void {
  219. console.log(checked);
  220. this.profiles = this.profiles.map((item) => {
  221. item.checked = checked;
  222. return item;
  223. });
  224. this.checkedAll = checked;
  225. }
  226. onItemChecked(id: string, e: boolean) {
  227. let checkedAll = true;
  228. this.profiles = this.profiles.map((item) => {
  229. if (id == item.objectId) item.checked = e;
  230. if (!item.checked) checkedAll = false;
  231. return item;
  232. });
  233. this.checkedAll = checkedAll;
  234. }
  235. //新建打开弹窗
  236. async showModalDepart(type: string) {
  237. this.parentList = this.nodes;
  238. if (type == 'edit') {
  239. let query = new Parse.Query('Department');
  240. let r = await query.get(this.activatedNode?.key);
  241. this.activeDepart = r;
  242. this.parentMap = this.formatNode(this.activatedNode);
  243. if(this.activatedNode?.parentNode?.origin.key){
  244. this.parentList = await this.getDepart(this.activatedNode.parentNode.origin.key);
  245. }
  246. }
  247. this.editType = type;
  248. this.isVisible = true;
  249. }
  250. //格式化链
  251. formatNode(node: NzTreeNode): Array<any> {
  252. let arr = [];
  253. if (node.parentNode?.origin.title) {
  254. arr.push({
  255. title: node.parentNode?.origin.title,
  256. key: node.parentNode?.origin.key,
  257. });
  258. arr.unshift(...this.formatNode(node.parentNode));
  259. }
  260. return arr;
  261. }
  262. async onPre(data?:any,index?:number){
  263. if(!data){
  264. this.parentList = await this.getDepart();
  265. this.parentMap = []
  266. return
  267. }
  268. if(index == this.parentMap.length-1) return
  269. this.parentMap.splice(index || 0+1)
  270. this.parentList = await this.getDepart(data?.key);
  271. }
  272. //选择所属类别下级列表
  273. async onCheckedDepart(e: any, checked?: boolean) {
  274. console.log(e);
  275. if (checked) {
  276. this.editObject = {
  277. name: e.title,
  278. code: '',
  279. desc: '',
  280. parent: e,
  281. branch: '',
  282. };
  283. return;
  284. }
  285. this.parentMap.push({
  286. title: e.title,
  287. key: e.key,
  288. });
  289. this.parentList = await this.getDepart(e?.key);
  290. }
  291. handleOk(): void {
  292. this.message.warning('权限灰度中')
  293. this.isVisible = false;
  294. }
  295. handleCancel(): void {
  296. console.log('Button cancel clicked!');
  297. this.isVisible = false;
  298. this.activatedNode = undefined;
  299. this.parentMap = [];
  300. }
  301. /* 组织 */
  302. showModalOrganize(){
  303. this.message.warning('权限灰度中')
  304. }
  305. }