123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { ActivatedRoute, Route, Router, RouterOutlet } from '@angular/router';
- import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
- import _Role from '../../../schemas/_Role';
- // import { TranslateService } from '@ngx-translate/core';
- import * as Parse from 'parse';
- import { CommonModule } from '@angular/common';
- import { Department } from '../../../schemas/Department';
- import { NzSpaceModule } from 'ng-zorro-antd/space';
- import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
- import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
- import { CommonCompModule } from '../../../services/common.modules';
- import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal';
- import {
- NzFormatEmitEvent,
- NzTreeModule,
- NzTreeNode,
- } from 'ng-zorro-antd/tree';
- import {
- NzContextMenuService,
- NzDropdownMenuComponent,
- } from 'ng-zorro-antd/dropdown';
- import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
- import { NzEmptyModule } from 'ng-zorro-antd/empty';
- import { NzRadioModule } from 'ng-zorro-antd/radio';
- import { NzMessageService } from 'ng-zorro-antd/message';
- interface nodes {
- title: string;
- key: string;
- isLeaf?: boolean;
- branch?: string;
- children?: Array<any>;
- }
- interface depart {
- name: string;
- id?: string;
- code?: string;
- desc?: string;
- parent?: object | any;
- branch: string;
- }
- @Component({
- selector: 'app-page-role',
- templateUrl: './page-role.component.html',
- styleUrls: ['./page-role.component.scss'],
- imports: [
- CommonModule,
- CommonCompModule,
- RouterOutlet,
- CompTableListComponent,
- NzSpaceModule,
- NzPageHeaderModule,
- NzBreadCrumbModule,
- NzTreeModule,
- NzCheckboxModule,
- NzEmptyModule,
- NzModalModule,
- NzRadioModule,
- ],
- standalone: true,
- })
- export class PageRoleComponent implements OnInit {
- @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
- // _Role = _Role
- Department = Department;
- user: Parse.User | undefined;
- className: string | undefined;
- queryParams: any | undefined;
- fieldsArray: Array<any> | undefined;
- searchValue: string = ''; //搜索内容
- searchValueNode: string = '';
- nodes: Array<nodes | any> = [];
- currentDepart: nodes | any = null;
- profiles: Array<any> = [];
- checkedShowFilter: boolean = false;
- checkedAll: boolean = false; //全选
- indeterminate = false;
- loading = false;
- isVisible: boolean = false;
- activatedNode: NzTreeNode | any; //当前选择节点
- editType: string = 'add'; //弹窗类型
- activeDepart?: Parse.Object; //当前编辑部门
- editObject: depart = {
- name: '',
- code: '',
- desc: '',
- parent: {},
- branch: '',
- };
- parentMap: Array<any> = [];
- parentList: Array<any> = [];
- radio: string = '';
- /* 添加账号 */
- accountIsVisible: boolean = false;
- account: any = {
- name: '',
- phone: '',
- email: '',
- password: '',
- identity: '',
- department: '',
- companyType: '',
- };
- constructor(
- private route: Router,
- private activeRoute: ActivatedRoute,
- private nzContextMenuService: NzContextMenuService,
- private modal: NzModalService,
- private message: NzMessageService
- ) {
- this.user = Parse.User.current();
- this.className = this.Department.className;
- this.fieldsArray = this.Department.fieldsArray;
- this.queryParams = {
- where: {
- // user:this.user?.toPointer(),
- isDeleted: { $ne: true },
- },
- };
- }
- ngOnInit(): void {
- this.activeRoute.paramMap.subscribe(async (params) => {
- // let isDeleted = params.get('isDeleted');
- // if (isDeleted) {
- // this.queryParams.where['isDeleted'] = { $eq: true };
- // } else {
- // this.queryParams.where['isDeleted'] = { $ne: true };
- // }
- // this.list?.ngOnInit();
- this.nodes = await this.getDepart();
- });
- }
- async getDepart(
- parent?: string,
- searchValue?: string,
- filter?: boolean
- ): Promise<Array<nodes>> {
- let nodes: any = [];
- let query = new Parse.Query('Department');
- if (!filter) {
- query.equalTo('parent', parent ? parent : undefined);
- }
- searchValue && query.contains('name', searchValue);
- query.notEqualTo('isDeleted', true);
- query.select('code', 'name', 'branch', 'parent', 'type');
- query.descending('createdAt');
- query.limit(2000);
- if (this.activeDepart) query.notEqualTo('objectId', this.activeDepart?.id);
- let res = await query.find();
- res.forEach((item) => {
- nodes.push({
- title: item.get('name'),
- key: item.id,
- children: [],
- branch: item.get('branch'),
- isLeaf: item.get('type') == '单位' ? true : false, //是否是最下级
- });
- });
- return nodes;
- }
- //搜索
- async onSearchNodes(e: string, modal?: boolean) {
- if (modal) {
- this.parentList = await this.getDepart('', e, true);
- return;
- }
- this.nodes = await this.getDepart('', e, e ? true : false);
- }
- //添加成员
- addMember() {
- // this.message.warning('权限灰度中')
- this.account = {
- name: '',
- phone: '',
- email: '',
- password: '',
- identity: '',
- department: '',
- companyType: '',
- };
- this.accountIsVisible = true;
- }
- //展开/合并
- async nzEvent(event: NzFormatEmitEvent): Promise<void> {
- console.log(event);
- let node: any = event.node;
- if (event.eventName === 'expand') {
- // if (node.origin.isParent) {
- // node.addChildren([]);
- // return;
- // }
- if (node?._children.length <= 0) {
- let data = await this.getDepart(node.key);
- node.addChildren(data);
- }
- console.log(this.nodes);
- } else {
- // if (node.origin.isParent) {
- this.currentDepart = node.origin;
- this.getProfile();
- // }
- }
- }
- async getProfile() {
- this.profiles = [];
- this.loading = true;
- let queryParams = {
- where: {
- $or: [
- {
- user: {
- $inQuery: {
- where: {
- $or: [
- {
- department: { $eq: this.currentDepart.key },
- },
- ],
- },
- className: '_User',
- },
- },
- },
- ],
- },
- };
- let query = Parse.Query.fromJSON('Profile', queryParams);
- query.include('user');
- query.notEqualTo('identity', '国家级管理员');
- query.notEqualTo('isDeleted', true);
- let r = await query.find();
- let profiles: any[] = [];
- r.forEach((item) => {
- let _item = item.toJSON();
- _item['checked'] = false;
- profiles.push(_item);
- });
- this.profiles = profiles;
- this.loading = false;
- }
- //搜索触发
- onSearch(event: NzFormatEmitEvent) {
- console.log(event);
- }
- contextMenu(
- $event: MouseEvent,
- menu: NzDropdownMenuComponent,
- node?: any
- ): void {
- console.log(node);
- this.activatedNode = node;
- this.nzContextMenuService.create($event, menu);
- }
- //删除部门
- async onDelDepart() {
- this.modal.confirm({
- nzTitle: '删除',
- nzContent:'删除后数据不可恢复,请谨慎操作',
- nzOkText: '确认',
- nzOkType: 'primary',
- nzOkDanger: true,
- nzOnOk: async () => {
- new Promise(async(resolve, reject) => {
- if(this.activatedNode){
- let query = new Parse.Query('Department');
- let r = await query.get(this.activatedNode?.key);
- if(r?.id){
- r.set('isDeleted',true)
- await r.save()
- }
- this.message.success('删除成功')
- this.nodes = await this.getDepart();
- resolve(true)
- }
- }).catch(() => console.log('Oops errors!'))
- },
- nzCancelText: '取消',
- nzOnCancel: () => console.log('Cancel'),
- });
- }
- onAllChecked(checked: boolean): void {
- console.log(checked);
- this.profiles = this.profiles.map((item) => {
- item.checked = checked;
- return item;
- });
- this.checkedAll = checked;
- }
- onItemChecked(id: string, e: boolean) {
- let checkedAll = true;
- this.profiles = this.profiles.map((item) => {
- if (id == item.objectId) item.checked = e;
- if (!item.checked) checkedAll = false;
- return item;
- });
- this.checkedAll = checkedAll;
- }
- //新建打开弹窗
- async showModalDepart(type: string) {
- this.parentList = this.nodes;
- this.editObject = {
- name: '',
- code: '',
- desc: '',
- parent: '',
- branch: '',
- };
- if (type == 'edit') {
- let query = new Parse.Query('Department');
- let r = await query.get(this.activatedNode?.key);
- this.activeDepart = r;
- this.editObject = {
- name: this.activeDepart.get('name'),
- code: this.activeDepart.get('code'),
- desc: this.activeDepart.get('desc'),
- parent: {
- title: this.activeDepart.get('parent')?.get('name'),
- id: this.activeDepart.get('parent')?.id,
- },
- branch: this.activeDepart.get('branch'),
- };
- this.parentMap = await this.formatNode(this.activeDepart.get('parent')?.id);
- if (this.activatedNode?.parentNode?.origin?.parentNode?.origin.key) {
- this.parentList = await this.getDepart(
- this.activatedNode?.parentNode?.origin?.parentNode?.origin.key
- );
- }
- }else if(type == 'add' && this.activatedNode){
- console.log(this.activatedNode);
- this.editObject.parent = {
- title: this.activatedNode.origin.title,
- id: this.activatedNode.origin.key,
- };
- this.editObject.branch = this.activatedNode.origin.branch || this.activatedNode.origin.title
- this.parentMap = await this.formatNode(this.activatedNode.origin.key);
- if (this.activatedNode?.parentNode?.origin.key) {
- this.parentList = await this.getDepart(
- this.activatedNode.parentNode.origin.key
- );
- }
- }
- console.log(this.parentMap);
- this.editType = type;
- this.isVisible = true;
- }
- //格式化链
- async formatNode(id: string): Promise<Array<any>> {
- let query = new Parse.Query('Department');
- query.select('name', 'parent');
- let r = await query.get(id);
- let arr = [
- {
- title: r.get('name'),
- key: r.id,
- },
- ];
- if (r?.get('parent')) {
- arr.unshift(...(await this.formatNode(r?.get('parent').id)));
- }
- return arr;
- }
- async onPre(data?: any, index?: number) {
- if (!data) {
- this.parentList = await this.getDepart();
- this.parentMap = [];
- return;
- }
- if (index == this.parentMap.length - 1) return;
- this.parentMap.splice(index || 0 + 1);
- this.parentList = await this.getDepart(data?.key);
- }
- //选择所属类别下级列表
- async onCheckedDepart(e: any, checked?: boolean) {
- this.radio = e.key;
- console.log(this.radio);
- this.parentMap = await this.formatNode(e.key);
- if (checked) {
- // this.editObject.name = e.title
- this.editObject.parent = {
- title: e.title,
- id: e.key,
- };
- this.editObject.branch = e.branch || e.title;
- return;
- }
- if (e.isLeaf) {
- return;
- }
- this.parentMap.push({
- title: e.title,
- key: e.key,
- });
- this.parentList = await this.getDepart(e?.key);
- }
- async handleOk():Promise<void> {
- if(!this.editObject?.name || !this.editObject.parent?.id){
- this.message.error('请填写完整信息')
- return
- }
- if(this.activeDepart?.id && this.editType == 'edit'){
- this.activeDepart.set('name',this.editObject?.name)
- this.activeDepart.set('code',this.editObject?.code)
- this.activeDepart.set('desc',this.editObject.desc)
- this.activeDepart.set('parent',{
- __type: 'Pointer',
- className: 'Department',
- objectId: this.editObject.parent?.id,
- })
- this.activeDepart.set('branch',this.editObject.branch)
- }else{
- let obj = Parse.Object.extend('Department')
- this.activeDepart = new obj()
- this.activeDepart?.set('name',this.editObject?.name)
- this.activeDepart?.set('code',this.editObject?.code)
- this.activeDepart?.set('desc',this.editObject.desc)
- this.activeDepart?.set('parent',{
- __type: 'Pointer',
- className: 'Department',
- objectId: this.editObject.parent?.id,
- })
- this.activeDepart?.set('branch',this.editObject.branch)
- }
- await this.activeDepart?.save()
- this.isVisible = false;
- this.message.success(this.editType == 'edit' ? '保存' : '添加' + '成功')
- this.activeDepart = undefined
- this.nodes = await this.getDepart();
- }
- handleCancel(): void {
- console.log('Button cancel clicked!');
- this.isVisible = false;
- this.activatedNode = undefined;
- this.parentMap = [];
- this.accountIsVisible = false;
- this.account = null;
- }
- /* 组织 */
- showModalOrganize() {
- this.message.warning('权限灰度中');
- }
- goDateil(id: string) {
- this.route.navigate(['/nav-admin/manage/user/edit', { id: id }]);
- }
- }
|