@impui/imp 1.0.15 → 1.0.16-beta.0
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.
- package/dist/axios/index.es.js +143 -0
- package/dist/config/index.es.js +127 -0
- package/dist/core/index.es.js +34 -0
- package/dist/gotool/go2/index.es.js +510 -0
- package/dist/gotool/index/index.es.js +164 -0
- package/dist/imph5/index.es.js +324 -0
- package/dist/index.es.js +49 -1
- package/dist/login/index.es.js +711 -0
- package/dist/node_modules/axios/index/index.es.js +38 -0
- package/dist/node_modules/axios/lib/adapters/adapters/index.es.js +71 -0
- package/dist/node_modules/axios/lib/adapters/fetch/index.es.js +219 -0
- package/dist/node_modules/axios/lib/adapters/xhr/index.es.js +141 -0
- package/dist/node_modules/axios/lib/axios/index.es.js +50 -0
- package/dist/node_modules/axios/lib/cancel/CancelToken/index.es.js +99 -0
- package/dist/node_modules/axios/lib/cancel/CanceledError/index.es.js +12 -0
- package/dist/node_modules/axios/lib/cancel/isCancel/index.es.js +6 -0
- package/dist/node_modules/axios/lib/core/Axios/index.es.js +180 -0
- package/dist/node_modules/axios/lib/core/AxiosError/index.es.js +80 -0
- package/dist/node_modules/axios/lib/core/AxiosHeaders/index.es.js +231 -0
- package/dist/node_modules/axios/lib/core/InterceptorManager/index.es.js +65 -0
- package/dist/node_modules/axios/lib/core/buildFullPath/index.es.js +12 -0
- package/dist/node_modules/axios/lib/core/dispatchRequest/index.es.js +52 -0
- package/dist/node_modules/axios/lib/core/mergeConfig/index.es.js +83 -0
- package/dist/node_modules/axios/lib/core/settle/index.es.js +18 -0
- package/dist/node_modules/axios/lib/core/transformData/index.es.js +17 -0
- package/dist/node_modules/axios/lib/defaults/index/index.es.js +116 -0
- package/dist/node_modules/axios/lib/defaults/transitional/index.es.js +8 -0
- package/dist/node_modules/axios/lib/env/data/index.es.js +4 -0
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams/index.es.js +34 -0
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode/index.es.js +77 -0
- package/dist/node_modules/axios/lib/helpers/bind/index.es.js +8 -0
- package/dist/node_modules/axios/lib/helpers/buildURL/index.es.js +34 -0
- package/dist/node_modules/axios/lib/helpers/combineURLs/index.es.js +6 -0
- package/dist/node_modules/axios/lib/helpers/composeSignals/index.es.js +39 -0
- package/dist/node_modules/axios/lib/helpers/cookies/index.es.js +49 -0
- package/dist/node_modules/axios/lib/helpers/formDataToJSON/index.es.js +54 -0
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL/index.es.js +6 -0
- package/dist/node_modules/axios/lib/helpers/isAxiosError/index.es.js +7 -0
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin/index.es.js +11 -0
- package/dist/node_modules/axios/lib/helpers/null/index.es.js +4 -0
- package/dist/node_modules/axios/lib/helpers/parseHeaders/index.es.js +47 -0
- package/dist/node_modules/axios/lib/helpers/parseProtocol/index.es.js +7 -0
- package/dist/node_modules/axios/lib/helpers/progressEventReducer/index.es.js +41 -0
- package/dist/node_modules/axios/lib/helpers/resolveConfig/index.es.js +46 -0
- package/dist/node_modules/axios/lib/helpers/speedometer/index.es.js +36 -0
- package/dist/node_modules/axios/lib/helpers/spread/index.es.js +8 -0
- package/dist/node_modules/axios/lib/helpers/throttle/index.es.js +35 -0
- package/dist/node_modules/axios/lib/helpers/toFormData/index.es.js +117 -0
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm/index.es.js +18 -0
- package/dist/node_modules/axios/lib/helpers/trackStream/index.es.js +80 -0
- package/dist/node_modules/axios/lib/helpers/validator/index.es.js +67 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob/index.es.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData/index.es.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams/index.es.js +5 -0
- package/dist/node_modules/axios/lib/platform/browser/index/index.es.js +15 -0
- package/dist/node_modules/axios/lib/platform/common/utils/index.es.js +15 -0
- package/dist/node_modules/axios/lib/platform/index/index.es.js +9 -0
- package/dist/node_modules/axios/lib/utils/index.es.js +387 -0
- package/dist/packages/com/dist/browser/index.es/index.es.js +1 -0
- package/dist/packages/com/dist/cache/index.es/index.es.js +145 -0
- package/dist/packages/com/dist/core/index.es/index.es.js +154 -0
- package/dist/packages/com/dist/data/index.es/index.es.js +26 -0
- package/dist/packages/com/dist/date/index.es/index.es.js +194 -0
- package/dist/packages/com/dist/log/index.es/index.es.js +110 -0
- package/dist/packages/com/dist/message/index.es/index.es.js +90 -0
- package/dist/packages/com/dist/req/index.es/index.es.js +35 -0
- package/dist/packages/com/dist/str/index.es/index.es.js +25 -0
- package/dist/packages/com/dist/typetool/index.es/index.es.js +53 -0
- package/dist/packages/com/dist/url/index.es/index.es.js +238 -0
- package/dist/restool/index/index.es.js +266 -0
- package/dist/restool/index.css/index.es.js +4 -0
- package/package.json +2 -3
|
@@ -0,0 +1,711 @@
|
|
|
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
|
+
};
|