123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- import { Component, OnInit, ViewChild } from '@angular/core';
- import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
- import { CompTableListComponent } from '../../../app/comp-table/comp-table-list/comp-table-list.component';
- // import _User from '../../../schemas/_User';
- import * as Parse from 'parse';
- import { CommonModule } from '@angular/common';
- import { NzPageHeaderModule } from 'ng-zorro-antd/page-header';
- import { NzBreadCrumbModule } from 'ng-zorro-antd/breadcrumb';
- import { NzSpaceModule } from 'ng-zorro-antd/space';
- import { CommonCompModule } from '../../../services/common.modules';
- // import { Profile } from '../../../schemas/Profile-list';
- import { NzEmptyModule } from 'ng-zorro-antd/empty';
- import { NzModalService } from 'ng-zorro-antd/modal';
- import { textbookServer } from '../../../services/textbook';
- import { NzMessageService } from 'ng-zorro-antd/message';
- @Component({
- selector: 'app-page-user',
- templateUrl: './page-user.component.html',
- styleUrls: ['./page-user.component.scss'],
- imports: [
- CommonModule,
- RouterOutlet,
- NzSpaceModule,
- NzPageHeaderModule,
- CompTableListComponent,
- NzBreadCrumbModule,
- CommonCompModule,
- NzEmptyModule,
- ],
- standalone: true,
- })
- export class PageUserComponent implements OnInit {
- @ViewChild(CompTableListComponent) list: CompTableListComponent | undefined;
- // _User = _User;
- // ProfileList = Profile;
- // className: string | undefined;
- // queryParams: any | undefined;
- // fieldsArray: Array<any> | undefined;
- user: Parse.User | undefined;
- profiles: Array<Parse.Object> = [];
- profileLength: number = 0; //总数据
- pageSize: number = 10;
- pageIndex: number = 1;
- checkedAll: boolean = false; //全选
- indeterminate = false;
- loading = false;
- searchValue: string = ''; //搜索内容
- setOfCheckedId = new Set<string>();
- constructor(
- public tbookSer: textbookServer,
- private modal: NzModalService,
- private route: Router,
- private message: NzMessageService,
- private activeRoute: ActivatedRoute
- ) {
- this.user = Parse.User.current();
- // this.className = this.ProfileList.className;
- // this.fieldsArray = this.ProfileList.fieldsArray;
- // this.queryParams = {
- // where: {
- // // user:this.user?.toPointer(),
- // isDeleted: { $ne: true },
- // },
- // };
- }
- ngOnInit(): void {
- this.activeRoute.paramMap.subscribe(async (params) => {
- this.getProfile();
- });
- }
- async getProfile() {
- this.profiles = [];
- this.loading = true;
- let queryParams: any = {
- where: {
- $or: [
- {
- user: {
- $inQuery: {
- where: {
- $or: [
- {
- name: { $regex: `.*${this.searchValue}.*` },
- },
- {
- username: { $regex: `.*${this.searchValue}.*` },
- },
- {
- phone: { $regex: `.*${this.searchValue}.*` },
- },
- {
- email: { $regex: `.*${this.searchValue}.*` },
- },
- ],
- },
- className: '_User',
- },
- },
- }
- ],
- },
- };
- if (
- this.tbookSer.profile.identity != '国家级管理员'
- ) {
- this.tbookSer.profile.user.department;
- queryParams['where']['$or'][0]['user']['$inQuery']['where'][
- 'department'
- ] = {
- $eq: this.tbookSer.profile.user.department?.objectId,
- };
- }
- let query = Parse.Query.fromJSON('Profile', queryParams);
- query.include('user');
- query.notEqualTo('identity', '国家级管理员');
- query.descending('createdAt')
- if(this.tbookSer.profile.identity == '工作联系人'){
- query.containedIn('identity', ['个人', '评审专家','高校联系人']);
- }else if(this.tbookSer.profile.identity == '高校联系人'){
- query.containedIn('identity', ['个人','评审专家']);
- }
- this.profileLength = await query.count();
- query.limit(this.pageSize);
- query.skip((this.pageIndex - 1) * this.pageSize);
- let r = await query.find();
- this.profiles = r;
- this.loading = false;
- }
- //分页切换
- pageIndexChange(e: any) {
- console.log(e);
- this.pageIndex = e;
- this.getProfile();
- }
- createUser() {
- this.route.navigate(['/nav-admin/manage/user/create'])
- }
- onItemChecked(id: string, e: boolean) {
- if (e) {
- this.setOfCheckedId.add(id);
- } else {
- this.setOfCheckedId.delete(id);
- }
- this.checkedAll = this.profiles.every((item) =>
- this.setOfCheckedId.has(item.id)
- );
- }
- onAllChecked(checked: boolean): void {
- this.profiles.forEach((item) => {
- if (checked) {
- this.setOfCheckedId.add(item.id);
- } else {
- this.setOfCheckedId.delete(item.id);
- }
- });
- this.checkedAll = checked;
- }
- resetChange(){
- this.setOfCheckedId = new Set<string>();
- this.checkedAll = false;
- }
- async updateUser(data: Parse.Object, type: string) {
- console.log(type);
- if(this.tbookSer.profile.identity != '国家级管理员'
- && (data?.get('identity') == '工作联系人' || data?.get('identity') == '高校联系人')
- ){
- this.message.warning('暂无权限')
- return
- }
- this.modal.confirm({
- nzTitle: '操作提示',
- nzContent: `确定${type}吗?`,
- nzOkText: '确认',
- nzOkType: 'primary',
- nzOkDanger: type == '删除' ? true : false,
- nzOnOk: async () => {
- let query = new Parse.Query('_User');
- query.equalTo('objectId', data?.get('user')?.id);
- let r = await query.first();
- if (r?.id) {
- switch (type) {
- case '通过认证':
- r?.set('accountState', '已认证');
- break;
- case '禁用':
- r?.set('accountState', '已禁用');
- break;
- case '删除':
- // r?.set('isDeleted', true);
- await data.destroy()
- await r.destroy()
- break;
- }
- await r?.save();
- }
- this.getProfile();
- },
- nzCancelText: '取消',
- nzOnCancel: () => console.log('Cancel'),
- });
- }
- deleteSelected() {
- this.modal.confirm({
- nzTitle: '批量删除',
- nzContent: `删除后数据不可恢复,请谨慎操作`,
- nzOkText: '确认',
- nzOkType: 'primary',
- nzOkDanger: true,
- nzOnOk: async () => {
- let selectedList = this.profiles.filter((item: any) =>
- this.setOfCheckedId.has(item?.id)
- );
- let deletePromiseList = selectedList.map((item: any) => {
- return new Promise((resolve) => {
- // item.set('isDeleted', true);
- // item.save();
- item.destroy().then(()=> resolve)
- });
- });
- try {
- await Promise.all(deletePromiseList);
- this.getProfile();
- } catch (err) {}
- },
- nzCancelText: '取消',
- nzOnCancel: () => console.log('Cancel'),
- });
- }
- goDateil(id: string) {
- this.route.navigate(['/nav-admin/manage/user/edit', { id: id }]);
- }
- }
|