1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { Environment } from "@/environments/environment";
import { AppServiceBase, Http, LogUtil, ViewTool } from "ibiz-core";
/**
* 应用无权限服务
*
* @memberof AppNoAuthDataService
*/
export class AppNoAuthDataService {
/**
* 单例变量声明
*
* @private
* @static
* @type {AppNoAuthDataService}
* @memberof AppNoAuthDataService
*/
private static AppNoAuthDataService: AppNoAuthDataService;
/**
* 样式表请求路径
*
* @private
* @type {string}
* @memberof AppNoAuthDataService
*/
private appUserStyleUrl: string = 'simple/PSSYSAPP.simple.json.css';
/**
* 样式表是否挂载
*
* @public
* @type {boolean}
* @memberof AppNoAuthDataService
*/
public appUserStyleIsMounted: boolean = false;
/**
* 无权限数据请求路径
*
* @private
* @type {string}
* @memberof AppNoAuthDataService
*/
private appNoAuthDataUrl: string = 'simple/PSSYSAPP.simple.json';
/**
* 无权限数据是否挂载
*
* @type {boolean}
* @memberof AppNoAuthDataService
*/
public appNoAuthDataIsMounted: boolean = false;
/**
* 获取AppNoAuthDataService单例对象
*
* @static
* @returns {AppNoAuthDataService}
* @memberof AppNoAuthDataService
*/
public static getInstance(): AppNoAuthDataService {
if (!this.AppNoAuthDataService) {
this.AppNoAuthDataService = new AppNoAuthDataService();
}
return this.AppNoAuthDataService;
}
/**
* 挂载基础数据
*
* @return {*}
* @memberof AppNoAuthDataService
*/
public async mountedAppBasicData() {
if (!this.appUserStyleIsMounted) {
const result = await this.mountedAppStyle();
}
if (!this.appNoAuthDataIsMounted) {
const result = await this.mountedAppNoAuthData();
}
return true;
}
/**
* 挂载应用样式表
*
*/
public async mountedAppStyle() {
const cssUrl = this.appUserStyleUrl;
try {
const cssContent = await this.loadAppUserStyle(cssUrl);
if (!cssContent) {
return true;
}
this.mountedAppUserStyle(cssContent);
AppServiceBase.getInstance().setAppUserStyle(cssContent);
return true;
} catch (error) {
LogUtil.error("挂载应用样式表异常");
return true;
} finally {
this.appUserStyleIsMounted = true;
}
}
/**
* 挂载应用无权限数据
*
* @memberof AppNoAuthDataService
*/
public async mountedAppNoAuthData() {
const dataUrl = this.appNoAuthDataUrl;
try {
const noAuthData = await this.loadNoAuthData(dataUrl);
if (!noAuthData) {
return true;
}
AppServiceBase.getInstance().setAppNoAuthData(noAuthData);
if(noAuthData.name){
Object.assign(Environment,{AppTitle:noAuthData.name});
document.title = Environment.AppTitle;
}
return true;
} catch (error) {
LogUtil.error("挂载应用无权限数据异常");
return true;
} finally {
this.appNoAuthDataIsMounted = true;
}
}
/**
* 加载应用自定义样式表
*
* @param cssUrl 样式路径
*/
public async loadAppUserStyle(cssUrl: string) {
let url = '';
if (Environment.bDynamic) {
url = `${Environment.remoteDynaPath}/${cssUrl}`;
} else {
const microAppService = AppServiceBase.getInstance().getMicroAppService();
if (microAppService && microAppService.getIsMicroApp() && microAppService.getMicroAppFolder()) {
url = `./${microAppService.getMicroAppFolder()}/assets/model/${cssUrl}`;
} else {
url = `./assets/model/${cssUrl}`;
}
}
try {
let headers: any = {};
const tempViewParam = ViewTool.getDcSystemIdViewParam();
if (tempViewParam.srfdcsystem) {
headers.srfdcsystem = tempViewParam.srfdcsystem
}
const result: any = await Http.getInstance().get(url, {}, false, headers);
return result.data ? result.data : null;
} catch (error) {
LogUtil.error("加载应用样式表异常");
return null;
}
}
/**
* 加载应用无权限数据
*
* @param dataUrl 无权限数据路径
*/
public async loadNoAuthData(dataUrl: string) {
let url = '';
if (Environment.bDynamic) {
url = `${Environment.remoteDynaPath}/${dataUrl}`;
} else {
const microAppService = AppServiceBase.getInstance().getMicroAppService();
if (microAppService && microAppService.getIsMicroApp() && microAppService.getMicroAppFolder()) {
url = `./${microAppService.getMicroAppFolder()}/assets/model/${dataUrl}`;
} else {
url = `./assets/model/${dataUrl}`;
}
}
try {
let headers: any = {};
const tempViewParam = ViewTool.getDcSystemIdViewParam();
if (tempViewParam.srfdcsystem) {
headers.srfdcsystem = tempViewParam.srfdcsystem
}
const result: any = await Http.getInstance().get(url, {}, false, headers);
return result.data ? result.data : null;
} catch (error) {
LogUtil.error("加载应用无权限数据异常");
return null;
}
}
/**
* 挂载应用自定义样式表
*
* @param cssContent 样式内容
*/
public mountedAppUserStyle(cssContent: string) {
let appStyleDom: any;
for (let i = document.head.childNodes.length - 1; i >= 0; i--) {
const children: any = document.head.childNodes[i]
if (children.nodeName == "STYLE" && children.getAttribute('title') && children.getAttribute('title') == 'app-style-css') {
appStyleDom = children;
}
}
if (appStyleDom) {
appStyleDom.innerText = cssContent;
} else {
const styleDom = document.createElement('style');
styleDom.type = "text/css";
styleDom.setAttribute('title', 'app-style-css');
styleDom.innerText = cssContent;
document.head.appendChild(styleDom);
}
}
}