@impui/imp 1.0.16-beta.0 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/axios/index.es.js +1 -143
  2. package/dist/config/index.es.js +1 -127
  3. package/dist/core/index.es.js +1 -34
  4. package/dist/gotool/go2/index.es.js +1 -510
  5. package/dist/gotool/index/index.es.js +1 -164
  6. package/dist/imph5/index.es.js +1 -324
  7. package/dist/index.es.js +1 -49
  8. package/dist/login/index.es.js +1 -711
  9. package/dist/node_modules/axios/index/index.es.js +1 -38
  10. package/dist/node_modules/axios/lib/adapters/adapters/index.es.js +1 -71
  11. package/dist/node_modules/axios/lib/adapters/fetch/index.es.js +1 -219
  12. package/dist/node_modules/axios/lib/adapters/xhr/index.es.js +1 -141
  13. package/dist/node_modules/axios/lib/axios/index.es.js +1 -50
  14. package/dist/node_modules/axios/lib/cancel/CancelToken/index.es.js +1 -99
  15. package/dist/node_modules/axios/lib/cancel/CanceledError/index.es.js +1 -12
  16. package/dist/node_modules/axios/lib/cancel/isCancel/index.es.js +1 -6
  17. package/dist/node_modules/axios/lib/core/Axios/index.es.js +1 -180
  18. package/dist/node_modules/axios/lib/core/AxiosError/index.es.js +1 -80
  19. package/dist/node_modules/axios/lib/core/AxiosHeaders/index.es.js +1 -231
  20. package/dist/node_modules/axios/lib/core/InterceptorManager/index.es.js +1 -65
  21. package/dist/node_modules/axios/lib/core/buildFullPath/index.es.js +1 -12
  22. package/dist/node_modules/axios/lib/core/dispatchRequest/index.es.js +1 -52
  23. package/dist/node_modules/axios/lib/core/mergeConfig/index.es.js +1 -83
  24. package/dist/node_modules/axios/lib/core/settle/index.es.js +1 -18
  25. package/dist/node_modules/axios/lib/core/transformData/index.es.js +1 -17
  26. package/dist/node_modules/axios/lib/defaults/index/index.es.js +1 -116
  27. package/dist/node_modules/axios/lib/defaults/transitional/index.es.js +1 -8
  28. package/dist/node_modules/axios/lib/env/data/index.es.js +1 -4
  29. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams/index.es.js +1 -34
  30. package/dist/node_modules/axios/lib/helpers/HttpStatusCode/index.es.js +1 -77
  31. package/dist/node_modules/axios/lib/helpers/bind/index.es.js +1 -8
  32. package/dist/node_modules/axios/lib/helpers/buildURL/index.es.js +1 -34
  33. package/dist/node_modules/axios/lib/helpers/combineURLs/index.es.js +1 -6
  34. package/dist/node_modules/axios/lib/helpers/composeSignals/index.es.js +1 -39
  35. package/dist/node_modules/axios/lib/helpers/cookies/index.es.js +1 -49
  36. package/dist/node_modules/axios/lib/helpers/formDataToJSON/index.es.js +1 -54
  37. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL/index.es.js +1 -6
  38. package/dist/node_modules/axios/lib/helpers/isAxiosError/index.es.js +1 -7
  39. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin/index.es.js +1 -11
  40. package/dist/node_modules/axios/lib/helpers/null/index.es.js +1 -4
  41. package/dist/node_modules/axios/lib/helpers/parseHeaders/index.es.js +1 -47
  42. package/dist/node_modules/axios/lib/helpers/parseProtocol/index.es.js +1 -7
  43. package/dist/node_modules/axios/lib/helpers/progressEventReducer/index.es.js +1 -41
  44. package/dist/node_modules/axios/lib/helpers/resolveConfig/index.es.js +1 -46
  45. package/dist/node_modules/axios/lib/helpers/speedometer/index.es.js +1 -36
  46. package/dist/node_modules/axios/lib/helpers/spread/index.es.js +1 -8
  47. package/dist/node_modules/axios/lib/helpers/throttle/index.es.js +1 -35
  48. package/dist/node_modules/axios/lib/helpers/toFormData/index.es.js +1 -117
  49. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm/index.es.js +1 -18
  50. package/dist/node_modules/axios/lib/helpers/trackStream/index.es.js +1 -80
  51. package/dist/node_modules/axios/lib/helpers/validator/index.es.js +1 -67
  52. package/dist/node_modules/axios/lib/platform/browser/classes/Blob/index.es.js +1 -4
  53. package/dist/node_modules/axios/lib/platform/browser/classes/FormData/index.es.js +1 -4
  54. package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams/index.es.js +1 -5
  55. package/dist/node_modules/axios/lib/platform/browser/index/index.es.js +1 -15
  56. package/dist/node_modules/axios/lib/platform/common/utils/index.es.js +1 -15
  57. package/dist/node_modules/axios/lib/platform/index/index.es.js +1 -9
  58. package/dist/node_modules/axios/lib/utils/index.es.js +1 -387
  59. package/dist/packages/com/dist/cache/index.es/index.es.js +1 -145
  60. package/dist/packages/com/dist/core/index.es/index.es.js +1 -154
  61. package/dist/packages/com/dist/data/index.es/index.es.js +1 -26
  62. package/dist/packages/com/dist/date/index.es/index.es.js +2 -194
  63. package/dist/packages/com/dist/log/index.es/index.es.js +1 -110
  64. package/dist/packages/com/dist/message/index.es/index.es.js +1 -90
  65. package/dist/packages/com/dist/req/index.es/index.es.js +1 -35
  66. package/dist/packages/com/dist/str/index.es/index.es.js +1 -25
  67. package/dist/packages/com/dist/typetool/index.es/index.es.js +1 -53
  68. package/dist/packages/com/dist/url/index.es/index.es.js +1 -238
  69. package/dist/restool/index/index.es.js +1 -266
  70. package/dist/restool/index.css/index.es.js +1 -4
  71. package/package.json +5 -1
