import { Component, AfterViewInit, ViewChild, Optional, OnInit } from '@angular/core';
|
import { FormGroup, FormBuilder, Validators, FormControl, ValidatorFn } from '@angular/forms';
|
import { CanActivate,Router,ActivatedRoute } from '@angular/router';
|
import { DomSanitizer } from '@angular/platform-browser';
|
import { HttpService } from './core/HttpService';
|
import { UserService } from './core/UserService';
|
import { Response} from "@angular/http";
|
import { StorageService } from './core/StorageService';
|
import { CookieService } from 'angular2-cookie/services/cookies.service';
|
import { NotificationsService } from 'angular2-notifications';
|
import { FormManagementComponent } from './form/formManagement/FormManagementComponent';
|
import { FormManagementMenuComponent } from './form/formManagement/FormManagementMenuComponent';
|
import { ToasterService } from './toastr/toast/toaster.service';
|
import { MessageService } from './core/MessageService';
|
import { UtilService } from './core/UtilService';
|
import { AppConfig } from './config/AppConfig';
|
import * as $ from "jquery";
|
import { NgModel } from '@angular/forms/src/directives/ng_model';
|
import { PermissionGuard } from './services/PermissionGuard';
|
import { Permission } from 'angular2-notifications/src/push-notification.type';
|
import { NoPermissionComponent } from './no-permisssion/no-permission.component';
|
import { Config } from './core/config.service';
|
const swal = require('sweetalert');
|
// const browser = require('jquery.browser');
|
@Component({
|
selector: 'app',
|
templateUrl: './app.component.html'
|
})
|
export class AppComponent implements AfterViewInit, OnInit {
|
// 表单验证
|
private showFlagTitle: boolean = false;
|
private loginForm: FormGroup;
|
private userName: string;
|
private password: string;
|
private showFlg: boolean = false;
|
private isShowTitle: boolean = false;
|
private menuName: string = 'industryCategory';
|
private name: string = 'industryCategory';
|
private options = {
|
position: ['top', 'left'],
|
showProgressBar: false,
|
animate: 'scale'
|
};
|
private flagNavbar;
|
public showTentAntId: any;
|
public showCompanyName: any;
|
public showSysNameBox: any;
|
public showSysName: any;
|
public showCompanyId: any;
|
public showSysId: any;
|
public quitHref: any;
|
public selectCompany: any;
|
isNavSearchVisible: boolean;
|
public showCompanyNameBox: any;
|
public showTentAntNameBox: any;
|
public showTentAntName: any;
|
public login_url: any;
|
public register_url = this.config.REGISTER_URL;
|
@ViewChild(FormManagementComponent) private modal: FormManagementComponent;
|
@ViewChild(FormManagementMenuComponent) private modalMenu: FormManagementMenuComponent;
|
@ViewChild('fsbutton') fsbutton;
|
|
constructor(private router: Router, private httpService: HttpService,
|
private user: UserService, private notifications: NotificationsService,
|
private fb: FormBuilder,
|
public sanitizer: DomSanitizer,
|
private storage: StorageService, private storageService: StorageService, private message: MessageService,
|
private _cookieService: CookieService,
|
private util: UtilService,
|
private canactivate: PermissionGuard,
|
private route: ActivatedRoute,
|
private config:Config,
|
|
@Optional() private toast: ToasterService) {
|
this.loginForm = this.fb.group({
|
'userName': [null, Validators.compose([Validators.required])],
|
'password': [null, Validators.compose([Validators.required])],
|
});
|
}
|
|
ngOnInit() {
|
this.config.resConfig();
|
//
|
//请求权限数据
|
let urlHash = window.location.hash;
|
let urlHref = window.location.href;
|
|
let serviceKey = this.util.GetQueryString(urlHash,'serviceKey');
|
let serviceId = this.util.GetQueryString(urlHash,'serviceId');
|
if (!serviceKey && !serviceId) {
|
this.canactivate.getPermissionObservable1();
|
}
|
|
|
$(document).click(() => {
|
this.showFlg = false;
|
});
|
$(".loginIFrame").click((event) => {
|
event.stopPropagation();
|
});
|
$(".logbtn").click((event) => {
|
event.stopPropagation();
|
});
|
$('body').scroll(function (e) {
|
|
//变量t就是滚动条滚动时,到顶部的距离
|
var t = $('body').scrollTop();
|
if (t >= 680) {
|
$('#logos').removeClass('logo');
|
$('#logos').addClass('logos');
|
$('#buttons').find('div').removeClass('logbtn');
|
$('#buttons').find('div').addClass('logbtns');
|
} else {
|
$('#logos').removeClass('logos');
|
$('#logos').addClass('logo');
|
$('#buttons').find('div').removeClass('logbtns');
|
$('#buttons').find('div').addClass('logbtn');
|
}
|
});
|
|
let loginFlag = (urlHash != "" && urlHash != "#/");
|
if ((this.storage.get('token') && loginFlag) || this.util.GetQueryString(urlHash,'serviceKey')) {
|
$('.appwrapper').hide();
|
$('.mainbox').hide();
|
$('.second').hide();
|
$('.third').hide();
|
$('footer').hide();
|
$('.simple-notification-wrapper').hide();
|
}
|
}
|
|
ngAfterViewInit() {
|
|
this.login_url = this.sanitizer.bypassSecurityTrustResourceUrl(this.config.LOGIN_URL);
|
let urlHash = window.location.hash;
|
let urlHref = window.location.href;
|
|
|
|
let key = this.util.GetQueryString(urlHref, 'key');
|
let serviceKey = this.util.GetQueryString(urlHash,'serviceKey');
|
let loginKey = this.util.GetQueryString(urlHref, 'loginKey');
|
|
//
|
if (serviceKey) {
|
|
let userName = decodeURI(this.util.GetQueryString(urlHref, 'userName'));
|
this.storageService.store("tenantID", {tenantID: this.util.GetQueryString(urlHref, 'tenantId')});
|
this.storageService.store("userName", {userName: userName});
|
|
// let data = this._cookieService.getAll();
|
|
// let res = this.httpService.post('/serviceCheck/checkData',{"sign":this.util.GetQueryString(urlHref, 'sign'),"data":data});
|
// res.subscribe(
|
// (response) => {
|
//
|
// if (response.rspCode != "000000") {
|
// this.cookiequitLogin(true);
|
// }
|
// })
|
|
this.user.setAccessToken(this.util.GetQueryString(urlHref, 'token'));
|
this.user.setTenantID(this.util.GetQueryString(urlHref, 'tenantId'));
|
this.user.setUsername(userName);
|
|
|
|
|
|
|
//费用云
|
|
// this.storage.store('userName', { userName: this.util.GetQueryString(urlHref, 'userName') })
|
// this.storage.store('tenantID', { tenantID: this.util.GetQueryString(urlHref, 'tenantID') });
|
// this.storage.store('token', { "accessToken": this.util.GetQueryString(urlHref, 'token') });
|
// this.storage.store('isShowTitle', true);
|
// this.storage.store('showFlg', false);
|
this.isShowTitle = false;
|
this.showFlg = false;
|
|
|
|
} else if (loginKey) {
|
|
let token = this._cookieService.get("token");
|
this.storage.store('token', { "accessToken": token });
|
this.user.setAccessToken(token);
|
this.showFlg = false;
|
this.isShowTitle = true;
|
window.parent.location.href = urlHref.replace("?loginKey=main", "");
|
$(window.parent.document.getElementsByClassName('wrapper')).hide();
|
window.parent.location.reload();
|
this.router.navigate(['main']);
|
|
} else {
|
|
let loginFlag = (urlHash != "" && urlHash != "#/");
|
|
if (this._cookieService.get('token') && loginFlag) {
|
//自定义表单
|
this.isShowTitle = true;
|
this.showFlg = false;
|
this.getCompanys();
|
// this.user.setAccessToken(this.storage.get('token').accessToken);
|
if (this.storage.get('tenantID') != undefined && this.storage.get('tenantID') != '') {
|
this.user.setTenantID(this.storage.get('tenantID').tenantID);
|
}
|
if (this._cookieService.get('userName') != undefined && this._cookieService.get('userName') != '') {
|
this.user.setUsername(this._cookieService.get('userName'));
|
this.userName = this._cookieService.get('userName');
|
|
}
|
|
|
|
this.menuName = this.storage.get('lastMenuName');
|
this.name = this.storage.get('lastMenuName');
|
}
|
// else {
|
// this.storage.clear('userName');
|
// this.storage.clear('tenantID');
|
// this.storage.clear('token');
|
// this.storage.clear('lastMenuName');
|
|
// this.storage.clear('isShowTitle');
|
// this.storage.clear('showFlg');
|
// window.location.hash = '';
|
// }
|
}
|
history.pushState(null, null, document.URL);
|
window.addEventListener('popstate', function () {
|
history.pushState(null, null, document.URL);
|
});
|
|
|
|
}
|
|
public submit(event) {
|
// this.userName = "huaixun.zhang";
|
// this.password = "1";
|
event.preventDefault();
|
if (this.loginForm.valid) {
|
let observable = this.httpService.post("/auth", {
|
"username": this.userName,
|
"password": this.password
|
});
|
observable.subscribe(
|
(response) => {
|
// this.flagNavbar =
|
|
this.isShowTitle = true;
|
this.user.setAccessToken(response.token);
|
this.user.setTenantID(response.tenantID);
|
this.user.setUsername(this.userName);
|
this.storage.store('userName', { userName: this.userName })
|
this.storage.store('tenantID', { tenantID: response.tenantID });
|
this.storage.store('token', { accessToken: response.token });
|
this._cookieService.put('token', response.token)
|
this.showFlg = false;
|
this.router.navigateByUrl("industryCategory");
|
},
|
(error) => {
|
// this.notifications.error("失败", "用户名密码不匹配", {timeOut: 10000});
|
// this.notifications.error("失败", "用户名密码不匹配", {timeOut: 999999910000});
|
this.toast.error("失败", this.message.getMessageText("E001", []), true, 5000);
|
}
|
);
|
} else {
|
for (let c in this.loginForm.controls) {
|
this.loginForm.controls[c].markAsTouched();
|
}
|
}
|
}
|
|
isShow() {
|
return this.showFlg;
|
}
|
private changeTag(menuName) {
|
this.menuName = menuName;
|
switch (menuName) {
|
case 'createForm':
|
this.modalMenu.show();
|
this.menuName = this.name;
|
break;
|
case 'formTending':
|
this.name = this.menuName;
|
this.storage.store('lastMenuName', this.name);
|
this.router.navigateByUrl('/formTending');
|
break;
|
case 'formOperation':
|
this.name = this.menuName;
|
this.storage.store('lastMenuName', this.name);
|
this.router.navigateByUrl('/formOperation');
|
break;
|
case 'industryCategory':
|
this.name = this.menuName;
|
this.storage.store('lastMenuName', this.name);
|
this.storageService.store('dataManagementFlag', '1');
|
this.router.navigateByUrl('industryCategory');
|
break;
|
case 'processTask':
|
this.name = this.menuName;
|
this.storage.store('lastMenuName', this.name);
|
this.storageService.store('dataManagementFlag', '1');
|
this.router.navigateByUrl('/processTask');
|
break;
|
case 'fm_templateCenter':
|
this.name = this.menuName;
|
this.storage.store('lastMenuName', this.name);
|
this.storageService.store('dataManagementFlag', '1');
|
this.router.navigateByUrl('/fm_templateCenter');
|
break;
|
}
|
}
|
|
showModal() {
|
this.showFlg = true;
|
}
|
//组织结构
|
toggleSubmenuHover(event) {
|
|
this.selectCompany = document.getElementById("selectCompany");
|
|
// this.selectCompany.setAttribute("display","none");
|
this.selectCompany.setAttribute("style", "transform: translate(0px,243px)!important;");
|
|
// arr[j].classList.remove("open");
|
}
|
//清除页面中的样式类
|
RemoveClass(Id1, Class1) { //Id1,要清除class的id、calss1:要清除的类
|
let removeClass1 = document.getElementById(Id1).getAttribute('class');
|
let classVal = removeClass1.replace(Class1, "");
|
document.getElementById(Id1).setAttribute("class", classVal);
|
}
|
toggleSubmenuHover2() {
|
this.RemoveClass("dropdown1", "open");
|
this.RemoveClass("dropdown2", "open");
|
this.RemoveClass("dropdown3", "open");
|
|
this.selectCompany.setAttribute("style", "transform: translate(0px, -45px);");
|
}
|
//退出登陆
|
quitLogin() {
|
this.quitHref = document.getElementById("quitLogin")
|
swal({
|
title: '是否确认退出?',
|
text: +'?',
|
showCancelButton: true,
|
confirmButtonColor: '#DD6B55',
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
closeOnConfirm: true,
|
imageUrl: "../../assets/img/warning.png",
|
imageSize: "50x 50x"
|
}, (isConfirm) => {
|
if (isConfirm) {
|
// this.toTdLogin();
|
this._cookieService.removeAll();
|
localStorage.clear();
|
sessionStorage.clear();
|
window.location.href = this.config.LOGOUT_URL;
|
|
// this.quitHref.setAttribute("href",");
|
}
|
});
|
}
|
getCompanys() {
|
// this.cookiequitLogin(false);
|
this.isNavSearchVisible = false;
|
var userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
|
if(userInfo==undefined||userInfo==null){
|
this.httpService.post('/getUserInfo', {}).subscribe(
|
(response) => {
|
if (response.rspCode == "000000") {
|
sessionStorage.setItem("userInfo", JSON.stringify(response.data));
|
this.userName = response.data.userName;
|
this.user.setUsername(this.userName);
|
|
this.storage.store('userName', { 'userName': this.userName })
|
}
|
}
|
);
|
}
|
if(userInfo!=undefined ){
|
this.userName = userInfo.userName;
|
this.user.setUsername(this.userName);
|
}
|
this.storage.store('userName', { 'userName': this.userName })
|
// if (browser.msie) { // Not supported under IE
|
// this.fsbutton.nativeElement.style.display = 'none';
|
// }
|
let res = this.httpService.post('/cscApi/findTenantsAndCompanys');
|
res.subscribe(
|
(response) => {
|
|
if (response.rspCode == "000000") {
|
this.showTentAntNameBox = response.data.tenants;
|
|
let tenantLocalStorage = this.storageService.get("TentAnt");
|
if (tenantLocalStorage) {
|
this.showTentAntName = tenantLocalStorage.name;
|
this.showTentAntId = tenantLocalStorage.id;
|
} else {
|
this._cookieService.put("companyId",response.data.tenants[0].companys[0].id);
|
this.showTentAntName = response.data.tenants[0].name;
|
this.showTentAntId = response.data.tenants[0].id;
|
}
|
for (let i = 0; i < this.showTentAntNameBox.length; i++) {
|
if (this.showTentAntId == this.showTentAntNameBox[i].id) {
|
this.showCompanyNameBox = this.showTentAntNameBox[i].companys;
|
|
let companyLocalStorage = this.storageService.get("Company");
|
if (companyLocalStorage) {
|
this.showCompanyName = companyLocalStorage.name;
|
this.showCompanyId = companyLocalStorage.id;
|
} else {
|
this.showCompanyName = this.showTentAntNameBox[i].companys[0].name;
|
this.showCompanyId = this.showTentAntNameBox[i].companys[0].id;
|
}
|
this._cookieService.put("tenantId", this.showTentAntId);
|
// this._cookieService.put("companyId", this.showCompanyId);
|
for (let j = 0; j < this.showCompanyNameBox.length; j++) {
|
if (this.showCompanyId == this.showCompanyNameBox[j].id) {
|
this.showSysNameBox = this.showCompanyNameBox[j].data;
|
let systemLocalStorage = localStorage.getItem("System");
|
if (systemLocalStorage) {
|
this.showSysName = JSON.parse(systemLocalStorage).name;
|
this.showSysId = JSON.parse(systemLocalStorage).id;
|
} else {
|
this.showSysName = this.showCompanyNameBox[j].data[0].name;
|
this.showSysId = this.showCompanyNameBox[j].data[0].id;
|
}
|
|
// this.httpService.post('process-control/center/app/check',{"tenantId":this.showTentAntId,"companyId":this.showCompanyId,"serviceId":this.showSysId},(res)=>{
|
//
|
// if(res.resCode=="00000"){
|
// // this.initState=res.data;
|
// // this.maskShowAll=res.data;
|
// if(!res.data){
|
// // this.formidService.twarning(this.utilService.getTranslateVel("table.prompt.PROMPT039"));
|
// }
|
// // localStorage.setItem("InitState",this.initState);
|
// }else{
|
// // this.formidService.twarning(this.utilService.getTranslateVel("table.prompt.PROMPT023"));
|
// }
|
// })
|
}
|
}
|
}
|
}
|
} else {
|
// this.formidService.twarning(this.utilService.getTranslateVel("table.prompt.PROMPT040"));
|
}
|
})
|
}
|
clickCompany(companydata) {
|
this.showCompanyName = companydata.name;
|
this.showCompanyId = companydata.id;
|
for (let j = 0; j < this.showCompanyNameBox.length; j++) {
|
if (this.showCompanyId == this.showCompanyNameBox[j].id) {
|
this.showSysNameBox = this.showCompanyNameBox[j].data;
|
let strCompany = JSON.stringify(this.showCompanyNameBox[j]);
|
if (this.showSysNameBox) {
|
this.showSysName = this.showSysNameBox[0].name;
|
this.showSysId = this.showSysNameBox[0].id;
|
}
|
this._cookieService.put("tenantId", this.showTentAntId);
|
this._cookieService.put("companyId", this.showCompanyId);
|
let Company = {
|
name:companydata.name,
|
id:companydata.id,
|
}
|
this.storageService.store("Company",Company);
|
this.router.navigate(['main']);
|
}
|
}
|
this.canactivate.getPermissionObservable1();
|
}
|
initChange(TentAnt){
|
for (let j = 0; j < this.showTentAntNameBox.length; j++) {
|
if(TentAnt==this.showTentAntNameBox[j].id){
|
this.showCompanyNameBox = this.showTentAntNameBox[j].companys;
|
this.showCompanyName = this.showTentAntNameBox[j].companys[0].name;
|
this.showTentAntName = this.showTentAntNameBox[j].name;
|
}
|
}
|
|
}
|
clickTentAnt(showTentAnt){
|
this.showTentAntName = showTentAnt.name;
|
this.showTentAntId = showTentAnt.id;
|
for (let j = 0; j < this.showTentAntNameBox.length; j++) {
|
if (this.showTentAntId == this.showTentAntNameBox[j].id) {
|
this.showCompanyNameBox = this.showTentAntNameBox[j].companys;
|
this.showCompanyName = this.showTentAntNameBox[j].companys[0].name;
|
this._cookieService.put("tenantId", this.showTentAntId);
|
this._cookieService.put("companyId", this.showTentAntNameBox[j].companys[0].id);
|
this.storage.store('tenantID', { 'tenantID': this.showTentAntId});
|
// 修改用户TenantID
|
this.user.setTenantID(this.showTentAntId);
|
let TentAnt = {
|
name:showTentAnt.name,
|
id:showTentAnt.id,
|
}
|
this.storageService.store("TentAnt",TentAnt);
|
this.router.navigate(['main']);
|
}
|
}
|
this.canactivate.getPermissionObservable1();
|
}
|
|
cookiequitLogin(flg) {
|
if (flg) {
|
this._cookieService.remove('token');
|
this._cookieService.remove('openId');
|
}
|
if (this._cookieService.get("token") == null || this._cookieService.get("token") == undefined || this._cookieService.get("openId") == null || this._cookieService.get("openId") == undefined) {
|
this.quitHref = document.getElementById("quitLogin")
|
swal({
|
title: '登录状态已失效,请重新登录',
|
text: +'?',
|
showCancelButton: false,
|
confirmButtonColor: '#DD6B55',
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
closeOnConfirm: true,
|
imageUrl: "../../assets/img/warning.png",
|
imageSize: "50x 50x"
|
}, (isConfirm) => {
|
if (isConfirm) {
|
// this.toTdLogin();
|
this._cookieService.removeAll();
|
localStorage.clear();
|
sessionStorage.clear();
|
window.location.href = this.config.LOGOUT_URL;
|
|
// this.quitHref.setAttribute("href",");
|
}
|
});
|
}
|
}
|
|
|
|
}
|