Browse Source

[完善]学习平台初步搭建完善

master
陈鹏飞 5 years ago
parent
commit
7e63df4c17
  1. 46
      package-lock.json
  2. 2
      package.json
  3. 12
      src/app/app-routing.module.ts
  4. 52
      src/app/app.component.ts
  5. 22
      src/app/http-interceptors/base-interceptor.ts
  6. 95
      src/app/http-interceptors/cache-token.service.ts
  7. 4
      src/app/navigation/navigation.component.html
  8. 14
      src/app/navigation/navigation.component.ts
  9. 5
      src/app/pages/lockscreen/lockscreen.component.ts
  10. 1
      src/app/pages/login/login.component.ts
  11. 18
      src/app/tabbar/tabbar.component.html
  12. 2
      src/app/ui/all-file/all-file.component.html
  13. 6
      src/index.html
  14. 46
      src/styles.scss

46
package-lock.json generated

@ -15968,8 +15968,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -16012,8 +16011,7 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
@ -16024,8 +16022,7 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -16142,8 +16139,7 @@
"inherits": {
"version": "2.0.4",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -16155,7 +16151,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -16185,7 +16180,6 @@
"version": "2.9.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -16204,7 +16198,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -16307,7 +16300,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -16393,8 +16385,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -16430,7 +16421,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -16450,7 +16440,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -16494,14 +16483,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -16939,8 +16926,7 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -17057,8 +17043,7 @@
"inherits": {
"version": "2.0.4",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -17100,7 +17085,6 @@
"version": "2.9.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -17119,7 +17103,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -17222,7 +17205,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -17308,8 +17290,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -17345,7 +17326,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -17409,14 +17389,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},

2
package.json

@ -3,7 +3,7 @@
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json --open --port 4000 ",
"start": "ng serve --proxy-config proxy.config.json --open --port 4100 ",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",

12
src/app/app-routing.module.ts

@ -11,20 +11,14 @@ import {AuthGuard} from './auth.guard'
const routes: Routes = [
{path:'',redirectTo:'login',pathMatch:'full'},
{
path:'',
component:NavigationComponent,
canActivate: [AuthGuard],//守卫验证
children:[
{path:'datacollection',loadChildren:() => import('./ui/ui.module').then(m => m.UiModule)}
]},
{path:'',loadChildren:() => import('./ui/ui.module').then(m => m.UiModule)}
]
},
{path:'login',
component:LoginComponent}, //登录页
{path:'register',
component:RegisterComponent,}, //注册页
];
@NgModule({

52
src/app/app.component.ts

@ -3,61 +3,23 @@ import { HttpClient } from '@angular/common/http'
import { Data } from './interface'
import { Router,ActivatedRoute } from '@angular/router'
import {CacheTokenService} from './http-interceptors/cache-token.service'//引入服务
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = '数字化预案编制管理平台';
constructor(private http:HttpClient,private router:Router,public token:CacheTokenService) { }
ngOnInit(): void {
var isnologin = localStorage.getItem("isnologin")
//七天免登录
if(isnologin){
var token = localStorage.getItem("token");
var refreshToken = localStorage.getItem("refreshToken");
this.http.post(
'/api/Account/RefreshToken',
{
token: token,
refreshToken: refreshToken
}
).subscribe(
(data: Data) => {
sessionStorage.setItem("token",data.token);
sessionStorage.setItem("refreshToken",data.refreshToken);
this.token.getmenus()
this.token.startUp()
this.router.navigate(['/ui/person'])
console.log('已自动登录')
}
)
}else{
var token = sessionStorage.getItem("token");
var refreshToken = sessionStorage.getItem("refreshToken");
if(token && refreshToken) {
this.http.post(
'/api/Account/RefreshToken',
{
token: token,
refreshToken: refreshToken
}
).subscribe(
(data: Data) => {
sessionStorage.setItem("token",data.token);
sessionStorage.setItem("refreshToken",data.refreshToken);
this.token.getmenus()
this.token.startUp()
console.log('已重启定时器')
}
)
}
}
}
}

22
src/app/http-interceptors/base-interceptor.ts

@ -6,8 +6,8 @@ import {
import { throwError } from 'rxjs'
import { catchError, retry } from 'rxjs/operators';
import { Router,ActivatedRoute } from '@angular/router'
import {CacheTokenService} from './cache-token.service'
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
//baseurl
// const baseurl = 'http://39.106.78.171:8008';
@ -15,7 +15,7 @@ import {CacheTokenService} from './cache-token.service'
@Injectable()
export class BaseInterceptor implements HttpInterceptor {
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService) {}
constructor(private http:HttpClient,private router:Router,private route:ActivatedRoute,public token:CacheTokenService,public snackBar: MatSnackBar) {}
intercept(req, next: HttpHandler) {
@ -24,7 +24,7 @@ export class BaseInterceptor implements HttpInterceptor {
});
if(!req.cancelToken) {
/*获取token*/
let token = sessionStorage.getItem("token")
let token = sessionStorage.getItem("token") || ''
/*此处设置额外请求头,token令牌*/
newReq.headers =
newReq.headers.set('Authorization', `Bearer ${token}`)
@ -47,11 +47,23 @@ export class BaseInterceptor implements HttpInterceptor {
this.token.delete()
sessionStorage.clear()
window.localStorage.clear()
alert('用户认证信息过期,请重新登录')
this.router.navigate(['/login'])
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('用户认证信息过期,请重新登录','确定',config);
}
if (error.status === 403) {
alert('对不起,您无此权限')
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('对不起,您无此权限','确定',config);
}
if (error.status === 400) {
const config = new MatSnackBarConfig();
config.verticalPosition = 'top';
config.duration = 3000
this.snackBar.open('请核对您的输入格式是否正确','确定',config);
}
if (error.error instanceof ErrorEvent) {

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

@ -9,108 +9,15 @@ export class CacheTokenService {
constructor(private http:HttpClient) { }
public timer;
public settime = null;
//刷新token令牌定时器
startUp = ():void=>{
// this.getmenus();
this.timer = window.setInterval(
()=>{
window.clearInterval(this.settime)
var token = sessionStorage.getItem("token");
var refreshToken = sessionStorage.getItem("refreshToken");
this.http.post(
'/api/Account/RefreshToken',
{
token: token,
refreshToken: refreshToken
}
).subscribe(
(data:any) => {
console.log(data)
sessionStorage.setItem("token",data.token);
sessionStorage.setItem("refreshToken",data.refreshToken);
}
)
}
,18*60*1000)
}
organization = false;//组织机构管理
un = false;//单位类型管理
unit = false;//单位类型
unitmessage = false;//单位基本信息模板
fireelement = false;//消防要素管理
power = false;//权限管理
datapower = false;//数据权限管理
menuspower = false;//导航菜单管理
role = false;//角色管理
user = false;//用户管理
matlibrary = false//素材库管理
getmenus = ():void=>{
this.http.get('/api/Account/NavMenus').subscribe((data:any)=>{
data.forEach(item => {
if(item.id == "5e4cd3c4146bea9014968113"){//组织机构管理
this.organization = true
}
if(item.id == "5e4cd85b146bea9014968119"){//单位类型管理
this.un = true
this.unit = true
this.unitmessage = true;//单位基本信息模板
this.fireelement = true;//消防要素管理
}
if(item.id == "5e4cd877146bea901496811a"){//权限管理
this.power = true;//权限管理
this.datapower = true;//数据权限管理
this.menuspower = true;//导航菜单管理
}
if(item.id == "5e4cd96e146bea901496811d"){//单位类型
this.un = true
this.unit = true
}
if(item.id == "5e4cd994146bea901496811e"){//单位基本信息模板
this.un = true
this.unitmessage = true
}
if(item.id == "5e4cd9a8146bea901496811f"){//消防要素管理
this.un = true
this.fireelement = true
}
if(item.id == "5e4cd9d8146bea9014968120"){//数据权限管理
this.power = true
this.datapower = true
}
if(item.id == "5e4cd9ec146bea9014968121"){//导航菜单管理
this.power = true
this.menuspower = true
}
if(item.id == "5e4cd883146bea901496811b"){//角色管理
this.role = true
}
if(item.id == "5e4cd88d146bea901496811c"){//用户管理
this.user = true
}
if(item.id == "5e5cb11948374f5264e46e84"){//素材库管理
this.matlibrary = true
}
});
// console.log(777,this.user,this.organization,this.power)
})
}
//删除定时器
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)
}
}

4
src/app/navigation/navigation.component.html

@ -12,9 +12,9 @@
</div>
</mat-sidenav>
<button type="button" mat-button (click)="drawer.toggle()" class="shownav">
<!-- <button type="button" mat-button (click)="drawer.toggle()" class="shownav">
<mat-icon>menu</mat-icon>
</button>
</button> -->
<div class="example-sidenav-content">

14
src/app/navigation/navigation.component.ts

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import {CacheTokenService} from '../http-interceptors/cache-token.service'//引入服务
@Component({
selector: 'app-navigation',
templateUrl: './navigation.component.html',
@ -13,21 +13,21 @@ export class NavigationComponent implements OnInit {
ngOnInit() {
}
ngOnDestroy(){
}
darktheme = false;
switchTheme(dark) {
this.darktheme = dark;
// alert(this.darkTheme);
}
defaulttheme(){
console.log(111)
this.darktheme = false
}
redtheme(){
console.log(222)
this.darktheme = true
}
}

5
src/app/pages/lockscreen/lockscreen.component.ts

@ -13,9 +13,6 @@ export class LockscreenComponent implements OnInit {
ngOnInit() {
}
open(){
if(this.password == "12345678"){
this.getMenus.getmenus()
this.router.navigate(['/ui/organization'])
}
}
}

1
src/app/pages/login/login.component.ts

@ -47,7 +47,6 @@ export class LoginComponent implements OnInit {
//调用服务中的function刷新token
this.token.startUp()
//调用服务中的function获取菜单
this.token.getmenus()
},
(err) =>
{this.errmsg = err}

18
src/app/tabbar/tabbar.component.html

@ -3,24 +3,24 @@
<h1>用户信息采集平台</h1>
<!-- 全屏 -->
<button mat-button (click)="!isfullscreen?fullscreenToggle():closefullscreen()" class="fullscreen">
<!-- <button mat-button (click)="!isfullscreen?fullscreenToggle():closefullscreen()" class="fullscreen">
<ng-container *ngIf="!isfullscreen; else elseTemplate">
<mat-icon *ngIf="!isfullscreen">fullscreen</mat-icon>
</ng-container>
<ng-template #elseTemplate>
<mat-icon else>fullscreen_exit</mat-icon>
</ng-template>
</button>
</button> -->
<!-- 黑夜模式开关 -->
<mat-slide-toggle (change)='onChange($event.checked)' class="darktheme"></mat-slide-toggle>
<!-- <mat-slide-toggle (change)='onChange($event.checked)' class="darktheme"></mat-slide-toggle> -->
<!-- 锁屏按钮 -->
<button mat-button class="lockscreen" [routerLink]="['/lockscreen']" routerLinkActive="router-link-active" >
<!-- <button mat-button class="lockscreen" [routerLink]="['/lockscreen']" routerLinkActive="router-link-active" >
<mat-icon>screen_lock_landscape</mat-icon>
</button>
</button> -->
<!-- 登录信息按钮 -->
<button mat-icon-button [matMenuTriggerFor]="appMenu" class="login">
<!-- <button mat-icon-button [matMenuTriggerFor]="appMenu" class="login">
<mat-icon>account_circle</mat-icon>
</button>
<mat-menu #appMenu="matMenu">
@ -36,10 +36,10 @@
<mat-icon>power_settings_new</mat-icon>
<span>退出系统</span>
</button>
</mat-menu>
</mat-menu> -->
<!-- 设置按钮 -->
<button mat-icon-button [matMenuTriggerFor]="appSet" class="setting">
<!-- <button mat-icon-button [matMenuTriggerFor]="appSet" class="setting">
<mat-icon>settings</mat-icon>
</button>
<mat-menu #appSet="matMenu" yPosition="below" xPosition="after">
@ -59,5 +59,5 @@
<mat-icon>laptop</mat-icon>
<span>盒子模式</span>
</button>
</mat-menu>
</mat-menu> -->
</mat-toolbar>

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

@ -1 +1 @@
<p>all-file works!</p>
<p>qaq</p>

6
src/index.html

@ -1,8 +1,8 @@
<!doctype html>
<html lang="en">
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>数字化预案编制管理平台</title>
<title>学习演练平台</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
@ -11,6 +11,4 @@
<body>
<app-root></app-root>
</body>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=04743eb4bbbdf60376851bb776c3dcdc"></script>
</html>

46
src/styles.scss

@ -1,15 +1,15 @@
// @import "~@angular/material/prebuilt-themes/indigo-pink.css";
@import './app/theme.scss';
html,body,ul,ol,dl,li,dt,dd,p,form,input,h1,h2,h3,h4,h5,h6,section,article,aside,header,footer,nav,figure,time,mark,main,canvas{
height:100%;
margin:0;
html,body{
width: 100%;
height: 100%;
margin:0 auto;
padding:0;
}
body{
margin: 0 auto;
ul,ol,dl,li,dt,dd,p,form,input,h1,h2,h3,h4,h5,h6,section,article,aside,header,footer,nav,figure,time,mark,main,canvas{
margin:0;
padding:0;
}
b,strong,i,em,h1,h2,h3,h4,h5,h6{
font-weight:500;
@ -20,7 +20,8 @@ img{
}
a{
text-decoration: none;
color:#000;
color:#000;
}
ul,ol,li{
list-style:none;
overflow-x: hidden;
@ -33,17 +34,17 @@ ul,ol,li{
height:0;
visibility: hidden;
}
}
.mat-expansion-panel-body {
padding: 0px !important;
}
//root标签
app-root{
height: 100%;
}
h1{
font-size: 16px;
}
.mat-expansion-panel-body {
padding: 0px !important;
}
.mat-expansion-indicator::after {
color: white;
}
@ -54,8 +55,27 @@ table th.mat-header-cell:last-of-type,table td.mat-cell:last-of-type,
table td.mat-footer-cell:last-of-type{
padding-right: 0px;
}
.mat-tab-body{
height: 100%;
overflow-y: auto;
}
.mat-content { //可展开面板垂直居中
align-items: center;
}
//x轴滚动条隐藏
.example-sidenav-content {
overflow-x: hidden; overflow-y: auto;
}
.mat-tab-body-wrapper{
height: 100%;
}
.mat-tab-body-content{
overflow: hidden!important;
// text-align: center;
}
Loading…
Cancel
Save