Commit f279db0d authored by van.chen's avatar van.chen

最小化稳定版本

parent 8ba0c4fd
......@@ -3,7 +3,7 @@ import {Routes, RouterModule, PreloadAllModules} from '@angular/router';
import { AuthService } from './service/auth.service';
const routes: Routes = [
{ path: '', redirectTo: 'extra', pathMatch: 'full' },
{ path: '', redirectTo: 'main', pathMatch: 'full' },
{ path: 'main', canActivateChild: [AuthService], loadChildren: './home/home.module#HomePageModule'},
{ path: 'extra', loadChildren: './extra/extra.module#ExtraPageModule'},
];
......
......@@ -32,6 +32,7 @@ export class AppComponent {
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.statusBar.backgroundColorByHexString('#ffffffff');
this.splashScreen.hide();
this.registerBackButtonAction(); // 注册返回按键事件
this.platform.resume.subscribe(); // 弹出框
......@@ -61,10 +62,12 @@ export class AppComponent {
registerBackButtonAction() {
this.platform.backButton.subscribe((event) => {
if (this.url === '/main/index' || this.url === '/extra') {
if (this.url === '/main' || this.url === '/extra') {
if (this.backBtnPressed) {
this.appMinimize.minimize();
this.backBtnPressed = false;
window.history.pushState('forward', null, this.url);
// window.history.forward();
return;
} else {
this.backBtnPressed = true;
......
......@@ -12,6 +12,6 @@
<div class="labelForInput">密码</div>
<ion-input type="password" [(ngModel)]="req.ps" mode="ios" class="input"></ion-input>
</div>
<ion-button mode="ios" color="primary" expand="full" class="loginBtn" (click)="login()">Login</ion-button>
<ion-button mode="ios" color="primary" expand="block" class="loginBtn" (click)="login()">Login</ion-button>
</div>
</div>
......@@ -34,6 +34,7 @@
.inputLine {
padding-top: 8%;
border-bottom: 2px solid #1890ff;
margin: 0 1%;
}
.labelForInput {
......
......@@ -29,12 +29,12 @@ export class LoginComponent implements OnInit {
this.tf.transfer({
from: 'app-extra',
to: 'app-home',
url: '/main/index',
url: '/main',
query: '',
hash: ''
});
} else {
// message
this.api.presentMsgToast(data && data.message ? data.message : '登录失败');
}
}]);
}
......
......@@ -17,7 +17,7 @@ import {PageDetailComponent} from '../main/page-detail/page-detail.component';
IonicModule,
RouterModule.forChild([
{
path: 'index',
path: '',
component: HomePage
},
{
......
......@@ -20,7 +20,7 @@ export class PageDetailComponent implements OnInit {
this.tf.transfer({
from: 'app-page-detail',
to: 'app-home',
url: '/main/index',
url: '/main',
query: '',
hash: 'page_two'
});
......
<div class="personSet">
<div class="topBar">
<img class="imgPart" src="../../../assets/icon/favicon.png">
<div class="imgPart">
<img src="../../../assets/icon/favicon.png">
</div>
<div class="topRight">1111111</div>
</div>
<ion-button mode="ios" color="primary" expand="full" class="loginBtn" (click)="getSelfInfo()">getSelfInfo</ion-button>
......
import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../service/api.service';
import { TransferService } from '../../service/transfer.service';
@Component({
selector: 'app-page-four',
......@@ -10,7 +11,7 @@ export class PageFourComponent implements OnInit {
req: any = {};
resp: any = '';
constructor(private api: ApiService) { }
constructor(private api: ApiService, private tf: TransferService) { }
ngOnInit() {}
......@@ -23,8 +24,9 @@ export class PageFourComponent implements OnInit {
if (data) {
console.log(data);
this.resp = JSON.stringify(data);
} else {
this.api.presentMsgToast(data && data.message ? data.message : '登录失败');
}
}]);
}
}
......@@ -2,10 +2,11 @@ import { HttpService } from './http.service';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { environment } from '../../environments/environment';
import { ToastController } from '@ionic/angular';
@Injectable()
export class ApiService {
constructor(private http: HttpService, private router: Router) {
constructor(private http: HttpService, private router: Router, private toast: ToastController) {
}
tokenLoseflag = 0;
......@@ -43,7 +44,7 @@ export class ApiService {
next(data);
} else {
if (!this.tokenLoseflag) {
// this.message.error(this.translate.instant('loginOutValidityTips'));
this.presentMsgToast('登录失效,请重新登陆');
this.http.toLoginPage(2000);
this.tokenLoseflag = 1;
setTimeout(() => {
......@@ -55,18 +56,18 @@ export class ApiService {
}
if (!error) {
error = (err) => {
// const data;
let data;
if (err && err.error && err.error.status) {
if (err.error.status === 401) {
// data = {code: 0, message: this.translate.instant('noLoginTips')};
data = {code: 0, message: '用户尚未登录'};
this.router.navigate(['/extra']);
} else {
// data = {code: 0, message: this.translate.instant('wrongServerWithCode') + err.error.status};
data = {code: 0, message: '服务器异常'};
}
} else {
// data = {code: 0, message: this.translate.instant('wrongServer')};
data = {code: 0, message: '服务器异常'};
}
// next(data);
next(data);
};
}
if (type === 'get') {
......@@ -75,4 +76,26 @@ export class ApiService {
this.http.post(this.url + addr, reqB, nextFunc, error, complete);
}
}
async presentMsgToast(msg) {
const toast = await this.toast.create({
message: msg,
duration: 2000,
mode: 'ios',
cssClass: 'msgToast'
});
toast.present();
}
async presentBtnToast(msg, btn, position) {
const toast = await this.toast.create({
message: msg,
showCloseButton: true,
position: position,
closeButtonText: btn,
mode: 'ios',
cssClass: 'btnToast'
});
toast.present();
}
}
import { Injectable, OnInit } from '@angular/core';
import { CanActivateChild, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
// import { PermissionService } from './permission.service';
// import { MenuService } from './menu.service';
@Injectable()
export class AuthService implements CanActivateChild, OnInit {
// public login = false;
// private permissionR = '';
constructor(private router: Router) {
}
......@@ -15,45 +11,11 @@ export class AuthService implements CanActivateChild, OnInit {
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
// const layoutCon = document.getElementById('layoutCon');
// if (layoutCon) {
// layoutCon.scrollTop = 0;
// }
// return this.checkLogin() && this.permissionCheck(state.url);
// // return this.checkLogin();
return true;
if (window.localStorage.getItem('token')) {
return true;
} else {
this.router.navigate(['/extra']);
return false;
}
}
// // 登录验证,如果有值就返回true.没有就跳转登录
// checkLogin() {
// if (window.sessionStorage.getItem('_AMap_AMap.MapInner')) {
// return true;
// }
// this.router.navigate(['/extra/login']);
// return false;
// }
//
// // 路由跳转权限检测
// permissionCheck(routerUrl) {
// clearInterval(parseInt(window.sessionStorage.getItem('_inv'), 10));
// let routerReq;
// if (routerUrl.indexOf('?') > -1) {
// routerReq = routerUrl.slice(0, routerUrl.indexOf('?'));
// } else {
// routerReq = routerUrl;
// }
// routerReq = routerReq.split('/');
// if (routerReq[routerReq.length - 1] === 'xdkDetail' || routerReq[routerReq.length - 1] === 'cissDetail'
// || routerReq[routerReq.length - 1] === 'warnEdit' || routerReq[routerReq.length - 1] === 'warnNew') {
// this.permissionR = routerReq[routerReq.length - 2];
// } else {
// this.permissionR = routerReq[routerReq.length - 1];
// }
// const permissions = JSON.stringify(this.permission.getTiny());
// if (permissions.indexOf(this.permissionR) > -1) {
// return true;
// } else {
// return false;
// }
// }
}
......@@ -2,12 +2,12 @@ import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Http, RequestOptions, Response } from '@angular/http';
import { Subscription } from 'rxjs/index';
import { Router } from '@angular/router';
import { TransferService } from './transfer.service';
@Injectable()
export class HttpService {
constructor(private http: HttpClient, private router: Router) {
constructor(private http: HttpClient, private tf: TransferService) {
this.subs = new Array<Subscription>();
}
private subs: Subscription[];
......@@ -63,7 +63,7 @@ export class HttpService {
// 跳转登录页面
toLoginPage(time) {
window.setTimeout(() => {
this.router.navigate(['/extra/login']);
this.tf.transfer({to: 'app-extra', from: 'app-home', url: '/extra'});
}, time);
}
......
......@@ -3,9 +3,14 @@
@import '~@ionic/angular/css/normalize.css';
@import '~@ionic/angular/css/structure.css';
@import '~@ionic/angular/css/typography.css';
@import '~@ionic/angular/css/padding.css';
@import '~@ionic/angular/css/float-elements.css';
@import '~@ionic/angular/css/text-alignment.css';
@import '~@ionic/angular/css/text-transformation.css';
@import '~@ionic/angular/css/flex-utils.css';
.msgToast, .btnToast {
--background: rgba(0, 0, 0, 0.7);
--color: #ffffff;
text-align: center;
}
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