Browse Source

[合并]合并代码

master
邵佳豪 5 years ago
parent
commit
dad7d0d505
  1. 4
      src/app/app.component.ts
  2. 16
      src/app/http-interceptors/cache-token.service.ts
  3. 4
      src/app/is-login.service.ts
  4. 4
      src/app/tabbar/tabbar.component.html
  5. 20
      src/app/tabbar/tabbar.component.ts
  6. 8
      src/app/ui/all-file/all-file.component.html
  7. 28
      src/app/ui/all-file/all-file.component.ts
  8. 19
      src/app/ui/changepassword/changepassword.component.ts
  9. 1
      src/app/ui/changepassword/equal-validator.directive.ts
  10. 7
      src/app/ui/login/login.component.ts

4
src/app/app.component.ts

@ -31,6 +31,10 @@ export class AppComponent {
this.isLogin.isLogin = true
this.token.startUp()
})
} else {
sessionStorage.clear()
this.isLogin.isLogin = false
this.token.delete()
}
}

16
src/app/http-interceptors/cache-token.service.ts

@ -16,13 +16,15 @@ export class CacheTokenService {
this.timer = window.setInterval(()=>{
var token = sessionStorage.getItem("token");
var refreshToken = sessionStorage.getItem("refreshToken");
this.http.post('/api/Account/RefreshToken', {
token: token,
refreshToken: refreshToken,
}).subscribe((data:any) => {
sessionStorage.setItem("token",data.token);
sessionStorage.setItem("refreshToken",data.refreshToken);
})
if (token && refreshToken) {
this.http.post('/api/Account/RefreshToken', {
token: token,
refreshToken: refreshToken,
}).subscribe((data:any) => {
sessionStorage.setItem("token",data.token);
sessionStorage.setItem("refreshToken",data.refreshToken);
})
} else { this.delete() }
},18*60*1000)
}

4
src/app/is-login.service.ts

