代码优化

This commit is contained in:
shimingxy 2024-07-18 17:46:52 +08:00
parent 806c9b55de
commit dc73b1d30e
3 changed files with 34 additions and 44 deletions

View File

@ -14,34 +14,24 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Inject, OnInit, OnDestroy, AfterViewInit, Optional } from '@angular/core';
ChangeDetectionStrategy, import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
ChangeDetectorRef, import { Router, ActivatedRoute } from '@angular/router';
Component, import { throwIfAlreadyLoaded } from '@core';
Inject, import { ReuseTabService } from '@delon/abc/reuse-tab';
OnInit, import { SettingsService, _HttpClient } from '@delon/theme';
OnDestroy, import { environment } from '@env/environment';
AfterViewInit, import { NzSafeAny } from 'ng-zorro-antd/core/types';
Optional import { NzMessageService } from 'ng-zorro-antd/message';
} from '@angular/core'; import { NzTabChangeEvent } from 'ng-zorro-antd/tabs';
import {AbstractControl, FormBuilder, FormGroup, Validators} from '@angular/forms'; import { finalize } from 'rxjs/operators';
import {Router, ActivatedRoute} from '@angular/router';
import {throwIfAlreadyLoaded} from '@core';
import {ReuseTabService} from '@delon/abc/reuse-tab';
import {SettingsService, _HttpClient} from '@delon/theme';
import {environment} from '@env/environment';
import {NzSafeAny} from 'ng-zorro-antd/core/types';
import {NzMessageService} from 'ng-zorro-antd/message';
import {NzTabChangeEvent} from 'ng-zorro-antd/tabs';
import {finalize} from 'rxjs/operators';
import {AuthnService} from '../../../service/authn.service'; import { AuthnService } from '../../../service/authn.service';
import {ImageCaptchaService} from '../../../service/image-captcha.service'; import { ImageCaptchaService } from '../../../service/image-captcha.service';
import {SocialsProviderService} from '../../../service/socials-provider.service'; import { SocialsProviderService } from '../../../service/socials-provider.service';
import {CONSTS} from '../../../shared/consts'; import { CONSTS } from '../../../shared/consts';
import { stringify } from 'querystring';
import {stringify} from 'querystring';
@Component({ @Component({
selector: 'passport-login', selector: 'passport-login',
@ -95,7 +85,6 @@ export class UserLoginComponent implements OnInit, OnDestroy {
}); });
} }
ngOnInit(): void { ngOnInit(): void {
//set redirect_uri , is BASE64URL //set redirect_uri , is BASE64URL
if (this.route.snapshot.queryParams[CONSTS.REDIRECT_URI]) { if (this.route.snapshot.queryParams[CONSTS.REDIRECT_URI]) {
@ -110,7 +99,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
//init socials,state //init socials,state
this.authnService.clear(); this.authnService.clear();
this.authnService this.authnService
.get({remember_me: localStorage.getItem(CONSTS.REMEMBER)}) .get({ remember_me: localStorage.getItem(CONSTS.REMEMBER) })
.pipe( .pipe(
finalize(() => { finalize(() => {
this.loading = false; this.loading = false;
@ -140,7 +129,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
this.form.get('captcha')?.clearValidators(); this.form.get('captcha')?.clearValidators();
} else { } else {
//init image captcha //init image captcha
this.imageCaptchaService.captcha({state: this.state, captcha: this.captchaType}).subscribe(res => { this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
this.imageCaptcha = res.data.image; this.imageCaptcha = res.data.image;
this.cdr.detectChanges(); this.cdr.detectChanges();
}); });
@ -206,7 +195,7 @@ export class UserLoginComponent implements OnInit, OnDestroy {
// #region get captcha // #region get captcha
getImageCaptcha(): void { getImageCaptcha(): void {
this.imageCaptchaService.captcha({state: this.state, captcha: this.captchaType}).subscribe(res => { this.imageCaptchaService.captcha({ state: this.state, captcha: this.captchaType }).subscribe(res => {
this.imageCaptcha = res.data.image; this.imageCaptcha = res.data.image;
this.cdr.detectChanges(); this.cdr.detectChanges();
}); });
@ -215,11 +204,11 @@ export class UserLoginComponent implements OnInit, OnDestroy {
//send sms //send sms
sendOtpCode(): void { sendOtpCode(): void {
if (this.mobile.invalid) { if (this.mobile.invalid) {
this.mobile.markAsDirty({onlySelf: true}); this.mobile.markAsDirty({ onlySelf: true });
this.mobile.updateValueAndValidity({onlySelf: true}); this.mobile.updateValueAndValidity({ onlySelf: true });
return; return;
} }
this.authnService.produceOtp({mobile: this.mobile.value}).subscribe(res => { this.authnService.produceOtp({ mobile: this.mobile.value }).subscribe(res => {
if (res.code !== 0) { if (res.code !== 0) {
this.msg.success(`发送失败`); this.msg.success(`发送失败`);
} }
@ -326,7 +315,6 @@ export class UserLoginComponent implements OnInit, OnDestroy {
} }
} }
}); });
} }
// #endregion // #endregion
@ -396,13 +384,13 @@ export class UserLoginComponent implements OnInit, OnDestroy {
qrScanMaxkey(data: any) { qrScanMaxkey(data: any) {
// @ts-ignore // @ts-ignore
document.getElementById("div_qrcodelogin").innerHTML = ''; document.getElementById('div_qrcodelogin').innerHTML = '';
// @ts-ignore // @ts-ignore
var qrcode = new QRCode("div_qrcodelogin", { var qrcode = new QRCode('div_qrcodelogin', {
width: 200, width: 200,
height: 200, height: 200,
colorDark: "#000000", colorDark: '#000000',
colorLight: "#ffffff" colorLight: '#ffffff'
}).makeCode(data.state); }).makeCode(data.state);
//3分钟监听二维码 //3分钟监听二维码
this.count = 90; this.count = 90;

View File

@ -46,6 +46,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -107,7 +108,7 @@ public class LoginEntryPoint {
* @return * @return
*/ */
@Operation(summary = "登录接口", description = "用户登录地址",method="GET") @Operation(summary = "登录接口", description = "用户登录地址",method="GET")
@RequestMapping(value={"/get"}, produces = {MediaType.APPLICATION_JSON_VALUE}) @GetMapping(value={"/get"}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> get( public ResponseEntity<?> get(
@RequestParam(value = "remember_me", required = false) String rememberMeJwt) { @RequestParam(value = "remember_me", required = false) String rememberMeJwt) {
logger.debug("/get."); logger.debug("/get.");

View File

@ -65,8 +65,9 @@ public class OneTimePasswordController {
@RequestMapping(value = {"/timebased"}) @RequestMapping(value = {"/timebased"})
@ResponseBody @ResponseBody
public ResponseEntity<?> timebased( public ResponseEntity<?> timebased(
@RequestParam String generate,@CurrentUser UserInfo currentUser) { @RequestParam(name="generate") String generate,
HashMap<String,Object >timebased =new HashMap<String,Object >(); @CurrentUser UserInfo currentUser) {
HashMap<String,Object >timebased =new HashMap<>();
generate(generate,currentUser); generate(generate,currentUser);