import { Injectable } from '@angular/core'; import Parse from 'parse'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root', }) export class textbookServer { company: string = localStorage.getItem('company')!; theme: boolean = false; //深色主题模式 profile: any = JSON.parse(localStorage.getItem('profile')!); constructor(private http: HttpClient) {} authMobile(mobile: string): boolean { let a = /^1[3456789]\d{9}$/; if (!String(mobile).match(a)) { return false; } return true; } randomPassword(): string { let sCode = 'A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m'; let aCode = sCode.split(','); let aLength = aCode.length; //获取到数组的长度 let str = []; for (let i = 0; i <= 16; i++) { let j = Math.floor(Math.random() * aLength); //获取到随机的索引值 let txt = aCode[j]; //得到随机的一个内容 str.push(txt); } return str.join(''); } formatTime(fmt: string, date1: Date) { let ret; let date = new Date(date1); const opt: any = { 'Y+': date.getFullYear().toString(), // 年 'm+': (date.getMonth() + 1).toString(), // 月 'd+': date.getDate().toString(), // 日 'H+': date.getHours().toString(), // 时 'M+': date.getMinutes().toString(), // 分 'S+': date.getSeconds().toString(), // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (let k in opt) { ret = new RegExp('(' + k + ')').exec(fmt); if (ret) { fmt = fmt.replace( ret[1], ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, '0') ); } } return fmt; } //格式化链 async formatNode(id: string): Promise> { let query = new Parse.Query('Department'); query.select('name', 'parent', 'hasChildren'); let r = await query.get(id); let arr = [ { title: r.get('name'), key: r.id, hasChildren: r.get('hasChildren'), //是否是最下级 }, ]; if (r?.get('parent')) { arr.unshift(...(await this.formatNode(r?.get('parent').id))); } return arr; } }