@ -19,7 +19,7 @@ export class IsLoginService {
let shardSize = 10 * 1024 * 1024 //文件大小是否大于10MB
if (file && fileSize<=shardSize) { //<=10MB时直接下载
this.http.get(`/api/Objects/PlanPlatform/${file.objectName}`,{responseType: 'blob'},).subscribe(data=>{
this.http.get(`/api/Objects/drives/${file.objectName}`,{responseType: 'blob'},).subscribe(data=>{
let url = window.URL.createObjectURL(new Blob([data])); //createObjectURL创建一个下载Blob的url地址
let link = document.createElement("a");
link.style.display = "none";
@ -47,7 +47,7 @@ export class IsLoginService {
let end = Math.min(fileSize, start + shardSize-1); //每次下载文件结束为止
let result = await new Promise ((result,reject)=>{
this.http.get(`/api/Objects/PlanPlatform/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{
this.http.get(`/api/Objects/drives/${file.objectName}`,{headers:{'range':`bytes= ${start}-${end}`},responseType:'blob'}).subscribe(data=>{
result(data) })
})
allFile.push(result)

4
src/app/tabbar/tabbar.component.html

@ -13,10 +13,10 @@
<mat-icon>account_circle</mat-icon>
</button>
<mat-menu #appMenu="matMenu">
<button mat-menu-item (click)='changeUserData()'>
<!-- <button mat-menu-item (click)='changeUserData()'>
<mat-icon>perm_identity</mat-icon>
<span>修改资料</span>
</button>
</button> -->
<button mat-menu-item (click)='changPassword()'>
<mat-icon>verified_user</mat-icon>
<span>修改密码</span>

20
src/app/tabbar/tabbar.component.ts

@ -7,6 +7,7 @@ import {ChangeuserdataComponent} from '../ui/changeuserdata/changeuserdata.compo
import {LoginComponent} from '../ui/login/login.component'
import {CacheTokenService} from '../http-interceptors/cache-token.service'//引入服务
import {IsLoginService} from '../is-login.service'//引入服务
import { MatSnackBarConfig, MatSnackBar } from '@angular/material/snack-bar';
@ -27,7 +28,7 @@ export class TabbarComponent implements OnInit {
@Output()
redtheme = new EventEmitter<boolean>();
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public dialog: MatDialog,public isLogin:IsLoginService) { }
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public dialog: MatDialog,public isLogin:IsLoginService,public snackBar: MatSnackBar,) { }
ngOnInit() {
@ -38,9 +39,7 @@ export class TabbarComponent implements OnInit {
//登录系统
login () {
let dialogRef = this.dialog.open(LoginComponent);
dialogRef.afterClosed().subscribe( data=>{
} );
dialogRef.afterClosed().subscribe();
}
@ -49,8 +48,17 @@ export class TabbarComponent implements OnInit {
signOut () {
let out = confirm("您确定要退出吗")
if(out) {
}
this.http.post('/api/Account/SignOut',{}).subscribe(data=>{
sessionStorage.clear()
this.isLogin.isLogin = false
this.token.delete()
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('退出成功','确定',config);
})
} //if
}
//修改用户资料

8
src/app/ui/all-file/all-file.component.html

@ -69,7 +69,7 @@
</div>
</div>
<div class="mainbox">
<table style="width: 100%;" mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8">
<table style="width: 100%;" mat-table [dataSource]="dataSource" matSort (matSortChange)="sortData($event)" class="mat-elevation-z8">
<ng-container matColumnDef="select">
<th style="width: 4%;" mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? masterToggle() : null"
@ -88,7 +88,7 @@
</ng-container>
<ng-container matColumnDef="name">
<th style="width: 63%;" mat-header-cell *matHeaderCellDef mat-sort-header> 文件名 </th>
<th style="width: 63%;" mat-header-cell *matHeaderCellDef> 文件名 </th>
<td mat-cell *matCellDef="let element">
<img *ngIf="element.type == 'pdf'" src="../../../assets/images/pdf.png" alt="">
<img *ngIf="element.type == 'jpeg' || element.type == 'jpg' || element.type == 'png'" src="../../../assets/images/img.png" alt="">
@ -108,13 +108,13 @@
</ng-container>
<ng-container matColumnDef="weight">
<th mat-header-cell style="width: 15%;" *matHeaderCellDef mat-sort-header> 大小 </th>
<th mat-header-cell style="width: 15%;" *matHeaderCellDef> 大小 </th>
<td mat-cell *matCellDef="let element"> {{element.size | size}} </td>
</ng-container>
<ng-container matColumnDef="time">
<th style="width: 18%;" mat-header-cell *matHeaderCellDef mat-sort-header> 修改日期 </th>
<td mat-cell *matCellDef="let element"> {{element.lastModified | date:'yyyy-MM-dd'}} </td>
<td mat-cell *matCellDef="let element"> {{element.lastModified | date:'yyyy-MM-dd HH:mm:ss'}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>

28
src/app/ui/all-file/all-file.component.ts

@ -29,6 +29,30 @@ export class AllFileComponent implements OnInit {
selection = new SelectionModel(true, []);
@ViewChild(MatSort) sort: MatSort;
oldDataSource:any; //原始表格数据
//表头排序
sortData (e) {
let data = this.oldDataSource.concat();
data.forEach(element => {
let typeArr = element.key.split('.')
element.type = typeArr[typeArr.length - 1]
element.newTime = new Date(element.lastModified).getTime()
});
if( e.direction=='asc' ) { //从小到大排序
data.sort( function(a,b) {
return a.newTime - b.newTime
} )
this.dataSource = new MatTableDataSource(data);
} else if ( e.direction=='desc' ) {//从大到小排序
data.sort( function(a,b) {
return b.newTime - a.newTime
} )
this.dataSource = new MatTableDataSource(data);
} else { //原始数据
this.dataSource = new MatTableDataSource(this.oldDataSource);
}
}
ngOnInit(): void {
this.dataSource.sort = this.sort;
@ -55,15 +79,13 @@ export class AllFileComponent implements OnInit {
this.http.get(`/api/Objects/drives`,{
params:paramsdata
}).subscribe((data:any) => {
// console.log(data)
this.oldDataSource = data.contents //保存表格数据
data.contents.forEach((item)=>{
let typeArr = item.key.split('.')
item.type = typeArr[typeArr.length - 1]
})
this.dataSource = new MatTableDataSource(data.contents);
this.dataSource.sort = this.sort;
this.fileNum = data.contents.length
if(data.contents.length == 0){
this.isNoFileTitle = true

19
src/app/ui/changepassword/changepassword.component.ts

@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { MatDialogRef } from '@angular/material/dialog';
import { MatSnackBarConfig, MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-changepassword',
@ -10,7 +11,7 @@ import { MatDialogRef } from '@angular/material/dialog';
export class ChangepasswordComponent implements OnInit {
constructor(private http:HttpClient,
constructor(private http:HttpClient,public snackBar: MatSnackBar,
public dialogRef: MatDialogRef<ChangepasswordComponent>) { }
ngOnInit() {
@ -18,14 +19,14 @@ export class ChangepasswordComponent implements OnInit {
errmsg :string = ''
onSubmit(e){
this.http.put(
'/api/Account/Password',
{
newPassword: e.newPassword,
password: e.password
}
).subscribe(data=> {
alert('密码修改成功')
this.http.put('/api/Account/Password', {
password: e.password,
newPassword: e.newPassword,
}).subscribe(data=> {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('密码修改成功','确定',config);
this.dialogRef.close(data);
},(err) =>
{this.errmsg = err}

1
src/app/ui/changepassword/equal-validator.directive.ts

@ -16,7 +16,6 @@ export class ConfirmpswDirective implements Validator {
}
validate(control: AbstractControl): {[key: string]: any} {
console.log(this.confirmpsw);
return this.confirmpsw ? comfirmPswValidator(this.confirmpsw)(control) : null;
}
}

7
src/app/ui/login/login.component.ts

@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { IsLoginService } from '../../is-login.service'
import { CacheTokenService } from '../../http-interceptors/cache-token.service'
import { MatDialogRef } from '@angular/material/dialog';
import { MatSnackBarConfig, MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-login',
@ -11,7 +12,7 @@ import { MatDialogRef } from '@angular/material/dialog';
})
export class LoginComponent implements OnInit {
constructor(private http:HttpClient,private isLogin:IsLoginService,private token:CacheTokenService,public dialogRef: MatDialogRef<any>) { }
constructor(private http:HttpClient,private isLogin:IsLoginService,private token:CacheTokenService,public dialogRef: MatDialogRef<any>,public snackBar: MatSnackBar) { }
ngOnInit(): void {
@ -30,6 +31,10 @@ export class LoginComponent implements OnInit {
sessionStorage.setItem("refreshToken",data.refreshToken);
this.isLogin.isLogin = true; //登陆成功设置登录状态为true
this.token.startUp(); //登陆成功启动定时器刷新token
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('登陆成功','确定',config);
this.dialogRef.close(data);
},(err) => {this.errmsg = err})

Loading…
Cancel
Save