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