@@ -1,711 +1 @@
1
- import "../axios/index.es.js";
2
- import { extend } from "../packages/com/dist/core/index.es/index.es.js";
3
- import { getLog } from "../packages/com/dist/log/index.es/index.es.js";
4
- import { isBoolean } from "../packages/com/dist/typetool/index.es/index.es.js";
5
- import "../packages/com/dist/browser/index.es/index.es.js";
6
- import "../packages/com/dist/str/index.es/index.es.js";
7
- import { cache } from "../packages/com/dist/cache/index.es/index.es.js";
8
- import "../packages/com/dist/req/index.es/index.es.js";
9
- import { urltool } from "../packages/com/dist/url/index.es/index.es.js";
10
- import { message } from "../packages/com/dist/message/index.es/index.es.js";
11
- import { event } from "@impui/com/event";
12
- import { handleUrl } from "../core/index.es.js";
13
- import { getConfig, getEvnConfig } from "../config/index.es.js";
14
- import { iframeReq, get } from "@impui/com/req";
15
- import axios from "../node_modules/axios/lib/axios/index.es.js";
16
- import "../node_modules/axios/index/index.es.js";
17
- const config = await getConfig();
18
- const log = await getLog();
19
- class Login {
20
- constructor() {
21
- this.loginDomain = window.loginDomain = location.hostname === "localhost" && getEvnConfig().isLocalhost ? "https://localhost:44360" : config.domainLogin;
22
- this.ver = "v1.0.0";
23
- this.loginTime = 6 * 60 * 60;
24
- this.prefix = "IMP_PLUG_LOGIN_";
25
- this.initUrls();
26
- this.initKeys();
27
- this.initEventKeys();
28
- this.bindEvents();
29
- this.iframeBox = null;
30
- this.iframe = null;
31
- this.iframeBg = null;
32
- this.autoLogin = {};
33
- this.exitLogin = {};
34
- this.threeLoginWin = null;
35
- this.checkTemp();
36
- window.login = this;
37
- }
38
- /**
39
- * 初始化URL配置
40
- */
41
- initUrls() {
42
- this.urls = {
43
- login: handleUrl(this.loginDomain + "/index.html", true),
44
- reg: handleUrl(this.loginDomain + "/index.html?type=reg", true),
45
- loginPage: handleUrl(this.loginDomain + "/loginPage.html", true),
46
- regPage: handleUrl(this.loginDomain + "/regPage.html", true),
47
- autoLogin: handleUrl(this.loginDomain + "/" + this.ver + "/user/autoLogin"),
48
- checkSSOLogin: handleUrl(this.loginDomain + "/" + this.ver + "/user/checkSSOLogin"),
49
- checkLoginPage: handleUrl(this.loginDomain + "/" + this.ver + "/user/checkLoginPage"),
50
- CheckLoginByCode: handleUrl(this.loginDomain + "/" + this.ver + "/user/CheckLoginByCode"),
51
- exitLogin: this.loginDomain + "/" + this.ver + "/user/exitLogin",
52
- userInfo: this.loginDomain + "/" + this.ver + "/user/UserInfo",
53
- writeCookies: "/ashx/member/CheckSSOWriteCookie.ashx",
54
- webLoginOut: "/ajax/logout.aspx"
55
- };
56
- }
57
- /**
58
- * 初始化键名配置
59
- */
60
- initKeys() {
61
- const spliceName = (name) => this.prefix + name;
62
- this.keys = {
63
- msg_loginReturn: spliceName("loginReturn"),
64
- msg_close: spliceName("close"),
65
- msg_goto: spliceName("goto"),
66
- msg_autoSize: spliceName("autoSize"),
67
- msg_getSize: spliceName("getSize"),
68
- cache_loginSave: spliceName("loginSave"),
69
- cache_userInfo: spliceName("userInfo"),
70
- checkLogin_code: "code",
71
- loginStatus: "__login_status",
72
- loginResult: "__login_result",
73
- url_tempSignKey: "sign",
74
- url_tempUseridxKey: "useridx"
75
- };
76
- }
77
- /**
78
- * 初始化事件键名
79
- */
80
- initEventKeys() {
81
- const spliceName = (name) => this.prefix + name;
82
- this.eventKeys = {
83
- nologin: spliceName("login"),
84
- closeThreeLogin: spliceName("close_login_three")
85
- };
86
- }
87
- /**
88
- * 绑定事件监听
89
- */
90
- bindEvents() {
91
- message.on(this.keys.msg_close, () => {
92
- log.debug("关闭登录框");
93
- this.close();
94
- });
95
- message.on(this.keys.msg_goto, (data) => {
96
- this.handlePageTransition(data);
97
- });
98
- message.on(this.keys.msg_autoSize, (data) => {
99
- this.handleAutoSize(data);
100
- });
101
- message.on(this.keys.msg_loginReturn, async (res) => {
102
- await this.dealwithLoginRes(res);
103
- });
104
- message.on(this.eventKeys.closeThreeLogin, (res) => {
105
- this.save(res);
106
- this.closeThreeLoginWin();
107
- });
108
- event.onM("login", "getLogin", this.getLogin.bind(this));
109
- event.onM("login", "noLogin", this.runNoLogin.bind(this));
110
- }
111
- /**
112
- * 处理页面切换动画
113
- */
114
- handlePageTransition(data) {
115
- if (!this.iframe) return;
116
- this.iframe.classList.remove("IMP_PLUG_LOGIN_animateIn");
117
- this.iframe.classList.add("IMP_PLUG_LOGIN_animateOut");
118
- const transitionEnd = () => {
119
- this.iframe.src = data.url;
120
- this.iframe.classList.remove("IMP_PLUG_LOGIN_animateOut");
121
- this.iframe.removeEventListener("transitionend", transitionEnd);
122
- };
123
- this.iframe.addEventListener("transitionend", transitionEnd);
124
- }
125
- /**
126
- * 处理尺寸自适应
127
- */
128
- handleAutoSize(data) {
129
- if (!this.iframe) return;
130
- log.debug("登录框尺寸适配", data);
131
- this.iframe.width = data.width;
132
- this.iframe.height = data.height;
133
- this.iframe.classList.add("IMP_PLUG_LOGIN_animateIn");
134
- this.iframeBg.classList.add("IMP_PLUG_LOGIN_animateIn");
135
- }
136
- /**
137
- * 执行登录返回的回调
138
- */
139
- runAutoLoginCallback(res, nocache) {
140
- if (!this.autoLogin.callbacks || this.autoLogin.callbacks.length === 0) return;
141
- this.autoLogin.callbacks.forEach((callback) => {
142
- if (isBoolean(res)) {
143
- callback.ok && callback.ok(res);
144
- } else {
145
- const processedRes = this.getLogin(res);
146
- callback.ok && callback.ok(processedRes && processedRes.code === axios.codeEnum.success);
147
- }
148
- });
149
- this.autoLogin.iframe && this.autoLogin.iframe.remove();
150
- this.autoLogin.window && this.autoLogin.window.close();
151
- this.autoLogin = {};
152
- if (res) {
153
- this.close();
154
- }
155
- }
156
- /**
157
- * 处理登录返回数据
158
- */
159
- async dealwithLoginRes(res) {
160
- log.debug("登录消息返回", res);
161
- res.isok = res.code === axios.codeEnum.success;
162
- if (res.code !== 1) {
163
- this.clear();
164
- this.runAutoLoginCallback(res);
165
- return;
166
- }
167
- if (res.sign && res.sign.length === 8) {
168
- this.save(res);
169
- return;
170
- }
171
- urltool.delParsUpUrl([this.keys.url_tempSignKey, this.keys.url_tempUseridxKey]);
172
- cache.set(this.keys.cache_loginSave, res, this.loginTime);
173
- axios.saveLogin(res.useridx, res.sign);
174
- try {
175
- if (config.domainmaster.startsWith(location.origin)) {
176
- await axios.get(this.urls.writeCookies, null, null, "text");
177
- }
178
- } finally {
179
- this.runAutoLoginCallback(res);
180
- }
181
- }
182
- /**
183
- * 保存登录状态
184
- */
185
- save(res) {
186
- const sign = res.__source?.headers?.[res.sign] || res.data?.headers?.[res.sign] || res.sign;
187
- const useridx = res.useridx || res.data?.___useridx;
188
- message.send(this.keys.msg_loginReturn, {
189
- code: res.code,
190
- msg: res.msg,
191
- sign,
192
- useridx
193
- });
194
- }
195
- /**
196
- * 清除登录状态
197
- */
198
- clear() {
199
- cache.remove(this.keys.cache_loginSave);
200
- cache.remove(this.keys.cache_userInfo);
201
- cache.remove(this.keys.cache_userInfo + "_more");
202
- cache.remove(this.keys.cache_userInfo + "_simplify");
203
- }
204
- /**
205
- * 注册登录成功事件
206
- */
207
- onLoginOK(resolve, reject) {
208
- if (!this.autoLogin.callbacks) {
209
- this.autoLogin.callbacks = [];
210
- }
211
- this.autoLogin.callbacks.push({ ok: resolve, no: reject });
212
- }
213
- /**
214
- * 创建登录框
215
- */
216
- create(param) {
217
- const def = extend(true, {
218
- url: "",
219
- name: "",
220
- option: null
221
- }, param);
222
- this.createIframeBox();
223
- this.createIframe(def);
224
- this.applyStyles(def.option || {});
225
- this.appendToDocument();
226
- }
227
- /**
228
- * 创建iframe容器
229
- */
230
- createIframeBox() {
231
- this.iframeBox = document.createElement("div");
232
- this.iframeBox.className = "IMP_PLUG_LOGIN_box";
233
- const zoom = parseFloat(window.getComputedStyle(document.documentElement).zoom);
234
- if (zoom < 1) {
235
- this.iframeBox.style.zoom = (1 / zoom).toFixed(2);
236
- }
237
- this.iframe = document.createElement("iframe");
238
- this.iframeBg = document.createElement("div");
239
- }
240
- /**
241
- * 创建iframe元素
242
- */
243
- createIframe(def) {
244
- this.iframe.id = this.iframe.name = def.name;
245
- this.iframe.src = def.url;
246
- const option = def.option || {};
247
- this.iframe.width = option.width || 400;
248
- this.iframe.height = option.height || 400;
249
- this.iframe.scrolling = option.scrolling || "no";
250
- this.iframe.marginWidth = option.marginWidth || "0";
251
- this.iframe.marginHeight = option.marginHeight || "0";
252
- this.iframe.frameBorder = option.frameBorder || "0";
253
- }
254
- /**
255
- * 应用样式
256
- */
257
- applyStyles(option) {
258
- Object.assign(this.iframe.style, {
259
- zIndex: 3e3,
260
- position: "fixed",
261
- borderRadius: option.radius || "none",
262
- opacity: 0
263
- });
264
- Object.assign(this.iframeBg.style, {
265
- position: "fixed",
266
- backgroundColor: "#6f6f6f80",
267
- width: "100%",
268
- height: "100%",
269
- top: 0,
270
- left: 0,
271
- opacity: 0
272
- });
273
- this.applyPosition(option.offset || "center");
274
- this.applyAnimation(option);
275
- }
276
- /**
277
- * 应用定位样式
278
- */
279
- applyPosition(offset) {
280
- const positions = {
281
- center: { top: "50%", left: "50%", transform: "translate(-50%, -50%)" },
282
- top: { top: "5%", left: "50%", transform: "translateX(-50%)" },
283
- bottom: { bottom: "5%", left: "50%", transform: "translateX(-50%)" },
284
- lt: { top: "5%", left: "5%" },
285
- lb: { bottom: "5%", left: "5%" },
286
- rt: { top: "5%", right: "5%" },
287
- rb: { bottom: "5%", right: "5%" }
288
- };
289
- const position = positions[offset] || positions.center;
290
- Object.assign(this.iframe.style, position);
291
- }
292
- /**
293
- * 应用动画样式
294
- */
295
- applyAnimation(option) {
296
- const animTime = option.animTime || 300;
297
- this.iframe.style.transition = `opacity ${animTime}ms`;
298
- this.iframeBg.style.transition = `opacity ${animTime}ms`;
299
- this.createAnimationStyles(option.anime || 0);
300
- }
301
- /**
302
- * 创建动画样式
303
- */
304
- createAnimationStyles(anime) {
305
- const styles = {
306
- 0: ".IMP_PLUG_LOGIN_animateIn{opacity:1 !important;} .IMP_PLUG_LOGIN_animateOut{opacity:0 !important;}"
307
- };
308
- const styleCss = styles[anime] || styles[0];
309
- const style = document.createElement("style");
310
- style.id = "IMP_PLUG_LOGIN_animateCss";
311
- try {
312
- style.appendChild(document.createTextNode(styleCss));
313
- } catch (error) {
314
- style.styleSheet.cssText = styleCss;
315
- }
316
- document.head.appendChild(style);
317
- }
318
- /**
319
- * 添加到文档
320
- */
321
- appendToDocument() {
322
- this.iframeBox.append(this.iframe);
323
- this.iframeBox.append(this.iframeBg);
324
- document.body.append(this.iframeBox);
325
- }
326
- /**
327
- * 判断是否顶层窗口
328
- */
329
- istop() {
330
- return parent === window;
331
- }
332
- /**
333
- * 关闭登录框
334
- */
335
- close() {
336
- if (!this.istop()) return;
337
- const removeElements = () => {
338
- if (this.iframeBox) {
339
- this.iframeBox.remove();
340
- this.iframeBox = null;
341
- }
342
- if (this.autoLogin.iframe) {
343
- this.autoLogin.iframe.remove();
344
- }
345
- const animateCss = document.getElementById("IMP_PLUG_LOGIN_animateCss");
346
- if (animateCss) {
347
- animateCss.remove();
348
- }
349
- };
350
- if (this.iframeBg) {
351
- this.iframeBg.classList.remove("IMP_PLUG_LOGIN_animateIn");
352
- this.iframeBg.classList.add("IMP_PLUG_LOGIN_animateOut");
353
- }
354
- if (this.iframe) {
355
- this.iframe.classList.remove("IMP_PLUG_LOGIN_animateIn");
356
- this.iframe.classList.add("IMP_PLUG_LOGIN_animateOut");
357
- this.iframe.addEventListener("transitionend", removeElements, { once: true });
358
- } else {
359
- removeElements();
360
- }
361
- }
362
- /**
363
- * 尺寸自适应
364
- */
365
- autoSize(width, height) {
366
- message.send(this.keys.msg_autoSize, {
367
- width: width || document.body.scrollWidth,
368
- height: height || document.body.scrollHeight
369
- });
370
- }
371
- /**
372
- * 打开登录弹层
373
- */
374
- open(isCustomThen = false) {
375
- if (this.iframeBox) return Promise.resolve();
376
- const pm = new Promise((resolve, reject) => {
377
- this.onLoginOK(resolve, reject);
378
- if (this.istop()) {
379
- this.create({
380
- url: this.urls.login,
381
- name: "signIn",
382
- option: { radius: "4px" }
383
- });
384
- } else {
385
- message.send(this.keys.msg_goto, { url: this.urls.login });
386
- }
387
- });
388
- return isCustomThen ? pm : pm.then(() => location.reload());
389
- }
390
- /**
391
- * 打开登录页面
392
- */
393
- openPage() {
394
- const sourceurl = urltool.getPar("sourceurl") || location.href;
395
- const url = urltool.addPar("sourceurl", unescape(sourceurl), this.urls.loginPage);
396
- location.href = url;
397
- }
398
- /**
399
- * 打开注册弹层
400
- */
401
- openReg(isCustomThen = false) {
402
- if (this.iframeBox) return Promise.resolve();
403
- const pm = new Promise((resolve, reject) => {
404
- this.onLoginOK(resolve, reject);
405
- if (this.istop()) {
406
- this.create({
407
- url: this.urls.reg,
408
- name: "signIn",
409
- option: { radius: "4px" }
410
- });
411
- } else {
412
- message.send(this.keys.msg_goto, { url: this.urls.reg });
413
- }
414
- });
415
- return isCustomThen ? pm : pm.then(() => location.reload());
416
- }
417
- /**
418
- * 打开注册页面
419
- */
420
- openRegPage() {
421
- const sourceurl = urltool.getPar("sourceurl") || location.href;
422
- const url = urltool.addPar("sourceurl", unescape(sourceurl), this.urls.regPage);
423
- location.href = url;
424
- }
425
- /**
426
- * 三方登录
427
- */
428
- threeLogin(type, options) {
429
- return new Promise((resolve, reject) => {
430
- this.closeThreeLoginWin();
431
- this.onLoginOK(resolve, reject);
432
- const url = handleUrl(`/v1.0.0/user/OpenThreeLogin?type=${type}`, options);
433
- this.threeLoginWin = window.open(url);
434
- });
435
- }
436
- /**
437
- * 关闭三方登录窗口
438
- */
439
- closeThreeLoginWin() {
440
- if (this.threeLoginWin) {
441
- this.threeLoginWin.close();
442
- this.threeLoginWin = null;
443
- }
444
- }
445
- /**
446
- * 获取微信code
447
- */
448
- getWechatCode() {
449
- const code = urltool.getPar("__login_code");
450
- if (!code) {
451
- const url = `${this.loginDomain}/v1.0.0/user/OpenThreeLogin?type=wechatcode&redirect_uri=${encodeURIComponent(location.href)}`;
452
- location.href = url;
453
- }
454
- return code;
455
- }
456
- /**
457
- * 获取登录信息
458
- */
459
- getLogin(user, alldata = false) {
460
- const userinfo = user || cache.get(this.keys.cache_loginSave);
461
- if (!userinfo) return null;
462
- if (!alldata) {
463
- delete userinfo.sign;
464
- }
465
- return userinfo;
466
- }
467
- /**
468
- * 获取用户信息
469
- */
470
- getUser(okcallback, ismore = false, isForce = false) {
471
- if (typeof okcallback !== "function") {
472
- isForce = ismore;
473
- ismore = okcallback;
474
- okcallback = null;
475
- }
476
- const pm = new Promise((resolve, reject) => {
477
- const cacheKey = this.keys.cache_userInfo + "_" + (ismore ? "more" : "simplify");
478
- if (!isForce) {
479
- const userinfo = cache.get(cacheKey);
480
- if (userinfo) {
481
- resolve(userinfo);
482
- return;
483
- }
484
- }
485
- axios.get(this.urls.userInfo, { more: ismore ? 1 : 0 }).then((res) => {
486
- if (res.code === 1) {
487
- cache.set(cacheKey, res.data, this.loginTime);
488
- resolve(res.data);
489
- } else {
490
- reject(res);
491
- }
492
- });
493
- });
494
- return okcallback ? pm.then(okcallback) : pm;
495
- }
496
- /**
497
- * 判断是否登录
498
- */
499
- islogin() {
500
- return !!this.getLogin();
501
- }
502
- /**
503
- * 验证登录状态
504
- */
505
- async check() {
506
- if (!this.isTempCheck && this.islogin()) {
507
- return true;
508
- }
509
- return this.checkZ();
510
- }
511
- /**
512
- * 强制从登录站验证登录
513
- */
514
- checkZ() {
515
- return new Promise((resolve, reject) => {
516
- if (!this.autoLogin.iframe && !this.autoLogin.window) {
517
- let url = this.urls.autoLogin;
518
- url = urltool.addPars({
519
- "sign": urltool.getPar(this.keys.url_tempSignKey),
520
- "useridx": urltool.getPar(this.keys.url_tempUseridxKey)
521
- }, url);
522
- this.autoLogin.iframe = this.getIframeUrl(url, this.keys.msg_loginReturn);
523
- this.autoLogin.callbacks = [];
524
- }
525
- this.autoLogin.callbacks.push({
526
- ok: resolve,
527
- no: () => {
528
- resolve(false);
529
- }
530
- // , no: () => {
531
- // log.debug("登录出现异常,退出登录!");
532
- // get(this.urls.webLoginOut, null, () => {
533
- // reject.apply(this, arguments);
534
- // }, "text");
535
- // }
536
- });
537
- });
538
- }
539
- /**
540
- * 临时验证登录
541
- */
542
- async checkTemp() {
543
- this.isTempCheck = urltool.getPar(this.keys.url_tempSignKey) && urltool.getPar(this.keys.url_tempUseridxKey);
544
- if (this.isTempCheck) {
545
- return this.checkZ();
546
- }
547
- }
548
- /**
549
- * 页面跳转验证登录
550
- */
551
- checkPage() {
552
- return new Promise((resolve, reject) => {
553
- const checkLogin_code = urltool.getPar(this.keys.checkLogin_code);
554
- const loginStatus = parseInt(urltool.getPar(this.keys.loginStatus) || -1);
555
- log.debug("checkLogin_code:", checkLogin_code);
556
- if (loginStatus === 0) {
557
- urltool.delParsUpUrl([this.keys.loginStatus]);
558
- reject("用户未登录!");
559
- } else if (loginStatus && checkLogin_code) {
560
- axios.get(this.urls.CheckLoginByCode, { code: checkLogin_code }).then((res) => {
561
- if (res.code === 1) {
562
- urltool.delParsUpUrl([this.keys.checkLogin_code, this.keys.loginStatus]);
563
- this.save(res.data);
564
- resolve(res);
565
- } else {
566
- reject();
567
- }
568
- });
569
- } else {
570
- axios.get(this.urls.checkSSOLogin).then((res) => {
571
- if (res.code === 1) {
572
- this.getUser().then(resolve);
573
- } else {
574
- let url = urltool.addPars({
575
- "redirect_uri": encodeURIComponent(location.href)
576
- }, this.urls.checkLoginPage);
577
- location.href = url;
578
- }
579
- });
580
- }
581
- });
582
- }
583
- /**
584
- * 获取登录回调结果
585
- */
586
- res(callback) {
587
- const resStr = decodeURIComponent(urltool.getPar(this.keys.loginResult) || "");
588
- if (resStr) {
589
- const res = JSON.parse(resStr);
590
- callback?.(res);
591
- urltool.delParsUpUrl([this.keys.loginResult]);
592
- }
593
- }
594
- /**
595
- * 退出登录
596
- */
597
- exit(isCustomThen = false) {
598
- log.debug("退出登录!");
599
- if (!this.exitLogin.Promise) {
600
- this.exitLogin.Promise = new Promise((resolve) => {
601
- iframeReq.get(this.urls.exitLogin).then((res) => {
602
- get(this.urls.webLoginOut, null, () => {
603
- resolve(res);
604
- }, "text");
605
- this.clear();
606
- this.exitLogin = {};
607
- });
608
- });
609
- if (!isCustomThen) {
610
- this.exitLogin.Promise = this.exitLogin.Promise.then(() => {
611
- location.reload();
612
- });
613
- }
614
- }
615
- return this.exitLogin.Promise;
616
- }
617
- /**
618
- * 创建隐藏iframe
619
- */
620
- getIframeUrl(url, postMessageName) {
621
- const iframe = document.createElement("iframe");
622
- Object.assign(iframe.style, {
623
- position: "absolute",
624
- width: "1px",
625
- height: "1px",
626
- top: "-100px"
627
- });
628
- iframe.dataset.flag = 9513;
629
- if (postMessageName) {
630
- url = urltool.addPar("post_msg_name", postMessageName, url);
631
- }
632
- iframe.src = url;
633
- const timeout = 1e4;
634
- let timeoutId;
635
- let isResolved = false;
636
- const cleanup = () => {
637
- iframe.removeEventListener("error", onError);
638
- clearTimeout(timeoutId);
639
- };
640
- const onLoad = (event2) => {
641
- if (isResolved) return;
642
- isResolved = true;
643
- cleanup();
644
- console.log("登录页面已打开");
645
- };
646
- const onError = (event2) => {
647
- if (isResolved) return;
648
- isResolved = true;
649
- cleanup();
650
- iframe.remove();
651
- this.runAutoLoginCallback(false);
652
- };
653
- iframe.addEventListener("load", onLoad, { once: true });
654
- iframe.addEventListener("error", onError, { once: true });
655
- timeoutId = setTimeout(() => {
656
- onError();
657
- }, timeout);
658
- document.body.append(iframe);
659
- return iframe;
660
- }
661
- /**
662
- * 注册未登录事件
663
- */
664
- onNoLogin(callback) {
665
- if (!event) {
666
- console.warn("事件模块event未加载,事件相关功能不可用!");
667
- return;
668
- }
669
- event.on(this.eventKeys.nologin, callback);
670
- }
671
- /**
672
- * 执行未登录事件
673
- */
674
- runNoLogin(res) {
675
- if (!event) {
676
- console.warn("事件模块event未加载,事件相关功能不可用!");
677
- return Promise.resolve();
678
- }
679
- return Promise.resolve(event.run(this.eventKeys.nologin, res));
680
- }
681
- /**
682
- * 写登录信息到xhr
683
- */
684
- writeXhr(xhr) {
685
- if (!xhr) {
686
- console.warn("xhr不能为空!");
687
- return xhr;
688
- }
689
- const user = this.getLogin(null, true);
690
- if (user) {
691
- xhr.withCredentials = true;
692
- xhr.setRequestHeader("imp_sign", user.sign);
693
- xhr.setRequestHeader("imp_useridx", user.useridx);
694
- }
695
- return xhr;
696
- }
697
- /**
698
- * 调试输出
699
- */
700
- debug(...args) {
701
- if (console && console.debug) {
702
- console.debug(...args);
703
- }
704
- }
705
- }
706
- const login = new Login();
707
- export {
708
- Login,
709
- login as default,
710
- login
711
- };
1
+ import"../axios/index.es.js";import{extend as e}from"../packages/com/dist/core/index.es/index.es.js";import{getLog as i}from"../packages/com/dist/log/index.es/index.es.js";import{isBoolean as t}from"../packages/com/dist/typetool/index.es/index.es.js";import"../packages/com/dist/browser/index.es/index.es.js";import"../packages/com/dist/str/index.es/index.es.js";import{cache as s}from"../packages/com/dist/cache/index.es/index.es.js";import"../packages/com/dist/req/index.es/index.es.js";import{urltool as o}from"../packages/com/dist/url/index.es/index.es.js";import{message as n}from"../packages/com/dist/message/index.es/index.es.js";import{event as r}from"@impui/com/event";import{handleUrl as a}from"../core/index.es.js";import{getConfig as h,getEvnConfig as l}from"../config/index.es.js";import{iframeReq as c,get as g}from"@impui/com/req";import m from"../node_modules/axios/lib/axios/index.es.js";import"../node_modules/axios/index/index.es.js";const d=await h(),u=await i();class p{constructor(){this.loginDomain=window.loginDomain="localhost"===location.hostname&&l().isLocalhost?"https://localhost:44360":d.domainLogin,this.ver="v1.0.0",this.loginTime=21600,this.prefix="IMP_PLUG_LOGIN_",this.initUrls(),this.initKeys(),this.initEventKeys(),this.bindEvents(),this.iframeBox=null,this.iframe=null,this.iframeBg=null,this.autoLogin={},this.exitLogin={},this.threeLoginWin=null,this.checkTemp(),window.login=this}initUrls(){this.urls={login:a(this.loginDomain+"/index.html",!0),reg:a(this.loginDomain+"/index.html?type=reg",!0),loginPage:a(this.loginDomain+"/loginPage.html",!0),regPage:a(this.loginDomain+"/regPage.html",!0),autoLogin:a(this.loginDomain+"/"+this.ver+"/user/autoLogin"),checkSSOLogin:a(this.loginDomain+"/"+this.ver+"/user/checkSSOLogin"),checkLoginPage:a(this.loginDomain+"/"+this.ver+"/user/checkLoginPage"),CheckLoginByCode:a(this.loginDomain+"/"+this.ver+"/user/CheckLoginByCode"),exitLogin:this.loginDomain+"/"+this.ver+"/user/exitLogin",userInfo:this.loginDomain+"/"+this.ver+"/user/UserInfo",writeCookies:"/ashx/member/CheckSSOWriteCookie.ashx",webLoginOut:"/ajax/logout.aspx"}}initKeys(){const e=e=>this.prefix+e;this.keys={msg_loginReturn:e("loginReturn"),msg_close:e("close"),msg_goto:e("goto"),msg_autoSize:e("autoSize"),msg_getSize:e("getSize"),cache_loginSave:e("loginSave"),cache_userInfo:e("userInfo"),checkLogin_code:"code",loginStatus:"__login_status",loginResult:"__login_result",url_tempSignKey:"sign",url_tempUseridxKey:"useridx"}}initEventKeys(){const e=e=>this.prefix+e;this.eventKeys={nologin:e("login"),closeThreeLogin:e("close_login_three")}}bindEvents(){n.on(this.keys.msg_close,()=>{u.debug("关闭登录框"),this.close()}),n.on(this.keys.msg_goto,e=>{this.handlePageTransition(e)}),n.on(this.keys.msg_autoSize,e=>{this.handleAutoSize(e)}),n.on(this.keys.msg_loginReturn,async e=>{await this.dealwithLoginRes(e)}),n.on(this.eventKeys.closeThreeLogin,e=>{this.save(e),this.closeThreeLoginWin()}),r.onM("login","getLogin",this.getLogin.bind(this)),r.onM("login","noLogin",this.runNoLogin.bind(this))}handlePageTransition(e){if(!this.iframe)return;this.iframe.classList.remove("IMP_PLUG_LOGIN_animateIn"),this.iframe.classList.add("IMP_PLUG_LOGIN_animateOut");const i=()=>{this.iframe.src=e.url,this.iframe.classList.remove("IMP_PLUG_LOGIN_animateOut"),this.iframe.removeEventListener("transitionend",i)};this.iframe.addEventListener("transitionend",i)}handleAutoSize(e){this.iframe&&(u.debug("登录框尺寸适配",e),this.iframe.width=e.width,this.iframe.height=e.height,this.iframe.classList.add("IMP_PLUG_LOGIN_animateIn"),this.iframeBg.classList.add("IMP_PLUG_LOGIN_animateIn"))}runAutoLoginCallback(e,i){this.autoLogin.callbacks&&0!==this.autoLogin.callbacks.length&&(this.autoLogin.callbacks.forEach(i=>{if(t(e))i.ok&&i.ok(e);else{const t=this.getLogin(e);i.ok&&i.ok(t&&t.code===m.codeEnum.success)}}),this.autoLogin.iframe&&this.autoLogin.iframe.remove(),this.autoLogin.window&&this.autoLogin.window.close(),this.autoLogin={},e&&this.close())}async dealwithLoginRes(e){if(u.debug("登录消息返回",e),e.isok=e.code===m.codeEnum.success,1!==e.code)return this.clear(),void this.runAutoLoginCallback(e);if(e.sign&&8===e.sign.length)this.save(e);else{o.delParsUpUrl([this.keys.url_tempSignKey,this.keys.url_tempUseridxKey]),s.set(this.keys.cache_loginSave,e,this.loginTime),m.saveLogin(e.useridx,e.sign);try{d.domainmaster.startsWith(location.origin)&&await m.get(this.urls.writeCookies,null,null,"text")}finally{this.runAutoLoginCallback(e)}}}save(e){const i=e.__source?.headers?.[e.sign]||e.data?.headers?.[e.sign]||e.sign,t=e.useridx||e.data?.___useridx;n.send(this.keys.msg_loginReturn,{code:e.code,msg:e.msg,sign:i,useridx:t})}clear(){s.remove(this.keys.cache_loginSave),s.remove(this.keys.cache_userInfo),s.remove(this.keys.cache_userInfo+"_more"),s.remove(this.keys.cache_userInfo+"_simplify")}onLoginOK(e,i){this.autoLogin.callbacks||(this.autoLogin.callbacks=[]),this.autoLogin.callbacks.push({ok:e,no:i})}create(i){const t=e(!0,{url:"",name:"",option:null},i);this.createIframeBox(),this.createIframe(t),this.applyStyles(t.option||{}),this.appendToDocument()}createIframeBox(){this.iframeBox=document.createElement("div"),this.iframeBox.className="IMP_PLUG_LOGIN_box";const e=parseFloat(window.getComputedStyle(document.documentElement).zoom);e<1&&(this.iframeBox.style.zoom=(1/e).toFixed(2)),this.iframe=document.createElement("iframe"),this.iframeBg=document.createElement("div")}createIframe(e){this.iframe.id=this.iframe.name=e.name,this.iframe.src=e.url;const i=e.option||{};this.iframe.width=i.width||400,this.iframe.height=i.height||400,this.iframe.scrolling=i.scrolling||"no",this.iframe.marginWidth=i.marginWidth||"0",this.iframe.marginHeight=i.marginHeight||"0",this.iframe.frameBorder=i.frameBorder||"0"}applyStyles(e){Object.assign(this.iframe.style,{zIndex:3e3,position:"fixed",borderRadius:e.radius||"none",opacity:0}),Object.assign(this.iframeBg.style,{position:"fixed",backgroundColor:"#6f6f6f80",width:"100%",height:"100%",top:0,left:0,opacity:0}),this.applyPosition(e.offset||"center"),this.applyAnimation(e)}applyPosition(e){const i={center:{top:"50%",left:"50%",transform:"translate(-50%, -50%)"},top:{top:"5%",left:"50%",transform:"translateX(-50%)"},bottom:{bottom:"5%",left:"50%",transform:"translateX(-50%)"},lt:{top:"5%",left:"5%"},lb:{bottom:"5%",left:"5%"},rt:{top:"5%",right:"5%"},rb:{bottom:"5%",right:"5%"}},t=i[e]||i.center;Object.assign(this.iframe.style,t)}applyAnimation(e){const i=e.animTime||300;this.iframe.style.transition=`opacity ${i}ms`,this.iframeBg.style.transition=`opacity ${i}ms`,this.createAnimationStyles(e.anime||0)}createAnimationStyles(e){const i={0:".IMP_PLUG_LOGIN_animateIn{opacity:1 !important;} .IMP_PLUG_LOGIN_animateOut{opacity:0 !important;}"},t=i[e]||i[0],s=document.createElement("style");s.id="IMP_PLUG_LOGIN_animateCss";try{s.appendChild(document.createTextNode(t))}catch(o){s.styleSheet.cssText=t}document.head.appendChild(s)}appendToDocument(){this.iframeBox.append(this.iframe),this.iframeBox.append(this.iframeBg),document.body.append(this.iframeBox)}istop(){return parent===window}close(){if(!this.istop())return;const e=()=>{this.iframeBox&&(this.iframeBox.remove(),this.iframeBox=null),this.autoLogin.iframe&&this.autoLogin.iframe.remove();const e=document.getElementById("IMP_PLUG_LOGIN_animateCss");e&&e.remove()};this.iframeBg&&(this.iframeBg.classList.remove("IMP_PLUG_LOGIN_animateIn"),this.iframeBg.classList.add("IMP_PLUG_LOGIN_animateOut")),this.iframe?(this.iframe.classList.remove("IMP_PLUG_LOGIN_animateIn"),this.iframe.classList.add("IMP_PLUG_LOGIN_animateOut"),this.iframe.addEventListener("transitionend",e,{once:!0})):e()}autoSize(e,i){n.send(this.keys.msg_autoSize,{width:e||document.body.scrollWidth,height:i||document.body.scrollHeight})}open(e=!1){if(this.iframeBox)return Promise.resolve();const i=new Promise((e,i)=>{this.onLoginOK(e,i),this.istop()?this.create({url:this.urls.login,name:"signIn",option:{radius:"4px"}}):n.send(this.keys.msg_goto,{url:this.urls.login})});return e?i:i.then(()=>location.reload())}openPage(){const e=o.getPar("sourceurl")||location.href,i=o.addPar("sourceurl",unescape(e),this.urls.loginPage);location.href=i}openReg(e=!1){if(this.iframeBox)return Promise.resolve();const i=new Promise((e,i)=>{this.onLoginOK(e,i),this.istop()?this.create({url:this.urls.reg,name:"signIn",option:{radius:"4px"}}):n.send(this.keys.msg_goto,{url:this.urls.reg})});return e?i:i.then(()=>location.reload())}openRegPage(){const e=o.getPar("sourceurl")||location.href,i=o.addPar("sourceurl",unescape(e),this.urls.regPage);location.href=i}threeLogin(e,i){return new Promise((t,s)=>{this.closeThreeLoginWin(),this.onLoginOK(t,s);const o=a(`/v1.0.0/user/OpenThreeLogin?type=${e}`,i);this.threeLoginWin=window.open(o)})}closeThreeLoginWin(){this.threeLoginWin&&(this.threeLoginWin.close(),this.threeLoginWin=null)}getWechatCode(){const e=o.getPar("__login_code");if(!e){const e=`${this.loginDomain}/v1.0.0/user/OpenThreeLogin?type=wechatcode&redirect_uri=${encodeURIComponent(location.href)}`;location.href=e}return e}getLogin(e,i=!1){const t=e||s.get(this.keys.cache_loginSave);return t?(i||delete t.sign,t):null}getUser(e,i=!1,t=!1){"function"!=typeof e&&(t=i,i=e,e=null);const o=new Promise((e,o)=>{const n=this.keys.cache_userInfo+"_"+(i?"more":"simplify");if(!t){const i=s.get(n);if(i)return void e(i)}m.get(this.urls.userInfo,{more:i?1:0}).then(i=>{1===i.code?(s.set(n,i.data,this.loginTime),e(i.data)):o(i)})});return e?o.then(e):o}islogin(){return!!this.getLogin()}async check(){return!(this.isTempCheck||!this.islogin())||this.checkZ()}checkZ(){return new Promise((e,i)=>{if(!this.autoLogin.iframe&&!this.autoLogin.window){let e=this.urls.autoLogin;e=o.addPars({sign:o.getPar(this.keys.url_tempSignKey),useridx:o.getPar(this.keys.url_tempUseridxKey)},e),this.autoLogin.iframe=this.getIframeUrl(e,this.keys.msg_loginReturn),this.autoLogin.callbacks=[]}this.autoLogin.callbacks.push({ok:e,no:()=>{e(!1)}})})}async checkTemp(){if(this.isTempCheck=o.getPar(this.keys.url_tempSignKey)&&o.getPar(this.keys.url_tempUseridxKey),this.isTempCheck)return this.checkZ()}checkPage(){return new Promise((e,i)=>{const t=o.getPar(this.keys.checkLogin_code),s=parseInt(o.getPar(this.keys.loginStatus)||-1);u.debug("checkLogin_code:",t),0===s?(o.delParsUpUrl([this.keys.loginStatus]),i("用户未登录!")):s&&t?m.get(this.urls.CheckLoginByCode,{code:t}).then(t=>{1===t.code?(o.delParsUpUrl([this.keys.checkLogin_code,this.keys.loginStatus]),this.save(t.data),e(t)):i()}):m.get(this.urls.checkSSOLogin).then(i=>{if(1===i.code)this.getUser().then(e);else{let e=o.addPars({redirect_uri:encodeURIComponent(location.href)},this.urls.checkLoginPage);location.href=e}})})}res(e){const i=decodeURIComponent(o.getPar(this.keys.loginResult)||"");if(i){const t=JSON.parse(i);e?.(t),o.delParsUpUrl([this.keys.loginResult])}}exit(e=!1){return u.debug("退出登录!"),this.exitLogin.Promise||(this.exitLogin.Promise=new Promise(e=>{c.get(this.urls.exitLogin).then(i=>{g(this.urls.webLoginOut,null,()=>{e(i)},"text"),this.clear(),this.exitLogin={}})}),e||(this.exitLogin.Promise=this.exitLogin.Promise.then(()=>{location.reload()}))),this.exitLogin.Promise}getIframeUrl(e,i){const t=document.createElement("iframe");Object.assign(t.style,{position:"absolute",width:"1px",height:"1px",top:"-100px"}),t.dataset.flag=9513,i&&(e=o.addPar("post_msg_name",i,e)),t.src=e;let s,n=!1;const r=()=>{t.removeEventListener("error",a),clearTimeout(s)},a=e=>{n||(n=!0,r(),t.remove(),this.runAutoLoginCallback(!1))};return t.addEventListener("load",e=>{n||(n=!0,r(),console.log("登录页面已打开"))},{once:!0}),t.addEventListener("error",a,{once:!0}),s=setTimeout(()=>{a()},1e4),document.body.append(t),t}onNoLogin(e){r?r.on(this.eventKeys.nologin,e):console.warn("事件模块event未加载,事件相关功能不可用!")}runNoLogin(e){return r?Promise.resolve(r.run(this.eventKeys.nologin,e)):(console.warn("事件模块event未加载,事件相关功能不可用!"),Promise.resolve())}writeXhr(e){if(!e)return console.warn("xhr不能为空!"),e;const i=this.getLogin(null,!0);return i&&(e.withCredentials=!0,e.setRequestHeader("imp_sign",i.sign),e.setRequestHeader("imp_useridx",i.useridx)),e}debug(...e){console&&console.debug&&console.debug(...e)}}const f=new p;export{p as Login,f as default,f as login};