Merge pull request 'ymt-dev' (#2) from ymt-dev into 2.0-dev

Reviewed-on: #2
2.0-dev
袁野 2 years ago
commit c8e7c6c7aa
  1. 2
      src/app/admin/login/login.module.ts
  2. 42
      src/app/admin/login/login/login.component.html
  3. 17
      src/app/admin/login/login/login.component.less
  4. 26
      src/app/admin/login/login/login.component.ts
  5. 5
      src/app/common/verification-code/verification-code.component.html
  6. 0
      src/app/common/verification-code/verification-code.component.scss
  7. 120
      src/app/common/verification-code/verification-code.component.ts
  8. 14
      src/app/common/verification-code/verification-code.module.ts
  9. 2
      src/environments/environment.ts

@ -5,6 +5,7 @@ import { LoginRoutingModule } from './login-routing.module';
import { LoginComponent } from './login/login.component'; import { LoginComponent } from './login/login.component';
import {NgZorroAntdModule} from 'ng-zorro-antd'; import {NgZorroAntdModule} from 'ng-zorro-antd';
import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { VerificationCodeModule } from 'src/app/common/verification-code/verification-code.module';
@NgModule({ @NgModule({
@ -13,6 +14,7 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
CommonModule, CommonModule,
LoginRoutingModule, LoginRoutingModule,
NgZorroAntdModule, NgZorroAntdModule,
VerificationCodeModule,
ReactiveFormsModule, ReactiveFormsModule,
FormsModule, FormsModule,
] ]

@ -7,9 +7,9 @@
</div> </div>
<div class="body-content-login"> <div class="body-content-login">
<div class="body-content-right-title">嗨森逛后台登录</div> <div class="body-content-right-title">嗨森逛后台登录</div>
<form nz-form class="login-form" [formGroup]="loginForm" (ngSubmit)="submitLogin()"> <form nz-form [nzLayout]="'vertical'" class="login-form" [formGroup]="loginForm" (ngSubmit)="submitLogin()">
<div class="form-item"> <!-- <div class="form-item">
<div class="form-item-label"><h3>用户名</h3></div> <div class="form-item-label"><h3>用户名</h3></div>
<div class="form-item-control"> <div class="form-item-control">
<input type="text" formControlName="loginName" placeholder="请输入您的用户名"> <input type="text" formControlName="loginName" placeholder="请输入您的用户名">
@ -22,6 +22,44 @@
<input type="password" formControlName="password" placeholder="请输入您的密码"> <input type="password" formControlName="password" placeholder="请输入您的密码">
</div> </div>
</div> </div>
<div class="form-item">
<div class="form-item-label"><h3>&nbsp;&nbsp;</h3></div>
<div class="form-item-control" nz-row [nzGutter]="16">
<input nz-col nzSpan="14" type="text" formControlName="vertifyCode" placeholder="请输入验证码">
<app-verification-code nz-col nzSpan="10" (validate)="validateFun($event)" ></app-verification-code>
</div>
</div> -->
<nz-form-item>
<nz-form-label nzRequired nzFor="loginName" class="form-item-label"><h3>用户名</h3></nz-form-label>
<nz-form-control nzErrorTip="请输入您的用户名!" class="form-item-control">
<input nz-input type="text" id="loginName" formControlName="loginName" placeholder="请输入您的用户名" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzFor="password" nzRequired class="form-item-label"><h3>&nbsp;&nbsp;&nbsp;</h3></nz-form-label>
<nz-form-control nzErrorTip="请输入您的密码!" class="form-item-control">
<input nz-input type="password" id="password" formControlName="password" placeholder="请输入您的密码" />
</nz-form-control>
</nz-form-item>
<nz-form-item>
<nz-form-label nzFor="vertifyCode" nzRequired class="form-item-label"><h3>验证码</h3></nz-form-label>
<nz-form-control nzErrorTip="请输入验证码!" class="form-item-control">
<div nz-row >
<input nz-col nzSpan="12" nz-input type="text" id="vertifyCode" formControlName="vertifyCode" placeholder="请输入验证码" />
<app-verification-code nz-col nzSpan="12" (validate)="validateFun($event)" ></app-verification-code>
</div>
</nz-form-control>
</nz-form-item>
<!--<div class="forget-pwd"> <!--<div class="forget-pwd">
<a routerLink="/retrieveAdminPwd">忘记密码</a> <a routerLink="/retrieveAdminPwd">忘记密码</a>

@ -4,7 +4,7 @@
} }
.header-block { .header-block {
width: 1230px; // width: 1230px;
margin: 0 auto; margin: 0 auto;
overflow: hidden; overflow: hidden;
background: #ffffff; background: #ffffff;
@ -55,7 +55,9 @@
.body-content-login { .body-content-login {
margin: -300px auto; margin: -300px auto;
width: 350px; width: 350px;
height: 400px; // height: 400px;
padding:10px 0 20px;
border-radius: 16px; border-radius: 16px;
box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.17); box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.17);
background: #ffffff; background: #ffffff;
@ -122,6 +124,7 @@
} }
.from-btn button { .from-btn button {
cursor: pointer;
margin-top: 20px; margin-top: 20px;
width: 250px; width: 250px;
height: 37px; height: 37px;
@ -211,7 +214,17 @@
float: left; float: left;
} }
::ng-deep .ant-form-item-label > label.ant-form-item-required::before{
display: none;
}
::ng-deep .ant-form-vertical .ant-form-item-label{
padding:0;
}
::ng-deep .ant-form-vertical .ant-form-item{
margin-bottom: 15px;
}
/*常规验证码*/ /*常规验证码*/
::ng-deep .verify-code { ::ng-deep .verify-code {

@ -16,7 +16,8 @@ import {HttpClient} from '@angular/common/http';
export class LoginComponent implements OnInit { export class LoginComponent implements OnInit {
loginForm: FormGroup; // 登录表单 loginForm: FormGroup; // 登录表单
code:string="";
constructor(private store: LocalStorageService, // 数据请求 constructor(private store: LocalStorageService, // 数据请求
private router: Router, // 路由 private router: Router, // 路由
private form: FormBuilder, // 表单校验 private form: FormBuilder, // 表单校验
@ -30,6 +31,7 @@ export class LoginComponent implements OnInit {
this.loginForm = this.form.group({ this.loginForm = this.form.group({
loginName: [null, [Validators.required]], loginName: [null, [Validators.required]],
password: [null, [Validators.required]], password: [null, [Validators.required]],
vertifyCode:[null, [Validators.required]]//验证码
}); });
} }
@ -37,18 +39,27 @@ export class LoginComponent implements OnInit {
* *
*/ */
submitLogin() { submitLogin() {
// tslint:disable-next-line:forin // tslint:disable-next-line:forin
for (const i in this.loginForm.controls) { for (const i in this.loginForm.controls) {
this.loginForm.controls[i].markAsDirty(); this.loginForm.controls[i].markAsDirty();
this.loginForm.controls[i].updateValueAndValidity(); this.loginForm.controls[i].updateValueAndValidity();
} }
if (this.loginForm.status == null || this.loginForm.status !== 'VALID') { if (this.loginForm.status == null || this.loginForm.status !== 'VALID') {
this.modal.warning({ // this.modal.warning({
nzTitle: '提示', // nzTitle: '提示',
nzContent: '请填写用户和密码', // nzContent: '请填写用户和密码',
}); // });
return;
}
if(this.loginForm.value.vertifyCode.toLowerCase() !== this.code ){
this.message.error("请填写正确的验证码");
return; return;
} }
this.loginService.userLogin(this.loginForm.value, data => { this.loginService.userLogin(this.loginForm.value, data => {
if (data['return_code'] === '000000') { if (data['return_code'] === '000000') {
data['return_data']['object']['menuList'] = data['return_data']['object']['menuList'].filter(o => o.showOnMobile == 0); data['return_data']['object']['menuList'] = data['return_data']['object']['menuList'].filter(o => o.showOnMobile == 0);
@ -63,4 +74,9 @@ export class LoginComponent implements OnInit {
}); });
} }
// 子组件验证方法
validateFun(str:string) {
this.code = str;
}
} }

@ -0,0 +1,5 @@
<div id="v_container" (click)="refresh()" style="width: 100%;height: 100%;display: flex;justify-content: center;">
<canvas #verifyCanvas width="100" height="40" style="cursor: pointer;" ></canvas>
</div>

@ -0,0 +1,120 @@
import { Component, ElementRef, ViewChild, OnInit,Output,EventEmitter } from '@angular/core';
@Component({
selector: 'app-verification-code',
templateUrl: './verification-code.component.html',
styleUrls: ['./verification-code.component.scss']
})
export class VerificationCodeComponent implements OnInit {
@ViewChild('verifyCanvas') verifyCanvas: ElementRef;
@Output() validate = new EventEmitter()
codeLength = 4; // 设置验证码长度
options = {
// 默认options参数值
id: 'v_container', // 容器Id
canvasId: 'verifyCanvas', // canvas的ID
width: 100, // 默认canvas宽度
height: 40, // 默认canvas高度
type: 'blend', // 图形验证码默认类型blend:数字字母混合类型、number:纯数字、letter:纯字母
code: '',
numArr: [],
letterArr: [],
};
ctx;
constructor() {}
ngOnInit() {}
ngAfterViewInit(){
this.ctx = this.verifyCanvas.nativeElement.getContext('2d');
this.options.numArr = '0,1,2,3,4,5,6,7,8,9'.split(',');
this.options.letterArr = this.getAllLetter();
this.refresh();
}
// 生成验证码
refresh() {
this.options.code = '';
this.ctx.textBaseline = 'middle';
this.ctx.fillStyle = this.randomColor(180, 240);
this.ctx.fillRect(0, 0, this.options.width, this.options.height);
let txtArr = [];
if (this.options.type === 'blend') {
// 判断验证码类型
txtArr = this.options.numArr.concat(this.options.letterArr);
} else if (this.options.type === 'number') {
txtArr = this.options.numArr;
} else {
txtArr = this.options.letterArr;
}
for (let i = 1; i <= this.codeLength; i++) {
const txt = txtArr[this.randomNum(0, txtArr.length)];
this.options.code += txt;
this.ctx.font = this.randomNum(this.options.height / 2, this.options.height) + 'px SimHei'; // 随机生成字体大小
this.ctx.fillStyle = this.randomColor(50, 160); // 随机生成字体颜色
this.ctx.shadowOffsetX = this.randomNum(-3, 3);
this.ctx.shadowOffsetY = this.randomNum(-3, 3);
this.ctx.shadowBlur = this.randomNum(-3, 3);
this.ctx.shadowColor = 'rgba(0, 0, 0, 0.3)';
const x = (this.options.width / (this.codeLength + 1)) * i;
const y = this.options.height / 2;
const deg = this.randomNum(-30, 30);
// 设置旋转角度和坐标原点
this.ctx.translate(x, y);
this.ctx.rotate((deg * Math.PI) / 180);
this.ctx.fillText(txt, 0, 0);
// 恢复旋转角度和坐标原点
this.ctx.rotate((-deg * Math.PI) / 180);
this.ctx.translate(-x, -y);
}
// 绘制干扰线
for (let i = 0; i < 2; i++) {
this.ctx.strokeStyle = this.randomColor(40, 180);
this.ctx.beginPath();
this.ctx.moveTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height));
this.ctx.lineTo(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height));
this.ctx.stroke();
}
// 绘制干扰点
for (let i = 0; i < this.options.width / 2; i++) {
this.ctx.fillStyle = this.randomColor(0, 255);
this.ctx.beginPath();
this.ctx.arc(this.randomNum(0, this.options.width), this.randomNum(0, this.options.height), 1, 0, 2 * Math.PI);
this.ctx.fill();
}
this.validate.emit(this.options.code.toLowerCase())
}
// 生成字母数组
getAllLetter() {
const letterStr =
'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z';
return letterStr.split(',');
}
// 生成一个随机数
randomNum(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
// 生成一个随机色
randomColor(min, max) {
const r = this.randomNum(min, max);
const g = this.randomNum(min, max);
const b = this.randomNum(min, max);
return 'rgb(' + r + ',' + g + ',' + b + ')';
}
}

@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { VerificationCodeComponent } from './verification-code.component';
@NgModule({
imports: [
CommonModule
],
exports: [
VerificationCodeComponent
],
declarations: [VerificationCodeComponent]
})
export class VerificationCodeModule { }

@ -4,7 +4,7 @@
export const environment = { export const environment = {
production: false, production: false,
baseUrl: 'http://localhost:9302/brest/', // 测试环境服务器地址(请求数据地址) baseUrl: 'https://hsgcs.dctpay.com/brest/', // 测试环境服务器地址(请求数据地址)
orderUrl: 'https://hsgcs.dctpay.com/order/', // 测试环境服务器地址(请求数据地址) orderUrl: 'https://hsgcs.dctpay.com/order/', // 测试环境服务器地址(请求数据地址)
imageUrl: 'https://hsgcs.dctpay.com/filesystem/', imageUrl: 'https://hsgcs.dctpay.com/filesystem/',
key: 'https://hsgcs.dctpay.com/phone-recharge-H5/index.html?codeValue=', key: 'https://hsgcs.dctpay.com/phone-recharge-H5/index.html?codeValue=',

Loading…
Cancel
Save