invite.component.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { AuthService } from '../../../services/auth.service';
  3. import * as Parse from 'parse';
  4. import { ActivatedRoute } from '@angular/router';
  5. import { HttpClient, HttpHeaders } from '@angular/common/http';
  6. import { catchError } from 'rxjs/operators';
  7. import { AgreementComponent } from '.././agreement/agreement.component';
  8. import { FormsModule, ReactiveFormsModule } from '@angular/forms';
  9. import { CommonModule } from '@angular/common';
  10. import {
  11. ionicStandaloneModules,
  12. AlertController,
  13. ToastController,
  14. ModalController,
  15. // LoadingController,
  16. } from '../../ionic-standalone.modules';
  17. import { Platform } from '@ionic/angular';
  18. @Component({
  19. selector: 'app-invite',
  20. templateUrl: './invite.component.html',
  21. styleUrls: ['./invite.component.scss'],
  22. standalone: true,
  23. imports: [
  24. CommonModule,
  25. FormsModule,
  26. ReactiveFormsModule,
  27. ...ionicStandaloneModules,
  28. ],
  29. })
  30. export class InviteComponent implements OnInit {
  31. constructor(
  32. private toastController: ToastController,
  33. public authServ: AuthService,
  34. // private router: Router,
  35. private activatedRoute: ActivatedRoute,
  36. private http: HttpClient,
  37. private modalCtrl: ModalController,
  38. private alertController: AlertController,
  39. // private loadingCtrl: LoadingController
  40. private platform: Platform
  41. ) {
  42. this.company = authServ.company;
  43. }
  44. inviteUser?:Parse.Object
  45. company: string = '';
  46. inputType: string = 'password';
  47. // 注册
  48. agreement: boolean = false;
  49. registerAgreement: any;
  50. registerInfo: any = {
  51. mobile: '',
  52. code: '',
  53. password: '',
  54. confirmPassword: '',
  55. invite: '',
  56. nickname: '',
  57. };
  58. isRegister: boolean = false; //是否注册成功
  59. app:Parse.Object
  60. nicknameArr = [
  61. "星辰",
  62. "月夜夜影",
  63. "花儿阳光",
  64. "彩虹颜色",
  65. "云朵天空",
  66. "凤凰火焰",
  67. "龙呼吸",
  68. "鹰翅膀",
  69. "狼族群",
  70. "虎爪子",
  71. "狮咆哮",
  72. "熊拥抱",
  73. "狐狸尾巴",
  74. "鹿鹿角",
  75. "马奔跑",
  76. "兔跳跃",
  77. "松鼠坚果",
  78. "猴子香蕉",
  79. "熊猫竹子",
  80. "长颈鹿脖子"
  81. ]
  82. ngOnInit() {
  83. if (this.platform.is('hybrid')) {
  84. this.authServ.logout();
  85. return;
  86. }
  87. this.registerInfo.nickname = this.nicknameArr[Math.floor(Math.random() * 20)] + new Date().getMilliseconds()
  88. let invite = localStorage.getItem('invite');
  89. // console.log('invite:', invite);
  90. if (invite) this.registerInfo.invite = invite;
  91. this.activatedRoute.paramMap.subscribe(async (param) => {
  92. let id = param?.get('id');
  93. if(!invite) invite = id
  94. if (invite) {
  95. let query = new Parse.Query('User');
  96. query.equalTo('invite', invite);
  97. query.select('mobile', 'username', 'nickname');
  98. this.inviteUser = await query.first();
  99. this.registerInfo.invite = invite;
  100. }else{
  101. window.location.href = '';
  102. }
  103. localStorage.setItem('APP_DEFAULT_COMPANY', 'Qje9D4bqol');
  104. localStorage.setItem('company', this.company);
  105. if (this.company) {
  106. let App = new Parse.Query('App');
  107. App.equalTo('company', this.company);
  108. this.app = await App.first();
  109. }
  110. this.getAgreement();
  111. });
  112. }
  113. // 获取验证码
  114. wait: number = 60;
  115. waitStatus: boolean = false;
  116. time() {
  117. if (this.wait == 0) {
  118. this.waitStatus = false;
  119. this.wait = 60;
  120. } else {
  121. this.waitStatus = true;
  122. this.wait--;
  123. setTimeout(() => {
  124. this.time();
  125. }, 1000);
  126. }
  127. }
  128. // 获取验证码
  129. vcode: string = '';
  130. mobile: string = '';
  131. loginToken: string = '';
  132. timer: boolean = false;
  133. async sendVerifyCode(mobile: string) {
  134. if (this.timer) {
  135. return;
  136. }
  137. this.timer = true;
  138. let a = /^1[3456789]\d{9}$/;
  139. if (mobile == undefined || !String(mobile).match(a)) {
  140. const toast = await this.toastController.create({
  141. message: '请填写正确手机号',
  142. color: 'warning',
  143. duration: 1000,
  144. });
  145. toast.present();
  146. this.timer = false;
  147. return;
  148. }
  149. this.http
  150. .post('https://server.fmode.cn/api/apig/message', {
  151. company: this.company,
  152. mobile: mobile,
  153. })
  154. .subscribe((res: any) => {
  155. this.waitStatus = true;
  156. this.time();
  157. this.vcode = res.data.code;
  158. this.timer = false;
  159. });
  160. }
  161. togglePassword() {
  162. if (this.inputType == 'password') {
  163. this.inputType = 'text';
  164. } else {
  165. this.inputType = 'password';
  166. }
  167. }
  168. // 注册账号
  169. agree() {
  170. this.agreement = !this.agreement;
  171. }
  172. getAgreement() {
  173. let Agreement = new Parse.Query('ContractAgreement');
  174. Agreement.equalTo('company', this.company);
  175. Agreement.equalTo('type', 'register');
  176. Agreement.first().then((res) => {
  177. console.log(res);
  178. this.registerAgreement = res;
  179. });
  180. }
  181. async showAgreement() {
  182. const modal = await this.modalCtrl.create({
  183. component: AgreementComponent,
  184. cssClass: 'my-custom-class',
  185. componentProps: {
  186. agreement: this.registerAgreement,
  187. },
  188. });
  189. return await modal.present();
  190. }
  191. async registerUser() {
  192. let a = /^1[3456789]\d{9}$/;
  193. if (
  194. this.registerInfo.mobile == undefined ||
  195. !String(this.registerInfo.mobile).match(a)
  196. ) {
  197. const toast = await this.toastController.create({
  198. message: '请填写正确的手机号',
  199. color: 'warning',
  200. duration: 1000,
  201. });
  202. toast.present();
  203. return;
  204. }
  205. if (this.registerInfo.code == undefined || this.registerInfo.code == '') {
  206. const toast = await this.toastController.create({
  207. message: '请输入验证码',
  208. color: 'warning',
  209. duration: 1000,
  210. });
  211. toast.present();
  212. return;
  213. }
  214. if (
  215. this.registerInfo.password == undefined ||
  216. this.registerInfo.password.trim() == ''
  217. ) {
  218. const toast = await this.toastController.create({
  219. message: '请输入密码',
  220. color: 'warning',
  221. duration: 1000,
  222. });
  223. toast.present();
  224. return;
  225. }
  226. if (
  227. this.registerInfo.password.length < 6 ||
  228. this.registerInfo.password.length.length > 20
  229. ) {
  230. const toast = await this.toastController.create({
  231. message: '密码长度不得小于6位或大于20位',
  232. color: 'warning',
  233. duration: 1000,
  234. });
  235. toast.present();
  236. return;
  237. }
  238. if (
  239. this.registerInfo.confirmPassword == undefined ||
  240. this.registerInfo.confirmPassword.trim() == ''
  241. ) {
  242. const toast = await this.toastController.create({
  243. message: '请确认密码',
  244. color: 'warning',
  245. duration: 1000,
  246. });
  247. toast.present();
  248. return;
  249. }
  250. if (
  251. this.registerInfo.password.trim() !=
  252. this.registerInfo.confirmPassword.trim()
  253. ) {
  254. const toast = await this.toastController.create({
  255. message: '两次输入密码不一致',
  256. color: 'warning',
  257. duration: 1000,
  258. });
  259. toast.present();
  260. return;
  261. }
  262. this.registerInfo.nickname = this.registerInfo.nickname?.trim()
  263. if(!this.registerInfo.nickname){
  264. const toast = await this.toastController.create({
  265. message: '请输入昵称',
  266. color: 'warning',
  267. duration: 1000,
  268. });
  269. toast.present();
  270. return;
  271. }
  272. if (!this.agreement) {
  273. const alert = await this.alertController.create({
  274. cssClass: 'my-custom-class',
  275. header: '提示',
  276. message: `请先勾选${this.registerAgreement?.get('title')}`,
  277. buttons: [
  278. {
  279. text: '取消',
  280. role: 'cancel',
  281. cssClass: 'secondary',
  282. handler: (blah) => {
  283. console.log('Confirm Cancel: blah');
  284. },
  285. },
  286. {
  287. text: '同意',
  288. handler: () => {
  289. this.agreement = true;
  290. },
  291. },
  292. ],
  293. });
  294. await alert.present();
  295. return;
  296. }
  297. let data = this.registerInfo.invite
  298. ? {
  299. company: this.company,
  300. code: this.registerInfo.code,
  301. mobile: this.registerInfo.mobile,
  302. password: this.registerInfo.password,
  303. invite: this.registerInfo.invite,
  304. nickname:this.registerInfo.nickname,
  305. }
  306. : {
  307. company: this.company,
  308. code: this.registerInfo.code,
  309. mobile: this.registerInfo.mobile,
  310. password: this.registerInfo.password,
  311. nickname:this.registerInfo.nickname,
  312. };
  313. this.http
  314. .post(`https://server.fmode.cn/api/auth/register`, data)
  315. .pipe(
  316. catchError(async (e) => {
  317. // 显示报错
  318. const toast = await this.toastController.create({
  319. message: e.error.mess,
  320. color: 'danger',
  321. duration: 1000,
  322. });
  323. toast.present();
  324. console.log(e);
  325. return;
  326. })
  327. )
  328. .subscribe(async (res: any) => {
  329. console.log(res);
  330. if (res && res.code == 200) {
  331. const toast = await this.toastController.create({
  332. message: res.msg,
  333. color: 'success',
  334. duration: 1000,
  335. });
  336. toast.present();
  337. const alert = await this.alertController.create({
  338. cssClass: 'my-custom-class',
  339. header: '注册成功',
  340. message: `恭喜你,注册成功`,
  341. backdropDismiss: false,
  342. buttons: [
  343. {
  344. text: '确认',
  345. handler: () => {
  346. this.registerInfo = {
  347. mobile: '',
  348. code: '',
  349. password: '',
  350. confirmPassword: '',
  351. invite: '',
  352. };
  353. this.isRegister = true
  354. },
  355. },
  356. ],
  357. });
  358. await alert.present();
  359. } else {
  360. // const toast = await this.toastController.create({
  361. // // 接口返回的错误,提示用户
  362. // message: res.mess,
  363. // color: 'danger',
  364. // duration: 1000,
  365. // });
  366. // toast.present();
  367. }
  368. });
  369. }
  370. downImg(url:string) {
  371. let dlLink: any = document.createElement('a');
  372. if ('download' in dlLink) {
  373. dlLink.style.visibility = 'hidden';
  374. dlLink.href = url;
  375. dlLink.download = 'hey聊';
  376. document.body.appendChild(dlLink);
  377. dlLink.click();
  378. document.body.removeChild(dlLink);
  379. } else {
  380. location.href = url;
  381. }
  382. }
  383. }