user-edit.component.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import { Component, Input, OnInit } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { NzSpaceModule } from 'ng-zorro-antd/space';
  4. import { CommonCompModule } from '../../../services/common.modules';
  5. import { NzTabsModule } from 'ng-zorro-antd/tabs';
  6. import { ActivatedRoute, Router } from '@angular/router';
  7. import { NzAvatarModule } from 'ng-zorro-antd/avatar';
  8. import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
  9. import { NzPopoverModule } from 'ng-zorro-antd/popover';
  10. import { NzTagModule } from 'ng-zorro-antd/tag';
  11. import { NzModalModule } from 'ng-zorro-antd/modal';
  12. import { NzMessageService } from 'ng-zorro-antd/message';
  13. import { textbookServer } from '../../../services/textbook';
  14. import { NzRadioModule } from 'ng-zorro-antd/radio';
  15. import Parse from 'parse';
  16. import { NzImageService } from 'ng-zorro-antd/image';
  17. import { NzImageModule } from 'ng-zorro-antd/image';
  18. import { NzSelectModule } from 'ng-zorro-antd/select';
  19. import { MatButtonModule } from '@angular/material/button';
  20. import { provinces } from '../../../services/provinces';
  21. @Component({
  22. selector: 'app-user-edit',
  23. templateUrl: './user-edit.component.html',
  24. styleUrls: ['./user-edit.component.scss'],
  25. imports: [
  26. CommonModule,
  27. NzSpaceModule,
  28. CommonCompModule,
  29. NzTabsModule,
  30. NzAvatarModule,
  31. NzDropDownModule,
  32. NzPopoverModule,
  33. NzTagModule,
  34. NzModalModule,
  35. NzRadioModule,
  36. NzImageModule,
  37. NzSelectModule,MatButtonModule
  38. ],
  39. standalone: true,
  40. })
  41. export class UserEditComponent implements OnInit {
  42. inputValue: string = `
  43. async function pipe(user, context, callback) {
  44. if (context.connection === "weibo") {
  45. return callback(new Error("当前系统禁止使用微博登录!"))
  46. }
  47. callback(null, user, context)
  48. }`;
  49. isVisible: boolean = false;
  50. user: Parse.Object | any;
  51. profile: Parse.Object | any;
  52. password: string = '';
  53. edit: boolean = false; //编辑权限
  54. //可编辑
  55. userDataJson: any = {
  56. companyType: '',
  57. department: null,
  58. };
  59. parentMap: Array<any> = [];
  60. parentList: Array<any> = []; //单位列表
  61. isShowModal: boolean = false;
  62. searchValue: string = ''; //搜索部门内容
  63. unitTypes: Array<any> = [];
  64. userJson: any = { //user编辑数据
  65. email:'',
  66. phone:'',
  67. name:'',
  68. username:'',
  69. }
  70. profileJson: any = { //身份编辑数据
  71. identity:'',
  72. telephone:'',
  73. province:'',
  74. departmentName:'',
  75. postName:'',
  76. majorSubject:''
  77. }
  78. userType: Array<string> = ['教师', '评审专家', '高校联系人', '工作联系人'];
  79. provinces: Array<string> = provinces.options; //省份
  80. constructor(
  81. public tbookSer: textbookServer,
  82. private activeRoute: ActivatedRoute,
  83. private router: Router,
  84. private message: NzMessageService,
  85. private nzImageService: NzImageService
  86. ) {}
  87. ngOnInit() {
  88. this.activeRoute.paramMap.subscribe(async (params) => {
  89. let id = params.get('id');
  90. console.log(id);
  91. if (id) {
  92. let query = new Parse.Query('_User');
  93. query.include('department');
  94. this.user = await query.get(id);
  95. this.userJson = this.user.toJSON();
  96. let queryProfile = new Parse.Query('Profile');
  97. queryProfile.equalTo('user', id);
  98. this.profile = await queryProfile.first();
  99. this.profileJson = this.profile.toJSON();
  100. this.userDataJson = {
  101. companyType: this.profile?.get('companyType'),
  102. department: this.user.get('department'),
  103. };
  104. }
  105. await this.getUnitTypes();
  106. let arr = ['教师', '评审专家', '高校联系人'];
  107. if (this.tbookSer.profile.identity == '国家级管理员') {
  108. this.edit = true;
  109. } else if (this.tbookSer.profile.identity == '工作联系人' && arr.includes(this.profile.get('identity'))
  110. ) {
  111. this.userType = ['教师', '评审专家', '工作联系人'];
  112. this.edit = true;
  113. } else if (
  114. this.tbookSer.profile.identity == '高校联系人' &&
  115. this.profile.get('identity') == '教师'
  116. ) {
  117. this.userType = ['教师'];
  118. this.edit = true;
  119. }
  120. });
  121. }
  122. async updateUser(type: string) {
  123. console.log(type);
  124. if (!this.edit) {
  125. this.message.warning('同级身份暂无权限操作');
  126. return;
  127. }
  128. switch (type) {
  129. case '已认证':
  130. this.user.set('accountState', '已认证');
  131. Parse.Cloud.run('aliSmsSend', {
  132. mobileList: [this.user?.get('phone')],
  133. templateCode: 'SMS_468870790',
  134. params: {},
  135. signName: '普通高等教育教材网',
  136. });
  137. break;
  138. case '已禁用':
  139. this.user.set('accountState', '已禁用');
  140. break;
  141. case '删除':
  142. this.user.set('isDeleted', true);
  143. break;
  144. }
  145. await this.user.save();
  146. this.ngOnInit();
  147. }
  148. async handleOk() {
  149. if (!this.edit) {
  150. this.message.warning('同级身份暂无权限操作');
  151. return;
  152. }
  153. this.password = this.password.trim();
  154. if (!this.password) {
  155. this.message.warning('密码格式错误');
  156. return;
  157. }
  158. try {
  159. this.user.set('password', this.password);
  160. await this.user.save();
  161. this.ngOnInit();
  162. } catch (err) {
  163. this.message.warning('保存出错,请注意密码格式');
  164. }
  165. this.isVisible = false;
  166. }
  167. //切换单位类型
  168. onChangeType(){
  169. this.userDataJson.department = null
  170. }
  171. //选择部门
  172. async showModalDepart() {
  173. if (!this.edit) {
  174. this.message.warning('同级身份暂无权限操作');
  175. return;
  176. }
  177. if (this.unitTypes.length == 0) {
  178. await this.getUnitTypes();
  179. }
  180. let parent = this.unitTypes.find(
  181. (item) => item.name == this.userDataJson.companyType
  182. );
  183. if (parent?.id) {
  184. this.parentMap = await this.formatNode(parent.id);
  185. }
  186. this.provinceChange(this.parentMap[this.parentMap.length - 1]?.id);
  187. this.isShowModal = true;
  188. }
  189. async getUnitTypes() {
  190. let query = new Parse.Query('Department');
  191. query.equalTo('branch', undefined);
  192. query.equalTo('parent', undefined);
  193. query.notEqualTo('isDeleted', true);
  194. query.select('name');
  195. let r = await query.find();
  196. r.forEach((item) => {
  197. this.unitTypes.push({ id: item.id, name: item.get('name') });
  198. });
  199. }
  200. //根据所选单位类型获取对应单位
  201. async provinceChange(id?: string, val?: string) {
  202. let query = new Parse.Query('Department');
  203. query.select('name', 'branch', 'parent');
  204. if (this.tbookSer.profile.identity != '国家级管理员') {
  205. query.equalTo(
  206. 'objectId',
  207. this.tbookSer.profile?.user.department?.objectId
  208. );
  209. }
  210. if (this.tbookSer.profile.identity == '国家级管理员' || id) {
  211. query.equalTo('parent', id ? id : null);
  212. }
  213. query.limit(100);
  214. val && query.contains('name', val);
  215. let r = await query.find();
  216. this.parentList = r;
  217. }
  218. async formatNode(id: string): Promise<Array<any>> {
  219. let arr = [];
  220. if (id) {
  221. let query = new Parse.Query('Department');
  222. query.equalTo('objectId', id);
  223. query.select('parent', 'name');
  224. let r = await query.first();
  225. arr.push({
  226. title: r?.get('name'),
  227. id: r?.id,
  228. });
  229. if (r?.get('parent')) {
  230. arr.unshift(...(await this.formatNode(r?.get('parent')?.id)));
  231. }
  232. }
  233. return arr;
  234. }
  235. onCheck(e: any) {
  236. console.log(e);
  237. this.userDataJson.department = undefined;
  238. this.provinceChange();
  239. }
  240. parent: string = ''; //搜索时传入的id
  241. //选择部门
  242. async onCheckedDepart(e: any) {
  243. console.log(e);
  244. if (e?.get('parent')?.id) {
  245. this.userDataJson.department = e;
  246. this.parent = e?.get('parent')?.id;
  247. } else {
  248. this.provinceChange(e.id);
  249. this.parent = e?.id;
  250. }
  251. this.parentMap = await this.formatNode(e.id);
  252. }
  253. handleCancel(): void {
  254. console.log('Button cancel clicked!');
  255. this.userDataJson = {
  256. companyType: this.profile?.get('companyType'),
  257. department: this.user.get('department'),
  258. };
  259. this.isShowModal = false;
  260. this.parent = '';
  261. }
  262. async completeChange(): Promise<void> {
  263. if (!this.userDataJson.department?.id) {
  264. this.message.warning('请选择部门');
  265. return;
  266. }
  267. this.userDataJson.companyType = this.userDataJson.department.get('branch');
  268. this.profile?.set('companyType', this.userDataJson.companyType);
  269. await this.profile?.save();
  270. this.user?.set('department', this.userDataJson.department?.toPointer());
  271. await this.user?.save();
  272. this.ngOnInit();
  273. this.isShowModal = false;
  274. this.parent = '';
  275. }
  276. openUrl(url: string) {
  277. if (!/\.(jpg|jpeg|png|GIF|JPG|PNG)$/.test(url)) {
  278. window.open(url);
  279. } else {
  280. let images = [
  281. {
  282. src: url,
  283. width: '200px',
  284. height: '200px',
  285. alt: 'ng-zorro',
  286. },
  287. ];
  288. this.nzImageService.preview(images, { nzZoom: 1.5, nzRotate: 0 });
  289. }
  290. }
  291. submitForm(type:string){
  292. this.message.warning('权限暂未开放')
  293. }
  294. }