diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 3a83d8e..4abeacd 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -2,7 +2,7 @@ import { Component, TemplateRef, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { Router, ActivatedRoute } from '@angular/router'
import { CacheTokenService } from './service/cache-token.service'//引入服务
-import { CookieService } from 'ngx-cookie-service';
+
import "reflect-metadata";
import { NzNotificationService } from 'ng-zorro-antd/notification';
@Component({
@@ -14,22 +14,10 @@ export class AppComponent {
@ViewChild(TemplateRef, { static: false }) template?: TemplateRef<{}>;
- constructor(private http: HttpClient, private router: Router, public token: CacheTokenService, private cookieService: CookieService, private notificationService: NzNotificationService) { }
+ constructor(private http: HttpClient, private router: Router, public token: CacheTokenService, private notificationService: NzNotificationService) { }
ngOnInit(): void {
- // var token = this.cookieService.get("token")
- // var refreshToken = this.cookieService.get("refreshToken");
- // if(token && refreshToken) {
- // this.http.post('/api/CompanyAccount/RefreshToken',{token: token,refreshToken: refreshToken}).subscribe((data: Data) => {
- // sessionStorage.setItem("token",data.token);
- // this.cookieService.set("token",data.token,null,'/');
- // this.cookieService.set("refreshToken",data.refreshToken,null,'/');
- // this.token.startUp()
- // })
- // }
-
- console.log(document.documentElement.clientWidth)
- console.log(document.documentElement.clientHeight)
+
}
ngAfterViewInit(): void {
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 6686fce..472dec3 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -13,7 +13,6 @@ import { HttpClientModule } from '@angular/common/http';
import { httpInterceptorProviders } from './http-interceptors/index'
import { CacheTokenService } from './service/cache-token.service'
import { TreeService } from './service/tree.service'
-import { CookieService } from 'ngx-cookie-service';//cookie插件
import { CountdownModule } from 'ngx-countdown'; //倒计时插件
import { NzNotificationModule } from 'ng-zorro-antd/notification';
import { NzMessageModule } from 'ng-zorro-antd/message';
@@ -36,7 +35,7 @@ import { NzMessageModule } from 'ng-zorro-antd/message';
NzNotificationModule,
NzMessageModule
],
- providers: [httpInterceptorProviders, CacheTokenService, TreeService, CookieService],
+ providers: [httpInterceptorProviders, CacheTokenService, TreeService],
bootstrap: [AppComponent]
})
export class AppModule { }
diff --git a/src/app/auth.guard.ts b/src/app/auth.guard.ts
index af4d216..823ac99 100644
--- a/src/app/auth.guard.ts
+++ b/src/app/auth.guard.ts
@@ -1,14 +1,13 @@
import { Component, OnInit, Inject } from '@angular/core';
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
-import { CookieService } from 'ngx-cookie-service';
@Injectable({
- providedIn: 'root'
+ providedIn: 'root'
})
export class AuthGuard implements CanActivate {
- constructor(private router: Router,private cookieService: CookieService) {
+ constructor(private router: Router) {
}
@@ -22,9 +21,8 @@ export class AuthGuard implements CanActivate {
}
checkLogin(): boolean {
- console.log('xxxxxxxxxxxx')
// 判断本地有没有token
- const token = this.cookieService.get("token") || sessionStorage.getItem('token');
+ const token = sessionStorage.getItem('token');
// 如果有token,允许访问
if (token) { return true; }
diff --git a/src/app/http-interceptors/base-interceptor.ts b/src/app/http-interceptors/base-interceptor.ts
index ffa2f93..b39d22a 100644
--- a/src/app/http-interceptors/base-interceptor.ts
+++ b/src/app/http-interceptors/base-interceptor.ts
@@ -7,7 +7,6 @@ import { throwError } from 'rxjs'
import { catchError } from 'rxjs/operators';
import { Router } from '@angular/router'
import { CacheTokenService } from '../service/cache-token.service'
-import { CookieService } from 'ngx-cookie-service';
import { NzMessageService } from 'ng-zorro-antd/message';
//baseurl
// const baseurl = 'http://39.106.78.171:8008';
@@ -15,10 +14,10 @@ import { NzMessageService } from 'ng-zorro-antd/message';
@Injectable()
export class BaseInterceptor implements HttpInterceptor {
- constructor(private router: Router, public token: CacheTokenService, private cookieService: CookieService, private message: NzMessageService) { }
+ constructor(private router: Router, public token: CacheTokenService, private message: NzMessageService) { }
intercept(req, next: HttpHandler) {
-
+
let params = req.params;
for (const key of req.params.keys()) {
if (params.get(key) === undefined || params.get(key) === null) {
@@ -26,14 +25,14 @@ export class BaseInterceptor implements HttpInterceptor {
}
}
req = req.clone({ params });
-// debugger
-// console.log('xxxxxx',req)
+ // debugger
+ // console.log('xxxxxx',req)
let newReq = req.clone({
url: req.hadBaseurl ? `${req.url}` : `${req.url}`,
});
if (!req.cancelToken) {
/*获取token*/
- let token = this.cookieService.get("token")
+ let token = sessionStorage.getItem("token")
/*此处设置额外请求头,token令牌*/
newReq.headers =
newReq.headers.set('Authorization', `Bearer ${token}`)
@@ -58,8 +57,6 @@ export class BaseInterceptor implements HttpInterceptor {
sessionStorage.clear()
// window.localStorage.clear()
localStorage.removeItem("isautologin")
- this.cookieService.set("token", '', new Date(new Date().getTime() + 1), '/')
- this.cookieService.set("refreshToken", '', new Date(new Date().getTime() + 1), '/')
this.message.create('error', `用户认证信息过期,请重新登录!`);
this.router.navigate(['/login'])
}
diff --git a/src/app/pages/home/home.component.html b/src/app/pages/home/home.component.html
index 32b4e32..2b1a6ed 100644
--- a/src/app/pages/home/home.component.html
+++ b/src/app/pages/home/home.component.html
@@ -89,4 +89,44 @@
忽略
-
\ No newline at end of file
+
+
+
+
+
+ 修改初始密码
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts
index 5ed864e..d332fd5 100644
--- a/src/app/pages/home/home.component.ts
+++ b/src/app/pages/home/home.component.ts
@@ -3,18 +3,19 @@ import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
import { NavChangeService } from '../../service/navChange.service';
import { CacheTokenService } from '../../service/cache-token.service' //引入服务
-import { CookieService } from 'ngx-cookie-service';
+
import { NzMessageService } from 'ng-zorro-antd/message';
import { SignalRAspNetCoreHelper } from '../../../shared/helpers/SignalRAspNetCoreHelper';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { GetOutOfLineDetailsComponent } from '../today-warning/get-out-of-line-details/get-out-of-line-details.component';
import { NzModalService } from 'ng-zorro-antd/modal';
import { HttpClient } from '@angular/common/http';
-import { ChangePasswordComponent } from '../change-password/change-password.component';
+import { ChangePasswordComponent, MyValidators } from '../change-password/change-password.component';
import { listRefreshService } from '../../service/listRefresh.service';
import { DisposeequipmentComponent } from '../warning-statistics-list/disposeequipment/disposeequipment.component';
declare var abp: any
import * as moment from 'moment';
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
@@ -22,8 +23,16 @@ import * as moment from 'moment';
})
export class HomeComponent implements OnInit {
@ViewChild('warning', { static: false }) template?: TemplateRef<{}>;
+ passwordValidateForm!: FormGroup;
constructor(private listRefreshService: listRefreshService, private http: HttpClient, private router: Router, private navChangeService: NavChangeService, public token: CacheTokenService,
- private cookieService: CookieService, private message: NzMessageService, private notificationService: NzNotificationService, private modal: NzModalService, private viewContainerRef: ViewContainerRef) { }
+ private message: NzMessageService, private notificationService: NzNotificationService, private modal: NzModalService, private viewContainerRef: ViewContainerRef, private fb: FormBuilder) {
+ const { password } = MyValidators;
+ this.passwordValidateForm = this.fb.group({
+ oldpassword: [null, [Validators.required]],
+ newpassword: [null, [Validators.required, password]],
+ affirmpassword: [null, [Validators.required, password]]
+ });
+ }
isGasStationNav: boolean
isGasStation: boolean
@@ -84,8 +93,44 @@ export class HomeComponent implements OnInit {
this.userName = JSON.parse(sessionStorage.getItem('userdata')).userName
}
+ this.changePasswordPopup()
+ }
+ //初次登陆修改密码弹窗
+ isVisible = false
+ isConfirmLoading = false
+ changePasswordPopup() {
+ this.isVisible = true
}
+ handleOk(): void {
+ console.log(this.passwordValidateForm)
+ if (this.passwordValidateForm.invalid) {
+ this.message.create('warning', `输入格式不正确`);
+ } else {
+ if (this.passwordValidateForm.value.newpassword != this.passwordValidateForm.value.affirmpassword) {
+ this.message.create('warning', '两次密码输入不一致!');
+ } else {
+ this.isConfirmLoading = true;
+ let body = {
+ currentPassword: this.passwordValidateForm.value.oldpassword,
+ newPassword: this.passwordValidateForm.value.newpassword
+ }
+ this.http.post('/api/services/app/User/ChangePassword', body).subscribe(data => {
+ this.message.create('success', '修改成功!');
+ this.isConfirmLoading = false;
+ this.isVisible = false;
+ //清除sessionStorage
+
+
+ }, err => {
+ this.message.create('warning', err.error.error.message);
+ this.isConfirmLoading = false;
+ })
+ }
+ }
+ }
+
+
reloadPage = (userNotification) => {
console.log('abp.notifications.received收到通知', userNotification);
@@ -111,7 +156,6 @@ export class HomeComponent implements OnInit {
}
this.messageId.push(obj)
}
- isVisible = false
modalData
look(item) {
@@ -305,11 +349,7 @@ export class HomeComponent implements OnInit {
this.message.create('success', `退出成功`);
this.token.delete()
sessionStorage.clear()
- // window.localStorage.clear()
-
localStorage.removeItem("isautologin")
- this.cookieService.set("token", '', new Date(new Date().getTime() + 1), '/');
- this.cookieService.set("refreshToken", '', new Date(new Date().getTime() + 1), '/');
this.router.navigate(['/login'])
}
diff --git a/src/app/pages/login/login.component.html b/src/app/pages/login/login.component.html
index 8fea242..c14a77a 100644
--- a/src/app/pages/login/login.component.html
+++ b/src/app/pages/login/login.component.html
@@ -2,7 +2,7 @@
-
+
-
-
diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts
index 4b99c36..a0086fa 100644
--- a/src/app/pages/login/login.component.ts
+++ b/src/app/pages/login/login.component.ts
@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { Router, ActivatedRoute } from '@angular/router'
import { CacheTokenService } from '../../service/cache-token.service'//引入服务
-import { CookieService } from 'ngx-cookie-service';//cookie插件
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Base64 } from 'js-base64';
@@ -19,7 +18,8 @@ declare var abp: any
export class LoginComponent implements OnInit {
validateForm!: FormGroup;
- constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute, public token: CacheTokenService, private cookieService: CookieService, private fb: FormBuilder, private message: NzMessageService, private notificationService: NzNotificationService) {
+ passwordValidateForm!: FormGroup;
+ constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute, public token: CacheTokenService, private fb: FormBuilder, private message: NzMessageService, private notificationService: NzNotificationService) {
const { password } = MyValidators;
this.validateForm = this.fb.group({
userName: [null, [Validators.required]],
@@ -27,6 +27,11 @@ export class LoginComponent implements OnInit {
remember: [null],
autologin: [null],
});
+ this.passwordValidateForm = this.fb.group({
+ oldpassword: [null, [Validators.required]],
+ newpassword: [null, [Validators.required, password]],
+ affirmpassword: [null, [Validators.required, password]]
+ });
}
ngOnInit() {
@@ -51,14 +56,11 @@ export class LoginComponent implements OnInit {
errmsg: string = ''; //错误信息
-
-
//跳转注册页面
toRegister() {
this.router.navigate(['/register'])
}
-
//记住密码
rememberInfo() {
// 判断用户是否勾选记住密码,如果勾选,在本地储存中储存登录信息
@@ -74,9 +76,6 @@ export class LoginComponent implements OnInit {
}
}
-
-
-
remember: any//记住密码
autologin: any//自动登录
isLoading = false;
@@ -108,11 +107,10 @@ export class LoginComponent implements OnInit {
}).subscribe(
(data: any) => {
sessionStorage.setItem("token", data.result.accessToken);
- this.cookieService.set("token", data.result.accessToken, null, '/');
- this.cookieService.set("refreshToken", data.result.encryptedAccessToken, null, '/');
sessionStorage.setItem("encryptedAccessToken", data.result.encryptedAccessToken);
- console.log('token', data)
+ console.log('token', data.result)
this.http.get('/api/services/app/Session/GetCurrentLoginInformations').subscribe((data: any) => {
+ console.log('GetCurrentLoginInformations', data.result)
sessionStorage.setItem('userdata', JSON.stringify(data.result.user))
sessionStorage.setItem('userdataOfgasstation', JSON.stringify(data.result.user))
this.isLoading = false;
@@ -129,10 +127,12 @@ export class LoginComponent implements OnInit {
sessionStorage.setItem("isGasStation", 'true');
this.router.navigate(['/todaywarning/petrolStation'])
this.message.create('success', `登录成功`);
+
} else {
sessionStorage.setItem("isGasStation", 'false');
this.router.navigate(['/homepage'])
this.message.create('success', `登录成功`);
+
}
}
}, err => {
@@ -149,17 +149,12 @@ export class LoginComponent implements OnInit {
)
}
- roleList = [
- '管理员', '职工'
- ]
-
- selectedRole: string
- selecteRole(role) {
- this.selectedRole = role
- }
forget() {
this.message.create('warning', `请联系管理员`);
}
+
+
+
}
export type MyErrorsOptions = { 'zh-cn': string; en: string } & Record;
export type MyValidationErrors = Record;
diff --git a/src/app/service/cache-token.service.ts b/src/app/service/cache-token.service.ts
index 2f8cf64..22e220e 100644
--- a/src/app/service/cache-token.service.ts
+++ b/src/app/service/cache-token.service.ts
@@ -1,31 +1,28 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
-import { CookieService } from 'ngx-cookie-service';
@Injectable({
providedIn: 'root'
})
export class CacheTokenService {
- constructor(private http:HttpClient,private cookieService: CookieService) { }
+ constructor(private http: HttpClient) { }
public timer;
//刷新token令牌定时器
- startUp = ():void=>{
+ startUp = (): void => {
window.clearInterval(this.timer)
- this.timer = window.setInterval( ()=>{
- var token = this.cookieService.get("token");
- var refreshToken = this.cookieService.get("refreshToken");
+ this.timer = window.setInterval(() => {
+ var token = sessionStorage.getItem("token");
+ var refreshToken = sessionStorage.getItem("refreshToken");
this.http.post('/api/CompanyAccount/RefreshToken', {
- token: token,
- refreshToken: refreshToken
- }).subscribe( (data:any) => {
- sessionStorage.setItem("token",data.token);
- this.cookieService.set("token",data.token,null,'/');
- this.cookieService.set("refreshToken",data.refreshToken,null,'/');
+ token: token,
+ refreshToken: refreshToken
+ }).subscribe((data: any) => {
+ sessionStorage.setItem("token", data.token);
})
- } ,18*60*1000)
+ }, 18 * 60 * 1000)
}
@@ -33,12 +30,12 @@ export class CacheTokenService {
//删除定时器
- delete = ():void=> {
+ delete = (): void => {
window.clearInterval(this.timer)
}
- createTime = (time:string)=>{
- var newtime = time.substr(0,4) + '年' + time.substr(5,2) + '月' + time.substr(8,2) + '日' + time.substr(11,8)
+ createTime = (time: string) => {
+ var newtime = time.substr(0, 4) + '年' + time.substr(5, 2) + '月' + time.substr(8, 2) + '日' + time.substr(11, 8)
}
}
diff --git a/src/app/ui/tabbar/tabbar.component.ts b/src/app/ui/tabbar/tabbar.component.ts
index b4ae5b2..f32254f 100644
--- a/src/app/ui/tabbar/tabbar.component.ts
+++ b/src/app/ui/tabbar/tabbar.component.ts
@@ -2,8 +2,6 @@ import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { Router, ActivatedRoute } from '@angular/router'
import { CacheTokenService } from '../../service/cache-token.service' //引入服务
-import { ChangepasswordComponent } from '../changepassword/changepassword.component'
-import { CookieService } from 'ngx-cookie-service';
import { NzMessageService } from 'ng-zorro-antd/message';
@@ -15,7 +13,7 @@ import { NzMessageService } from 'ng-zorro-antd/message';
export class TabbarComponent implements OnInit {
constructor(private http: HttpClient, private router: Router, private route: ActivatedRoute, public token: CacheTokenService,
- private cookieService: CookieService, private message: NzMessageService) { }
+ private message: NzMessageService) { }
surname: string
userName: string
isGasStation: string
@@ -24,15 +22,15 @@ export class TabbarComponent implements OnInit {
this.getTime()
}, 1000);
this.isGasStation = JSON.parse(sessionStorage.getItem('isGasStation'))
- if(this.isGasStation == 'true'){
+ if (this.isGasStation == 'true') {
this.surname = JSON.parse(sessionStorage.getItem('userdataOfgasstation')).name
this.userName = JSON.parse(sessionStorage.getItem('userdataOfgasstation')).userName
- }else{
+ } else {
this.surname = JSON.parse(sessionStorage.getItem('userdata')).name
this.userName = JSON.parse(sessionStorage.getItem('userdata')).userName
}
-
-
+
+
}
//获得时间
@@ -69,8 +67,6 @@ export class TabbarComponent implements OnInit {
// window.localStorage.clear()
localStorage.removeItem("isautologin")
- this.cookieService.set("token", '', new Date(new Date().getTime() + 1), '/');
- this.cookieService.set("refreshToken", '', new Date(new Date().getTime() + 1), '/');
this.router.navigate(['/login'])
}