|
|
|
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({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
styleUrls: ['./app.component.scss']
|
|
|
|
})
|
|
|
|
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) { }
|
|
|
|
|
|
|
|
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()
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let t = this;
|
|
|
|
// if(t._getSystem()) { //判断设备,目前只在windows系统下校正浏览器缩放比例
|
|
|
|
// //初始化页面校正浏览器缩放比例
|
|
|
|
// t._correct();
|
|
|
|
// //开启监听页面缩放
|
|
|
|
// t._watch();
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_getSystem() {
|
|
|
|
let flag = false;
|
|
|
|
var agent = navigator.userAgent.toLowerCase();
|
|
|
|
// var isMac = /macintosh|mac os x/i.test(navigator.userAgent);
|
|
|
|
// if(isMac) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//现只针对windows处理,其它系统暂无该情况,如有,继续在此添加
|
|
|
|
if (agent.indexOf("windows") >= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取页面缩放比例
|
|
|
|
// _getDevicePixelRatio() {
|
|
|
|
// let t = this;
|
|
|
|
// }
|
|
|
|
//监听方法兼容写法
|
|
|
|
_addHandler(element, type, handler) {
|
|
|
|
if (element.addEventListener) {
|
|
|
|
element.addEventListener(type, handler, false);
|
|
|
|
} else if (element.attachEvent) {
|
|
|
|
element.attachEvent("on" + type, handler);
|
|
|
|
} else {
|
|
|
|
element["on" + type] = handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//校正浏览器缩放比例
|
|
|
|
_correct() {
|
|
|
|
let t = this;
|
|
|
|
console.log('devicePixelRatio',window.devicePixelRatio)
|
|
|
|
//页面devicePixelRatio(设备像素比例)变化后,计算页面body标签zoom修改其大小,来抵消devicePixelRatio带来的变化。
|
|
|
|
document.getElementsByTagName('body')[0].style['zoom'] = String(1 / window.devicePixelRatio);
|
|
|
|
sessionStorage.setItem('zoom',String(1 / window.devicePixelRatio))
|
|
|
|
|
|
|
|
}
|
|
|
|
//监听页面缩放
|
|
|
|
_watch() {
|
|
|
|
let t = this;
|
|
|
|
t._addHandler(window, 'resize', function () { //注意这个方法是解决全局有两个window.resize
|
|
|
|
//重新校正
|
|
|
|
t._correct()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|