Commit ad8e33bb by zeyang

1.解决首次登录后token未及时更新的BUG

parent 5c4c35bf
import { Component, OnDestroy, OnInit,HostListener,ViewChild,ElementRef } from '@angular/core';
import { Component, OnDestroy, OnInit, HostListener, ViewChild, ElementRef } from '@angular/core';
import { NavigationExtras, Router } from '@angular/router';
import { AuthService } from '../auth.service';
import { LifeCommonService } from '../../common/life-common.service';
......@@ -9,28 +9,28 @@ import { LifeCommonService } from '../../common/life-common.service';
styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit, OnDestroy {
@ViewChild('dragContainer') dragContainer: ElementRef;
@ViewChild('dragHandler') dragHandler: ElementRef;
@ViewChild('dragContainer') dragContainer : ElementRef;
@ViewChild('dragHandler') dragHandler : ElementRef;
MOBILE_REGEXP = /^(1)\d{10}$/;
sendCodeHtml: string = '获取验证码';
timer: any;
remainTimes: number = 60;
disabledSendBtn: boolean = false;
userInfo: any = {
sendCodeHtml : string = '获取验证码';
timer : any;
remainTimes : number = 60;
disabledSendBtn : boolean = false;
userInfo : any = {
mobileNo: null,
verificationCode: null
};
isNeedAlert: boolean;
dialogInfo: any;
redirect: any;
dragBg:any;
dragText:any;
maxHandlerOffset:any;
isVertifySucc:boolean = true;
left:any;
deviceType:any;
len:any;
constructor(public authService: AuthService, public router: Router, public lifeCommonService: LifeCommonService) {
isNeedAlert : boolean;
dialogInfo : any;
redirect : any;
dragBg : any;
dragText : any;
maxHandlerOffset : any;
isVertifySucc : boolean = true;
left : any;
deviceType : any;
len : any;
constructor(public authService : AuthService, public router : Router, public lifeCommonService : LifeCommonService) {
this.deviceType = this.lifeCommonService.checkDeviceType();
}
......@@ -61,7 +61,7 @@ export class LoginComponent implements OnInit, OnDestroy {
// //滑块的最大偏移量 = 滑动验证容器文本长度 - 滑块长度
this.maxHandlerOffset = this.dragContainer.nativeElement.clientWidth - this.dragHandler.nativeElement.clientWidth;
this.initDrag();
this.len = (window.innerWidth-document.body.clientWidth)/2;
this.len = (window.innerWidth - document.body.clientWidth) / 2;
}
......@@ -78,23 +78,22 @@ export class LoginComponent implements OnInit, OnDestroy {
mobileNo: this.userInfo.mobileNo,
verificationCode: this.userInfo.verificationCode,
expireTime: '3600',
fromSystemName:'ydLife'
fromSystemName: 'ydLife'
};
if (this.MOBILE_REGEXP.test(this.userInfo.mobileNo) && this.userInfo.verificationCode && this.userInfo.verificationCode.length == 6) {
this.authService.compare(compareInfo).subscribe(res => {
if (res['success']) {
this.authService.login({ mobileNo: this.userInfo.mobileNo,fromSystemName:'ydLife' }).subscribe((response) => {
this.authService.login({ mobileNo: this.userInfo.mobileNo, fromSystemName: 'ydLife' }).subscribe((response) => {
if (response['success']) {
this.authService.isLoggedIn = true;
if(response['data']['practitionerBasicInfo'] && response['data']['practitionerBasicInfo']['subordinateName']){
if (response['data']['practitionerBasicInfo'] && response['data']['practitionerBasicInfo']['subordinateName']) {
sessionStorage.setItem('subordinateSystemName', response['data']['practitionerBasicInfo']['subordinateName'])
}
const lifeCustomerInfo = { ...response.data, mobileNo: this.userInfo.mobileNo, commonResult: null };
this.authService.obtainToken(this.userInfo.mobileNo,response['data']['customerId']).subscribe((res)=>{
if (res['success']) {
localStorage.setItem('lifeToken', res['data']['token']);
this.authService.obtainToken(this.userInfo.mobileNo, response['data']['customerId']).subscribe((res2) => {
if (res2['success']) {
localStorage.setItem('lifeToken', res2['data']['token']);
}
})
if (lifeCustomerInfo['customerId'] && lifeCustomerInfo['practitionerId']) {
// if (response['data']['practitionerTypeId'] == 28) {
localStorage.setItem('lifeCustomerInfo', JSON.stringify(lifeCustomerInfo));
......@@ -130,6 +129,8 @@ export class LoginComponent implements OnInit, OnDestroy {
} else {
this.openPopInfo('暂无查询资格');
}
})
} else {
this.openPopInfo(response['message']);
}
......@@ -196,39 +197,39 @@ export class LoginComponent implements OnInit, OnDestroy {
//在滑动验证容器文本写入“拖动滑块验证”
this.dragText.textContent = "拖动滑块验证";
//给滑块添加鼠标按下监听
if(this.deviceType == 2 || this.deviceType == 3){
this.dragHandler.nativeElement.addEventListener("touchstart", ()=>{
if (this.deviceType == 2 || this.deviceType == 3) {
this.dragHandler.nativeElement.addEventListener("touchstart", () => {
this.onDragHandlerMouseDown()
},false);
}else{
this.dragHandler.nativeElement.addEventListener("mousedown", ()=>{
}, false);
} else {
this.dragHandler.nativeElement.addEventListener("mousedown", () => {
this.onDragHandlerMouseDown()
});
}
}
}
//选中滑块
onDragHandlerMouseDown() {
if(this.deviceType == 2 || this.deviceType == 3){
if (this.deviceType == 2 || this.deviceType == 3) {
//鼠标移动监听
document.addEventListener("touchmove", ()=>{
document.addEventListener("touchmove", () => {
this.onDragHandlerMouseMove(event)
},false);
}, false);
//鼠标松开监听
document.addEventListener("touchend", ()=>{
document.addEventListener("touchend", () => {
this.onDragHandlerMouseUp
});
}else{
} else {
document.querySelector('#dragHandler').classList.add('slideController');
//获取滑块
this.dragHandler.nativeElement = document.getElementsByClassName("slideController")[0];
//鼠标移动监听
this.dragHandler.nativeElement.addEventListener("mousemove",(e)=>{
this.dragHandler.nativeElement.addEventListener("mousemove", (e) => {
this.onDragHandlerMouseMove(e);
});
//鼠标松开监听
this.dragHandler.nativeElement.addEventListener("mouseup", ()=>{this.onDragHandlerMouseUp});
this.dragHandler.nativeElement.addEventListener("mouseup", () => { this.onDragHandlerMouseUp });
}
}
......@@ -247,25 +248,25 @@ export class LoginComponent implements OnInit, OnDestroy {
offsetX是相对当前元素的,clientX和pageX是相对其父元素的
*/
//滑块移动量
if(this.deviceType == 2 || this.deviceType == 3){
if (this.deviceType == 2 || this.deviceType == 3) {
this.left = touch.clientX - this.dragHandler.nativeElement.clientWidth / 2 - this.len;
}else{
} else {
//获取滑块
this.dragHandler.nativeElement = document.getElementsByClassName("slideController")[0];
if(this.dragHandler.nativeElement){
if (this.dragHandler.nativeElement) {
this.left = touch.clientX - this.dragHandler.nativeElement.clientWidth / 2 - this.len;
}else{
} else {
this.left = 0;
}
}
if(this.left < 0) {
if (this.left < 0) {
this.left = 0;
//如果滑块移动量 > 滑块的最大偏移量 ,则调用验证成功函数
} else if(this.left > this.maxHandlerOffset) {
} else if (this.left > this.maxHandlerOffset) {
this.left = this.maxHandlerOffset;
this.verifySucc();
}
if(this.dragHandler.nativeElement){
if (this.dragHandler.nativeElement) {
//滑块移动量
this.dragHandler.nativeElement.style.left = this.left + "px";
//绿色背景的长度
......@@ -275,19 +276,19 @@ export class LoginComponent implements OnInit, OnDestroy {
//松开滑块函数
onDragHandlerMouseUp() {
if(this.deviceType == 2 || this.deviceType == 3){
if (this.deviceType == 2 || this.deviceType == 3) {
//移除鼠标移动监听
document.removeEventListener("touchmove", this.onDragHandlerMouseMove);
//移除鼠标松开监听
document.removeEventListener("touchend", this.onDragHandlerMouseUp);
}else{
} else {
//移除鼠标移动监听
document.removeEventListener("mousemove", this.onDragHandlerMouseMove);
//移除鼠标松开监听
document.removeEventListener("mouseup", this.onDragHandlerMouseUp);
document.querySelector('#dragHandler').classList.remove('slideController');
}
if(this.isVertifySucc){
if (this.isVertifySucc) {
//初始化滑块移动量
this.dragHandler.nativeElement.style.left = 0;
//初始化绿色背景
......@@ -301,18 +302,18 @@ export class LoginComponent implements OnInit, OnDestroy {
this.dragText.textContent = "验证通过";
this.dragText.style.color = "white";
this.dragHandler.nativeElement.setAttribute("class", "dragHandlerOkBg");
if(this.deviceType == 2 || this.deviceType == 3){
if (this.deviceType == 2 || this.deviceType == 3) {
this.dragHandler.nativeElement.removeEventListener("touchstart", this.onDragHandlerMouseDown);
document.removeEventListener("touchmove", this.onDragHandlerMouseMove);
document.removeEventListener("touchend", this.onDragHandlerMouseUp);
}else{
} else {
this.dragHandler.nativeElement.removeEventListener("mousedown", this.onDragHandlerMouseDown);
this.dragHandler.nativeElement.removeEventListener("mousemove", this.onDragHandlerMouseMove);
this.dragHandler.nativeElement.removeEventListener("mouseup", this.onDragHandlerMouseUp);
}
setTimeout(()=>{
setTimeout(() => {
this.dragContainer.nativeElement.style.display = 'none'
},1000)
}, 1000)
};
}
\ No newline at end of file
......@@ -2,18 +2,18 @@ import { Component, OnInit, ViewChild, ElementRef, AfterViewInit } from '@angula
import { Router } from '@angular/router';
import { LifeCommonService } from 'src/app/common/life-common.service';
import { MyService } from '../my.service';
declare var wx: any;
declare var wx : any;
@Component({
selector: 'ydlife-my-center-home',
templateUrl: './my-center-home.component.html',
styleUrls: ['./my-center-home.component.scss'],
})
export class MyCenterHomeComponent implements OnInit {
messageUnreadCount:string;
productInfo: any;
inquiry: any;
public announcementInfo: string;
public searchText: string;
messageUnreadCount : string;
productInfo : any;
inquiry : any;
public announcementInfo : string;
public searchText : string;
public featureLists = [
{ key: '00', name: '产品库', icon: 'productLibary', link: '/product', isOpen: true },
{ key: '01', name: '计划书', icon: 'proposals', link: '', isOpen: false },
......@@ -26,8 +26,8 @@ export class MyCenterHomeComponent implements OnInit {
public bannerLists = [];
public hotProductLists = [];
public onlineProductLists = [];
lifeCustomerInfo: any = JSON.parse(localStorage.getItem('lifeCustomerInfo')) ? JSON.parse(localStorage.getItem('lifeCustomerInfo')) : null;
canSeeSchool:any='';
lifeCustomerInfo : any = JSON.parse(localStorage.getItem('lifeCustomerInfo')) ? JSON.parse(localStorage.getItem('lifeCustomerInfo')) : null;
canSeeSchool : any = '';
state = {
modal1: false,
};
......@@ -41,14 +41,14 @@ export class MyCenterHomeComponent implements OnInit {
}
}
querySystemMessage(){
this.myService.querySystemMessage({practitionerId:localStorage.getItem('lifeCustomerInfo') ? JSON.parse(localStorage.getItem('lifeCustomerInfo')).practitionerId : null}).subscribe(res=>{
if(res['success']){
querySystemMessage() {
this.myService.querySystemMessage({ practitionerId: localStorage.getItem('lifeCustomerInfo') ? JSON.parse(localStorage.getItem('lifeCustomerInfo')).practitionerId : null }).subscribe(res => {
if (res['success']) {
this.messageUnreadCount = res['data']['unReadcount'];
if(Number(this.messageUnreadCount) > 99){
if (Number(this.messageUnreadCount) > 99) {
this.messageUnreadCount = '99+';
}
}else{
} else {
this.messageUnreadCount = null;
}
})
......@@ -97,7 +97,7 @@ export class MyCenterHomeComponent implements OnInit {
}
// 点击产品进入详情页
goProductDetail(product): void {
goProductDetail(product) : void {
if (product.isThirdpartyPurchase == 1) {
if (product.thirdpartyPurchaseUrl) {
window.location.href = product.thirdpartyPurchaseUrl;
......@@ -146,24 +146,22 @@ export class MyCenterHomeComponent implements OnInit {
return;
}
}
queryCanSee(){
this.myService.queryCanSee({practitionerId: this.lifeCustomerInfo?this.lifeCustomerInfo['practitionerId']:null,}).subscribe((res)=>{
if(res['success']){
queryCanSee() {
this.myService.queryCanSee({ practitionerId: this.lifeCustomerInfo ? this.lifeCustomerInfo['practitionerId'] : null, }).subscribe((res) => {
if (res['success']) {
this.canSeeSchool = res['data']['canSeeYdCollege'];
if (this.canSeeSchool.includes('insuranceABC') || this.canSeeSchool.includes('preJobTraining') || this.canSeeSchool.includes('newTraining') ||this.canSeeSchool.includes('promotionTraining')
if (this.canSeeSchool.includes('insuranceABC') || this.canSeeSchool.includes('preJobTraining') || this.canSeeSchool.includes('newTraining') || this.canSeeSchool.includes('promotionTraining')
|| this.canSeeSchool.includes('productTraining') || this.canSeeSchool.includes('myTraining')) {
this.featureLists.push({ key: '06', name: '银盾学院', icon: 'ydCollege', link: '/ydCollege', isOpen: true },);
}else{
} else {
this.featureLists.push({ key: '06', name: '新人入口', icon: 'potentialCustomers', link: '/newPeople', isOpen: true });
}
this.featureLists.push({ key: '07', name: '更多功能', icon: 'more', link: '/moreFeatures', isOpen: true });
}
})
}
constructor(private myService: MyService, private router: Router, private lifeCommonService: LifeCommonService) { }
ngOnInit(): void {
constructor(private myService : MyService, private router : Router, private lifeCommonService : LifeCommonService) { }
ngOnInit() : void {
this.filePathQuery()
// 查询互联网产品
this.queryproductlistbytag(272, 'onlineProductLists');
......@@ -177,6 +175,3 @@ export class MyCenterHomeComponent implements OnInit {
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment