@kevisual/kv-login 0.1.2 → 0.1.4
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/app.d.ts +4 -1
- package/dist/app.js +1174 -223
- package/package.json +6 -4
- package/src/main.ts +1 -2
- package/src/modules/login-handle.ts +21 -1
- package/src/pages/kv-login.ts +25 -12
package/dist/app.js
CHANGED
|
@@ -2052,7 +2052,7 @@ var require_browser = __commonJS((exports) => {
|
|
|
2052
2052
|
});
|
|
2053
2053
|
});
|
|
2054
2054
|
|
|
2055
|
-
// ../../node_modules/.pnpm/lit-html@3.3.
|
|
2055
|
+
// ../../node_modules/.pnpm/lit-html@3.3.2/node_modules/lit-html/development/lit-html.js
|
|
2056
2056
|
var DEV_MODE = true;
|
|
2057
2057
|
var ENABLE_EXTRA_SECURITY_HOOKS = true;
|
|
2058
2058
|
var ENABLE_SHADYDOM_NOPATCH = true;
|
|
@@ -2857,7 +2857,7 @@ class ElementPart {
|
|
|
2857
2857
|
}
|
|
2858
2858
|
var polyfillSupport = DEV_MODE ? global.litHtmlPolyfillSupportDevMode : global.litHtmlPolyfillSupport;
|
|
2859
2859
|
polyfillSupport?.(Template, ChildPart);
|
|
2860
|
-
(global.litHtmlVersions ??= []).push("3.3.
|
|
2860
|
+
(global.litHtmlVersions ??= []).push("3.3.2");
|
|
2861
2861
|
if (DEV_MODE && global.litHtmlVersions.length > 1) {
|
|
2862
2862
|
queueMicrotask(() => {
|
|
2863
2863
|
issueWarning("multiple-versions", `Multiple versions of Lit loaded. ` + `Loading multiple versions is not recommended.`);
|
|
@@ -2901,7 +2901,7 @@ if (ENABLE_EXTRA_SECURITY_HOOKS) {
|
|
|
2901
2901
|
}
|
|
2902
2902
|
}
|
|
2903
2903
|
|
|
2904
|
-
// ../../node_modules/.pnpm/lit-html@3.3.
|
|
2904
|
+
// ../../node_modules/.pnpm/lit-html@3.3.2/node_modules/lit-html/development/directive.js
|
|
2905
2905
|
var PartType = {
|
|
2906
2906
|
ATTRIBUTE: 1,
|
|
2907
2907
|
CHILD: 2,
|
|
@@ -2933,7 +2933,7 @@ class Directive {
|
|
|
2933
2933
|
}
|
|
2934
2934
|
}
|
|
2935
2935
|
|
|
2936
|
-
// ../../node_modules/.pnpm/lit-html@3.3.
|
|
2936
|
+
// ../../node_modules/.pnpm/lit-html@3.3.2/node_modules/lit-html/development/directives/unsafe-html.js
|
|
2937
2937
|
var HTML_RESULT2 = 1;
|
|
2938
2938
|
|
|
2939
2939
|
class UnsafeHTMLDirective extends Directive {
|
|
@@ -2972,19 +2972,23 @@ UnsafeHTMLDirective.directiveName = "unsafeHTML";
|
|
|
2972
2972
|
UnsafeHTMLDirective.resultType = HTML_RESULT2;
|
|
2973
2973
|
var unsafeHTML = directive(UnsafeHTMLDirective);
|
|
2974
2974
|
|
|
2975
|
-
// ../../node_modules/.pnpm/@kevisual+query@0.0.
|
|
2975
|
+
// ../../node_modules/.pnpm/@kevisual+query@0.0.33/node_modules/@kevisual/query/dist/query-browser.js
|
|
2976
2976
|
var isTextForContentType = (contentType) => {
|
|
2977
2977
|
if (!contentType)
|
|
2978
2978
|
return false;
|
|
2979
|
-
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded"];
|
|
2979
|
+
const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
|
|
2980
2980
|
return textTypes.some((type) => contentType.includes(type));
|
|
2981
2981
|
};
|
|
2982
2982
|
var adapter = async (opts = {}, overloadOpts) => {
|
|
2983
2983
|
const controller = new AbortController;
|
|
2984
2984
|
const signal = controller.signal;
|
|
2985
|
-
const isBlob = opts.isBlob || false;
|
|
2986
|
-
const isText = opts.isText || false;
|
|
2987
2985
|
const isPostFile = opts.isPostFile || false;
|
|
2986
|
+
let responseType = opts.responseType || "json";
|
|
2987
|
+
if (opts.isBlob) {
|
|
2988
|
+
responseType = "blob";
|
|
2989
|
+
} else if (opts.isText) {
|
|
2990
|
+
responseType = "text";
|
|
2991
|
+
}
|
|
2988
2992
|
const timeout = opts.timeout || 60000 * 3;
|
|
2989
2993
|
const timer = setTimeout(() => {
|
|
2990
2994
|
controller.abort();
|
|
@@ -3002,6 +3006,9 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3002
3006
|
const isGet = method === "GET";
|
|
3003
3007
|
if (isGet) {
|
|
3004
3008
|
url.search = new URLSearchParams(opts.body).toString();
|
|
3009
|
+
} else {
|
|
3010
|
+
const params = opts.params || {};
|
|
3011
|
+
url.search = new URLSearchParams(params).toString();
|
|
3005
3012
|
}
|
|
3006
3013
|
let body = undefined;
|
|
3007
3014
|
if (isGet) {
|
|
@@ -3023,15 +3030,16 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3023
3030
|
headers
|
|
3024
3031
|
}).then(async (response) => {
|
|
3025
3032
|
const contentType = response.headers.get("Content-Type");
|
|
3026
|
-
if (
|
|
3033
|
+
if (responseType === "blob") {
|
|
3027
3034
|
return await response.blob();
|
|
3028
3035
|
}
|
|
3036
|
+
const isText = responseType === "text";
|
|
3029
3037
|
const isJson = contentType && contentType.includes("application/json");
|
|
3030
3038
|
if (isJson && !isText) {
|
|
3031
3039
|
return await response.json();
|
|
3032
3040
|
} else if (isTextForContentType(contentType)) {
|
|
3033
3041
|
return {
|
|
3034
|
-
code:
|
|
3042
|
+
code: response.status,
|
|
3035
3043
|
status: response.status,
|
|
3036
3044
|
data: await response.text()
|
|
3037
3045
|
};
|
|
@@ -3050,15 +3058,6 @@ var adapter = async (opts = {}, overloadOpts) => {
|
|
|
3050
3058
|
clearTimeout(timer);
|
|
3051
3059
|
});
|
|
3052
3060
|
};
|
|
3053
|
-
var setBaseResponse = (res) => {
|
|
3054
|
-
res.success = res.code === 200;
|
|
3055
|
-
res.showError = (fn) => {
|
|
3056
|
-
if (!res.success && !res.noMsg) {
|
|
3057
|
-
fn?.();
|
|
3058
|
-
}
|
|
3059
|
-
};
|
|
3060
|
-
return res;
|
|
3061
|
-
};
|
|
3062
3061
|
var wrapperError = ({ code, message }) => {
|
|
3063
3062
|
const result = {
|
|
3064
3063
|
code: code || 500,
|
|
@@ -3079,9 +3078,11 @@ class Query {
|
|
|
3079
3078
|
timeout;
|
|
3080
3079
|
stop;
|
|
3081
3080
|
qws;
|
|
3081
|
+
isClient = false;
|
|
3082
3082
|
constructor(opts) {
|
|
3083
3083
|
this.adapter = opts?.adapter || adapter;
|
|
3084
|
-
|
|
3084
|
+
const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
|
|
3085
|
+
this.url = opts?.url || defaultURL;
|
|
3085
3086
|
this.headers = opts?.headers || {
|
|
3086
3087
|
"Content-Type": "application/json"
|
|
3087
3088
|
};
|
|
@@ -3147,7 +3148,6 @@ class Query {
|
|
|
3147
3148
|
}
|
|
3148
3149
|
return _adapter(req).then(async (res) => {
|
|
3149
3150
|
try {
|
|
3150
|
-
setBaseResponse(res);
|
|
3151
3151
|
if (_afterResponse) {
|
|
3152
3152
|
return await _afterResponse(res, {
|
|
3153
3153
|
req,
|
|
@@ -3187,7 +3187,13 @@ class Query {
|
|
|
3187
3187
|
..._options?.headers || {}
|
|
3188
3188
|
}
|
|
3189
3189
|
});
|
|
3190
|
-
|
|
3190
|
+
if (res && !res.code) {
|
|
3191
|
+
return {
|
|
3192
|
+
code: 200,
|
|
3193
|
+
data: res
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3196
|
+
return res;
|
|
3191
3197
|
}
|
|
3192
3198
|
}
|
|
3193
3199
|
|
|
@@ -3216,8 +3222,8 @@ class BaseQuery {
|
|
|
3216
3222
|
}
|
|
3217
3223
|
}
|
|
3218
3224
|
|
|
3219
|
-
// ../../node_modules/.pnpm/@kevisual+query@0.0.
|
|
3220
|
-
var
|
|
3225
|
+
// ../../node_modules/.pnpm/@kevisual+query@0.0.33/node_modules/@kevisual/query/dist/query.js
|
|
3226
|
+
var setBaseResponse = (res) => {
|
|
3221
3227
|
res.success = res.code === 200;
|
|
3222
3228
|
res.showError = (fn) => {
|
|
3223
3229
|
if (!res.success && !res.noMsg) {
|
|
@@ -3407,7 +3413,7 @@ class MyCache extends CacheWorkspace {
|
|
|
3407
3413
|
}
|
|
3408
3414
|
}
|
|
3409
3415
|
|
|
3410
|
-
// ../../node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.
|
|
3416
|
+
// ../../node_modules/.pnpm/@kevisual+query-login@0.0.7_@kevisual+query@0.0.33/node_modules/@kevisual/query-login/dist/query-login-browser.js
|
|
3411
3417
|
var LoginCacheStore = class {
|
|
3412
3418
|
cache;
|
|
3413
3419
|
name;
|
|
@@ -3614,7 +3620,7 @@ var QueryLogin = class extends BaseQuery {
|
|
|
3614
3620
|
}
|
|
3615
3621
|
return this.post({ key: "refreshToken", data }, {
|
|
3616
3622
|
afterResponse: async (response, ctx) => {
|
|
3617
|
-
|
|
3623
|
+
setBaseResponse(response);
|
|
3618
3624
|
return response;
|
|
3619
3625
|
}
|
|
3620
3626
|
});
|
|
@@ -3639,7 +3645,7 @@ var QueryLogin = class extends BaseQuery {
|
|
|
3639
3645
|
body,
|
|
3640
3646
|
headers: { ...headers, Authorization: `Bearer ${accessToken}` }
|
|
3641
3647
|
});
|
|
3642
|
-
|
|
3648
|
+
setBaseResponse(res2);
|
|
3643
3649
|
return res2;
|
|
3644
3650
|
}
|
|
3645
3651
|
} else {
|
|
@@ -4160,175 +4166,1103 @@ class EventEmitter {
|
|
|
4160
4166
|
var eventEmitter = new EventEmitter;
|
|
4161
4167
|
var emit = (event) => eventEmitter.emit(event);
|
|
4162
4168
|
|
|
4163
|
-
//
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4169
|
+
// ../../node_modules/.pnpm/@kevisual+api@0.0.8/node_modules/@kevisual/api/query/query-login/login-cache.ts
|
|
4170
|
+
class LoginCacheStore2 {
|
|
4171
|
+
cache;
|
|
4172
|
+
name;
|
|
4173
|
+
cacheData;
|
|
4174
|
+
constructor(opts) {
|
|
4175
|
+
if (!opts.cache) {
|
|
4176
|
+
throw new Error("cache is required");
|
|
4177
|
+
}
|
|
4178
|
+
this.cache = opts.cache;
|
|
4179
|
+
this.cacheData = {
|
|
4180
|
+
loginUsers: [],
|
|
4181
|
+
user: undefined,
|
|
4182
|
+
id: undefined,
|
|
4183
|
+
accessToken: undefined,
|
|
4184
|
+
refreshToken: undefined
|
|
4185
|
+
};
|
|
4186
|
+
this.name = opts.name;
|
|
4172
4187
|
}
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
};
|
|
4178
|
-
var loginHandle = async (opts) => {
|
|
4179
|
-
const { loginMethod, data, el } = opts;
|
|
4180
|
-
switch (loginMethod) {
|
|
4181
|
-
case "password":
|
|
4182
|
-
await loginByPassword(data);
|
|
4183
|
-
break;
|
|
4184
|
-
case "phone":
|
|
4185
|
-
await loginByPhone(data);
|
|
4186
|
-
break;
|
|
4187
|
-
case "wechat-mp":
|
|
4188
|
-
await loginByWeChatMp(data);
|
|
4189
|
-
break;
|
|
4190
|
-
case "wechat":
|
|
4191
|
-
await loginByWeChat(data);
|
|
4192
|
-
break;
|
|
4193
|
-
default:
|
|
4194
|
-
console.warn("未知的登录方式:", loginMethod);
|
|
4188
|
+
async setValue(value) {
|
|
4189
|
+
await this.cache.set(this.name, value);
|
|
4190
|
+
this.cacheData = value;
|
|
4191
|
+
return value;
|
|
4195
4192
|
}
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4193
|
+
async delValue() {
|
|
4194
|
+
await this.cache.del();
|
|
4195
|
+
}
|
|
4196
|
+
getValue() {
|
|
4197
|
+
return this.cache.get(this.name);
|
|
4198
|
+
}
|
|
4199
|
+
async init() {
|
|
4200
|
+
const defaultData = {
|
|
4201
|
+
loginUsers: [],
|
|
4202
|
+
user: null,
|
|
4203
|
+
id: null,
|
|
4204
|
+
accessToken: null,
|
|
4205
|
+
refreshToken: null
|
|
4206
|
+
};
|
|
4207
|
+
if (this.cache.init) {
|
|
4208
|
+
try {
|
|
4209
|
+
const cacheData = await this.cache.init();
|
|
4210
|
+
this.cacheData = cacheData || defaultData;
|
|
4211
|
+
} catch (error) {
|
|
4212
|
+
console.log("cacheInit error", error);
|
|
4209
4213
|
}
|
|
4214
|
+
} else {
|
|
4215
|
+
this.cacheData = await this.getValue() || defaultData;
|
|
4210
4216
|
}
|
|
4211
4217
|
}
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4218
|
+
async setLoginUser(user) {
|
|
4219
|
+
const has = this.cacheData.loginUsers.find((u) => u.id === user.id);
|
|
4220
|
+
if (has) {
|
|
4221
|
+
this.cacheData.loginUsers = this.cacheData?.loginUsers?.filter((u) => u?.id && u.id !== user.id);
|
|
4222
|
+
}
|
|
4223
|
+
this.cacheData.loginUsers.push(user);
|
|
4224
|
+
this.cacheData.user = user.user;
|
|
4225
|
+
this.cacheData.id = user.id;
|
|
4226
|
+
this.cacheData.accessToken = user.accessToken;
|
|
4227
|
+
this.cacheData.refreshToken = user.refreshToken;
|
|
4228
|
+
await this.setValue(this.cacheData);
|
|
4215
4229
|
}
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
});
|
|
4220
|
-
if (res.code === 200) {
|
|
4221
|
-
console.log("登录成功");
|
|
4222
|
-
message.success("登录成功");
|
|
4223
|
-
redirectHome();
|
|
4224
|
-
} else {
|
|
4225
|
-
message.error(`登录失败: ${res.message}`);
|
|
4230
|
+
getCurrentUser() {
|
|
4231
|
+
const cacheData = this.cacheData;
|
|
4232
|
+
return Promise.resolve(cacheData.user);
|
|
4226
4233
|
}
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
console.log("使用手机号登录:", data);
|
|
4230
|
-
};
|
|
4231
|
-
var loginByWeChat = async (data) => {
|
|
4232
|
-
console.log("使用微信登录:", data);
|
|
4233
|
-
};
|
|
4234
|
-
var loginByWeChatMp = async (data) => {
|
|
4235
|
-
console.log("使用微信公众号登录:", data);
|
|
4236
|
-
};
|
|
4237
|
-
var clearCode = () => {
|
|
4238
|
-
const url = new URL(window.location.href);
|
|
4239
|
-
url.searchParams.delete("code");
|
|
4240
|
-
url.searchParams.delete("state");
|
|
4241
|
-
window.history.replaceState({}, document.title, url.toString());
|
|
4242
|
-
};
|
|
4243
|
-
var checkWechat = async () => {
|
|
4244
|
-
const url = new URL(window.location.href);
|
|
4245
|
-
const code = url.searchParams.get("code");
|
|
4246
|
-
const state = url.searchParams.get("state");
|
|
4247
|
-
if (state?.includes?.("-")) {
|
|
4248
|
-
return;
|
|
4234
|
+
getCurrentUserList() {
|
|
4235
|
+
return Promise.resolve(this.cacheData.loginUsers.filter((u) => u?.id));
|
|
4249
4236
|
}
|
|
4250
|
-
|
|
4251
|
-
|
|
4237
|
+
getRefreshToken() {
|
|
4238
|
+
const cacheData = this.cacheData;
|
|
4239
|
+
return Promise.resolve(cacheData.refreshToken || "");
|
|
4252
4240
|
}
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
redirectHome();
|
|
4257
|
-
} else {
|
|
4258
|
-
message.error(res.message || "登录失败");
|
|
4259
|
-
clearCode();
|
|
4241
|
+
getAccessToken() {
|
|
4242
|
+
const cacheData = this.cacheData;
|
|
4243
|
+
return Promise.resolve(cacheData.accessToken || "");
|
|
4260
4244
|
}
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
console.log("检查微信公众号登录流程:", mpLogin, state, originState);
|
|
4267
|
-
if (mpLogin === "1") {
|
|
4268
|
-
checkMpWechatInWx();
|
|
4269
|
-
} else if (mpLogin === "2") {
|
|
4270
|
-
const code = url.searchParams.get("code");
|
|
4271
|
-
const res2 = await query.post({
|
|
4272
|
-
path: "wx",
|
|
4273
|
-
key: "mplogin",
|
|
4274
|
-
state,
|
|
4275
|
-
code
|
|
4276
|
-
});
|
|
4277
|
-
if (res2.code === 200) {
|
|
4278
|
-
message.success("登录成功");
|
|
4279
|
-
} else {
|
|
4280
|
-
message.error(res2.message || "登录失败");
|
|
4245
|
+
async clearCurrentUser() {
|
|
4246
|
+
const user = await this.getCurrentUser();
|
|
4247
|
+
const has = this.cacheData.loginUsers.find((u) => u.id === user.id);
|
|
4248
|
+
if (has) {
|
|
4249
|
+
this.cacheData.loginUsers = this.cacheData?.loginUsers?.filter((u) => u?.id && u.id !== user.id);
|
|
4281
4250
|
}
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
return /micromessenger/i.test(ua);
|
|
4288
|
-
};
|
|
4289
|
-
var closePage = (time = 2000) => {
|
|
4290
|
-
if (!isWechat()) {
|
|
4291
|
-
setTimeout(() => {
|
|
4292
|
-
window.close();
|
|
4293
|
-
}, time);
|
|
4294
|
-
return;
|
|
4295
|
-
}
|
|
4296
|
-
if (window.WeixinJSBridge) {
|
|
4297
|
-
setTimeout(() => {
|
|
4298
|
-
window.WeixinJSBridge.call("closeWindow");
|
|
4299
|
-
}, time);
|
|
4300
|
-
} else {
|
|
4301
|
-
setTimeout(() => {
|
|
4302
|
-
window.close();
|
|
4303
|
-
}, time);
|
|
4251
|
+
this.cacheData.user = undefined;
|
|
4252
|
+
this.cacheData.id = undefined;
|
|
4253
|
+
this.cacheData.accessToken = undefined;
|
|
4254
|
+
this.cacheData.refreshToken = undefined;
|
|
4255
|
+
await this.setValue(this.cacheData);
|
|
4304
4256
|
}
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
const redirectURL = new URL(url.pathname, url.origin);
|
|
4313
|
-
state = "2-" + state;
|
|
4314
|
-
const redirect_uri = encodeURIComponent(redirectURL.toString());
|
|
4315
|
-
document.body.innerHTML = `<p>正在准备跳转到微信公众号授权页面...</p>`;
|
|
4316
|
-
const scope = `snsapi_userinfo`;
|
|
4317
|
-
if (!state) {
|
|
4318
|
-
alert("Invalid state. Please try again later.");
|
|
4319
|
-
closePage();
|
|
4320
|
-
return;
|
|
4257
|
+
async clearAll() {
|
|
4258
|
+
this.cacheData.loginUsers = [];
|
|
4259
|
+
this.cacheData.user = undefined;
|
|
4260
|
+
this.cacheData.id = undefined;
|
|
4261
|
+
this.cacheData.accessToken = undefined;
|
|
4262
|
+
this.cacheData.refreshToken = undefined;
|
|
4263
|
+
await this.setValue(this.cacheData);
|
|
4321
4264
|
}
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4265
|
+
}
|
|
4266
|
+
|
|
4267
|
+
// ../../node_modules/.pnpm/@kevisual+load@0.0.6/node_modules/@kevisual/load/dist/load.js
|
|
4268
|
+
function getDefaultExportFromCjs(x) {
|
|
4269
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4270
|
+
}
|
|
4271
|
+
var eventemitter3 = { exports: {} };
|
|
4272
|
+
var hasRequiredEventemitter3;
|
|
4273
|
+
function requireEventemitter3() {
|
|
4274
|
+
if (hasRequiredEventemitter3)
|
|
4275
|
+
return eventemitter3.exports;
|
|
4276
|
+
hasRequiredEventemitter3 = 1;
|
|
4277
|
+
(function(module) {
|
|
4278
|
+
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
4279
|
+
function Events() {}
|
|
4280
|
+
if (Object.create) {
|
|
4281
|
+
Events.prototype = Object.create(null);
|
|
4282
|
+
if (!new Events().__proto__)
|
|
4283
|
+
prefix = false;
|
|
4284
|
+
}
|
|
4285
|
+
function EE(fn, context, once) {
|
|
4286
|
+
this.fn = fn;
|
|
4287
|
+
this.context = context;
|
|
4288
|
+
this.once = once || false;
|
|
4289
|
+
}
|
|
4290
|
+
function addListener(emitter, event, fn, context, once) {
|
|
4291
|
+
if (typeof fn !== "function") {
|
|
4292
|
+
throw new TypeError("The listener must be a function");
|
|
4293
|
+
}
|
|
4294
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
4295
|
+
if (!emitter._events[evt])
|
|
4296
|
+
emitter._events[evt] = listener, emitter._eventsCount++;
|
|
4297
|
+
else if (!emitter._events[evt].fn)
|
|
4298
|
+
emitter._events[evt].push(listener);
|
|
4299
|
+
else
|
|
4300
|
+
emitter._events[evt] = [emitter._events[evt], listener];
|
|
4301
|
+
return emitter;
|
|
4302
|
+
}
|
|
4303
|
+
function clearEvent(emitter, evt) {
|
|
4304
|
+
if (--emitter._eventsCount === 0)
|
|
4305
|
+
emitter._events = new Events;
|
|
4306
|
+
else
|
|
4307
|
+
delete emitter._events[evt];
|
|
4308
|
+
}
|
|
4309
|
+
function EventEmitter2() {
|
|
4310
|
+
this._events = new Events;
|
|
4311
|
+
this._eventsCount = 0;
|
|
4312
|
+
}
|
|
4313
|
+
EventEmitter2.prototype.eventNames = function eventNames() {
|
|
4314
|
+
var names = [], events, name;
|
|
4315
|
+
if (this._eventsCount === 0)
|
|
4316
|
+
return names;
|
|
4317
|
+
for (name in events = this._events) {
|
|
4318
|
+
if (has.call(events, name))
|
|
4319
|
+
names.push(prefix ? name.slice(1) : name);
|
|
4320
|
+
}
|
|
4321
|
+
if (Object.getOwnPropertySymbols) {
|
|
4322
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
4323
|
+
}
|
|
4324
|
+
return names;
|
|
4325
|
+
};
|
|
4326
|
+
EventEmitter2.prototype.listeners = function listeners(event) {
|
|
4327
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
4328
|
+
if (!handlers)
|
|
4329
|
+
return [];
|
|
4330
|
+
if (handlers.fn)
|
|
4331
|
+
return [handlers.fn];
|
|
4332
|
+
for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) {
|
|
4333
|
+
ee[i] = handlers[i].fn;
|
|
4334
|
+
}
|
|
4335
|
+
return ee;
|
|
4336
|
+
};
|
|
4337
|
+
EventEmitter2.prototype.listenerCount = function listenerCount(event) {
|
|
4338
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
4339
|
+
if (!listeners)
|
|
4340
|
+
return 0;
|
|
4341
|
+
if (listeners.fn)
|
|
4342
|
+
return 1;
|
|
4343
|
+
return listeners.length;
|
|
4344
|
+
};
|
|
4345
|
+
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
4346
|
+
var evt = prefix ? prefix + event : event;
|
|
4347
|
+
if (!this._events[evt])
|
|
4348
|
+
return false;
|
|
4349
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
4350
|
+
if (listeners.fn) {
|
|
4351
|
+
if (listeners.once)
|
|
4352
|
+
this.removeListener(event, listeners.fn, undefined, true);
|
|
4353
|
+
switch (len) {
|
|
4354
|
+
case 1:
|
|
4355
|
+
return listeners.fn.call(listeners.context), true;
|
|
4356
|
+
case 2:
|
|
4357
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
4358
|
+
case 3:
|
|
4359
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
4360
|
+
case 4:
|
|
4361
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
4362
|
+
case 5:
|
|
4363
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
4364
|
+
case 6:
|
|
4365
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
4366
|
+
}
|
|
4367
|
+
for (i = 1, args = new Array(len - 1);i < len; i++) {
|
|
4368
|
+
args[i - 1] = arguments[i];
|
|
4369
|
+
}
|
|
4370
|
+
listeners.fn.apply(listeners.context, args);
|
|
4371
|
+
} else {
|
|
4372
|
+
var length = listeners.length, j;
|
|
4373
|
+
for (i = 0;i < length; i++) {
|
|
4374
|
+
if (listeners[i].once)
|
|
4375
|
+
this.removeListener(event, listeners[i].fn, undefined, true);
|
|
4376
|
+
switch (len) {
|
|
4377
|
+
case 1:
|
|
4378
|
+
listeners[i].fn.call(listeners[i].context);
|
|
4379
|
+
break;
|
|
4380
|
+
case 2:
|
|
4381
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
4382
|
+
break;
|
|
4383
|
+
case 3:
|
|
4384
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
4385
|
+
break;
|
|
4386
|
+
case 4:
|
|
4387
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
4388
|
+
break;
|
|
4389
|
+
default:
|
|
4390
|
+
if (!args)
|
|
4391
|
+
for (j = 1, args = new Array(len - 1);j < len; j++) {
|
|
4392
|
+
args[j - 1] = arguments[j];
|
|
4393
|
+
}
|
|
4394
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
4395
|
+
}
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
return true;
|
|
4399
|
+
};
|
|
4400
|
+
EventEmitter2.prototype.on = function on(event, fn, context) {
|
|
4401
|
+
return addListener(this, event, fn, context, false);
|
|
4402
|
+
};
|
|
4403
|
+
EventEmitter2.prototype.once = function once(event, fn, context) {
|
|
4404
|
+
return addListener(this, event, fn, context, true);
|
|
4405
|
+
};
|
|
4406
|
+
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
4407
|
+
var evt = prefix ? prefix + event : event;
|
|
4408
|
+
if (!this._events[evt])
|
|
4409
|
+
return this;
|
|
4410
|
+
if (!fn) {
|
|
4411
|
+
clearEvent(this, evt);
|
|
4412
|
+
return this;
|
|
4413
|
+
}
|
|
4414
|
+
var listeners = this._events[evt];
|
|
4415
|
+
if (listeners.fn) {
|
|
4416
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
4417
|
+
clearEvent(this, evt);
|
|
4418
|
+
}
|
|
4419
|
+
} else {
|
|
4420
|
+
for (var i = 0, events = [], length = listeners.length;i < length; i++) {
|
|
4421
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
4422
|
+
events.push(listeners[i]);
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
if (events.length)
|
|
4426
|
+
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
4427
|
+
else
|
|
4428
|
+
clearEvent(this, evt);
|
|
4429
|
+
}
|
|
4430
|
+
return this;
|
|
4431
|
+
};
|
|
4432
|
+
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
4433
|
+
var evt;
|
|
4434
|
+
if (event) {
|
|
4435
|
+
evt = prefix ? prefix + event : event;
|
|
4436
|
+
if (this._events[evt])
|
|
4437
|
+
clearEvent(this, evt);
|
|
4438
|
+
} else {
|
|
4439
|
+
this._events = new Events;
|
|
4440
|
+
this._eventsCount = 0;
|
|
4441
|
+
}
|
|
4442
|
+
return this;
|
|
4443
|
+
};
|
|
4444
|
+
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
|
|
4445
|
+
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
|
|
4446
|
+
EventEmitter2.prefixed = prefix;
|
|
4447
|
+
EventEmitter2.EventEmitter = EventEmitter2;
|
|
4448
|
+
{
|
|
4449
|
+
module.exports = EventEmitter2;
|
|
4450
|
+
}
|
|
4451
|
+
})(eventemitter3);
|
|
4452
|
+
return eventemitter3.exports;
|
|
4453
|
+
}
|
|
4454
|
+
var eventemitter3Exports = requireEventemitter3();
|
|
4455
|
+
var EventEmitter2 = /* @__PURE__ */ getDefaultExportFromCjs(eventemitter3Exports);
|
|
4456
|
+
var reRunFn = (promiseOpts) => {
|
|
4457
|
+
const timeout = promiseOpts.timeout || 5 * 60 * 1000;
|
|
4458
|
+
const interval = promiseOpts.interval || 1000;
|
|
4459
|
+
const checkSuccess = promiseOpts?.checkSuccess || (() => true);
|
|
4460
|
+
const signal = promiseOpts.signal;
|
|
4461
|
+
return new Promise(async (resolve, reject) => {
|
|
4462
|
+
let intervalId;
|
|
4463
|
+
let timeoutId = setTimeout(() => {
|
|
4464
|
+
clearTimeout(intervalId);
|
|
4465
|
+
resolve({
|
|
4466
|
+
code: 500,
|
|
4467
|
+
message: "timeout"
|
|
4468
|
+
});
|
|
4469
|
+
}, timeout);
|
|
4470
|
+
const fn = promiseOpts.fn || (() => true);
|
|
4471
|
+
const runFn = async () => {
|
|
4472
|
+
if (signal?.aborted) {
|
|
4473
|
+
clearInterval(intervalId);
|
|
4474
|
+
clearTimeout(timeoutId);
|
|
4475
|
+
return resolve({
|
|
4476
|
+
code: 499,
|
|
4477
|
+
message: "operation cancelled"
|
|
4478
|
+
});
|
|
4479
|
+
}
|
|
4480
|
+
const res = await fn();
|
|
4481
|
+
if (!!checkSuccess(res)) {
|
|
4482
|
+
clearInterval(intervalId);
|
|
4483
|
+
clearTimeout(timeoutId);
|
|
4484
|
+
resolve({
|
|
4485
|
+
code: 200,
|
|
4486
|
+
data: res
|
|
4487
|
+
});
|
|
4488
|
+
} else {
|
|
4489
|
+
setTimeout(() => {
|
|
4490
|
+
runFn();
|
|
4491
|
+
}, interval);
|
|
4492
|
+
}
|
|
4493
|
+
};
|
|
4494
|
+
if (signal) {
|
|
4495
|
+
signal.addEventListener("abort", () => {
|
|
4496
|
+
clearInterval(intervalId);
|
|
4497
|
+
clearTimeout(timeoutId);
|
|
4498
|
+
resolve({
|
|
4499
|
+
code: 499,
|
|
4500
|
+
message: "operation cancelled"
|
|
4501
|
+
});
|
|
4502
|
+
});
|
|
4503
|
+
}
|
|
4504
|
+
runFn();
|
|
4505
|
+
});
|
|
4506
|
+
};
|
|
4507
|
+
|
|
4508
|
+
class BaseLoad {
|
|
4509
|
+
modules = new Map;
|
|
4510
|
+
event;
|
|
4511
|
+
loading;
|
|
4512
|
+
static reRunFn = reRunFn;
|
|
4513
|
+
timeout = 5 * 60 * 1000;
|
|
4514
|
+
constructor() {
|
|
4515
|
+
this.event = new EventEmitter2;
|
|
4516
|
+
this.loading = false;
|
|
4517
|
+
}
|
|
4518
|
+
listenKey(key, listenOpts) {
|
|
4519
|
+
const timeout = listenOpts?.timeout ?? this.timeout;
|
|
4520
|
+
return new Promise((resolve) => {
|
|
4521
|
+
const timeoutId = setTimeout(() => {
|
|
4522
|
+
this.event.removeListener(key, onEvent);
|
|
4523
|
+
resolve({
|
|
4524
|
+
code: 500,
|
|
4525
|
+
message: "timeout"
|
|
4526
|
+
});
|
|
4527
|
+
}, timeout);
|
|
4528
|
+
const onEvent = (error) => {
|
|
4529
|
+
clearTimeout(timeoutId);
|
|
4530
|
+
if (error) {
|
|
4531
|
+
return resolve({
|
|
4532
|
+
code: 500,
|
|
4533
|
+
message: error
|
|
4534
|
+
});
|
|
4535
|
+
}
|
|
4536
|
+
const data = this.modules.get(key);
|
|
4537
|
+
if (data?.loadSuccessClear) {
|
|
4538
|
+
this.remove(key);
|
|
4539
|
+
}
|
|
4540
|
+
resolve({
|
|
4541
|
+
code: 200,
|
|
4542
|
+
data: data?.modules
|
|
4543
|
+
});
|
|
4544
|
+
};
|
|
4545
|
+
this.event.once(key, onEvent);
|
|
4546
|
+
});
|
|
4547
|
+
}
|
|
4548
|
+
async hasLoaded(key, hasLoadOpts) {
|
|
4549
|
+
if (!key) {
|
|
4550
|
+
return {
|
|
4551
|
+
code: 404,
|
|
4552
|
+
message: "key is required"
|
|
4553
|
+
};
|
|
4554
|
+
}
|
|
4555
|
+
const has = this.modules.has(key);
|
|
4556
|
+
if (!has) {
|
|
4557
|
+
const isExist = hasLoadOpts?.isExist ?? true;
|
|
4558
|
+
const timeout = hasLoadOpts?.timeout ?? this.timeout;
|
|
4559
|
+
if (isExist) {
|
|
4560
|
+
return await this.listenKey(key, { timeout });
|
|
4561
|
+
}
|
|
4562
|
+
return {
|
|
4563
|
+
code: 404
|
|
4564
|
+
};
|
|
4565
|
+
}
|
|
4566
|
+
const data = this.modules.get(key);
|
|
4567
|
+
if (data?.status === "loaded") {
|
|
4568
|
+
return {
|
|
4569
|
+
code: 200,
|
|
4570
|
+
data: data.modules
|
|
4571
|
+
};
|
|
4572
|
+
}
|
|
4573
|
+
if (data?.status === "loading") {
|
|
4574
|
+
return await this.listenKey(key, { timeout: hasLoadOpts?.timeout ?? this.timeout });
|
|
4575
|
+
}
|
|
4576
|
+
if (data?.status === "error") {
|
|
4577
|
+
return {
|
|
4578
|
+
code: 500,
|
|
4579
|
+
message: "load error"
|
|
4580
|
+
};
|
|
4581
|
+
}
|
|
4582
|
+
if (data?.status === "cancel") {
|
|
4583
|
+
return {
|
|
4584
|
+
code: 499,
|
|
4585
|
+
message: "operation cancelled"
|
|
4586
|
+
};
|
|
4587
|
+
}
|
|
4588
|
+
return {
|
|
4589
|
+
code: 404
|
|
4590
|
+
};
|
|
4591
|
+
}
|
|
4592
|
+
async loadFn(loadContent, opts) {
|
|
4593
|
+
const key = opts.key;
|
|
4594
|
+
if (!key) {
|
|
4595
|
+
return {
|
|
4596
|
+
code: 404,
|
|
4597
|
+
message: "key is required"
|
|
4598
|
+
};
|
|
4599
|
+
}
|
|
4600
|
+
const newModule = {
|
|
4601
|
+
key: opts.key,
|
|
4602
|
+
status: "loading",
|
|
4603
|
+
loading: true,
|
|
4604
|
+
loadSuccessClear: opts.loadSuccessClear ?? true
|
|
4605
|
+
};
|
|
4606
|
+
let errorMessage = "";
|
|
4607
|
+
try {
|
|
4608
|
+
const isReRun = opts.isReRun ?? false;
|
|
4609
|
+
let res;
|
|
4610
|
+
if (!isReRun) {
|
|
4611
|
+
this.modules.set(key, newModule);
|
|
4612
|
+
res = await loadContent();
|
|
4613
|
+
} else {
|
|
4614
|
+
newModule.controller = new AbortController;
|
|
4615
|
+
const signal = newModule.controller.signal;
|
|
4616
|
+
this.modules.set(key, newModule);
|
|
4617
|
+
const data = await reRunFn({
|
|
4618
|
+
timeout: opts.timeout,
|
|
4619
|
+
interval: opts.interval,
|
|
4620
|
+
checkSuccess: opts.checkSuccess,
|
|
4621
|
+
fn: loadContent,
|
|
4622
|
+
signal
|
|
4623
|
+
});
|
|
4624
|
+
newModule.controller = null;
|
|
4625
|
+
if (data.code === 499) {
|
|
4626
|
+
newModule.status = "cancel";
|
|
4627
|
+
return {
|
|
4628
|
+
code: 499,
|
|
4629
|
+
message: "operation cancelled"
|
|
4630
|
+
};
|
|
4631
|
+
}
|
|
4632
|
+
if (data.code !== 200) {
|
|
4633
|
+
throw new Error(data.message);
|
|
4634
|
+
}
|
|
4635
|
+
res = data.data;
|
|
4636
|
+
}
|
|
4637
|
+
newModule.modules = res;
|
|
4638
|
+
newModule.status = "loaded";
|
|
4639
|
+
return {
|
|
4640
|
+
code: 200,
|
|
4641
|
+
data: res
|
|
4642
|
+
};
|
|
4643
|
+
} catch (error) {
|
|
4644
|
+
errorMessage = error.message;
|
|
4645
|
+
newModule.status = "error";
|
|
4646
|
+
return {
|
|
4647
|
+
code: 500,
|
|
4648
|
+
message: error
|
|
4649
|
+
};
|
|
4650
|
+
} finally {
|
|
4651
|
+
newModule.loading = false;
|
|
4652
|
+
this.modules.set(opts.key, newModule);
|
|
4653
|
+
if (!errorMessage) {
|
|
4654
|
+
this.event.emit(opts.key);
|
|
4655
|
+
} else {
|
|
4656
|
+
this.event.emit(opts.key, errorMessage);
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
async load(loadContent, opts) {
|
|
4661
|
+
this.loading = true;
|
|
4662
|
+
const key = opts.key;
|
|
4663
|
+
if (!key) {
|
|
4664
|
+
return {
|
|
4665
|
+
code: 404,
|
|
4666
|
+
message: "key is required"
|
|
4667
|
+
};
|
|
4668
|
+
}
|
|
4669
|
+
if (opts?.force) {
|
|
4670
|
+
this.remove(key);
|
|
4671
|
+
}
|
|
4672
|
+
const has = this.modules.has(key);
|
|
4673
|
+
if (has) {
|
|
4674
|
+
return await this.hasLoaded(key);
|
|
4675
|
+
}
|
|
4676
|
+
if (typeof loadContent === "function") {
|
|
4677
|
+
return this.loadFn(loadContent, opts);
|
|
4678
|
+
}
|
|
4679
|
+
console.error("loadContent is not a function and not has loaded");
|
|
4680
|
+
}
|
|
4681
|
+
remove(key) {
|
|
4682
|
+
const has = this.modules.has(key);
|
|
4683
|
+
if (has) {
|
|
4684
|
+
this.checkRemoveController(key);
|
|
4685
|
+
this.modules.delete(key);
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
emitLoaded(key) {
|
|
4689
|
+
this.checkRemoveController(key);
|
|
4690
|
+
this.event.emit(key);
|
|
4691
|
+
}
|
|
4692
|
+
setModule(key, data, loadData) {
|
|
4693
|
+
const newModule = {
|
|
4694
|
+
key,
|
|
4695
|
+
status: "loaded",
|
|
4696
|
+
loading: false,
|
|
4697
|
+
modules: data || {},
|
|
4698
|
+
...loadData
|
|
4699
|
+
};
|
|
4700
|
+
this.modules.set(key, newModule);
|
|
4701
|
+
this.emitLoaded(key);
|
|
4702
|
+
return newModule;
|
|
4703
|
+
}
|
|
4704
|
+
cancel(key) {
|
|
4705
|
+
this.checkRemoveController(key);
|
|
4706
|
+
}
|
|
4707
|
+
checkRemoveController(key) {
|
|
4708
|
+
const data = this.modules.get(key);
|
|
4709
|
+
if (data?.controller) {
|
|
4710
|
+
data.controller?.abort?.();
|
|
4711
|
+
delete data.controller;
|
|
4712
|
+
this.modules.set(key, data);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
// ../../node_modules/.pnpm/@kevisual+api@0.0.8/node_modules/@kevisual/api/query/query-login/query-login.ts
|
|
4718
|
+
class QueryLogin2 extends BaseQuery {
|
|
4719
|
+
cacheStore;
|
|
4720
|
+
isBrowser;
|
|
4721
|
+
load;
|
|
4722
|
+
storage;
|
|
4723
|
+
onLoad;
|
|
4724
|
+
constructor(opts) {
|
|
4725
|
+
super({
|
|
4726
|
+
query: opts?.query || new Query
|
|
4727
|
+
});
|
|
4728
|
+
this.cacheStore = new LoginCacheStore2({ name: "login", cache: opts?.cache });
|
|
4729
|
+
this.isBrowser = opts?.isBrowser ?? true;
|
|
4730
|
+
this.init();
|
|
4731
|
+
this.onLoad = opts?.onLoad;
|
|
4732
|
+
this.storage = opts?.storage || localStorage;
|
|
4733
|
+
}
|
|
4734
|
+
setQuery(query2) {
|
|
4735
|
+
this.query = query2;
|
|
4736
|
+
}
|
|
4737
|
+
async init() {
|
|
4738
|
+
await this.cacheStore.init();
|
|
4739
|
+
this.load = true;
|
|
4740
|
+
this.onLoad?.();
|
|
4741
|
+
}
|
|
4742
|
+
async post(data, opts) {
|
|
4743
|
+
try {
|
|
4744
|
+
return this.query.post({ path: "user", ...data }, opts);
|
|
4745
|
+
} catch (error) {
|
|
4746
|
+
console.log("error", error);
|
|
4747
|
+
return {
|
|
4748
|
+
code: 400
|
|
4749
|
+
};
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
async login(data) {
|
|
4753
|
+
const res = await this.post({ key: "login", ...data });
|
|
4754
|
+
if (res.code === 200) {
|
|
4755
|
+
const { accessToken, refreshToken } = res?.data || {};
|
|
4756
|
+
this.storage.setItem("token", accessToken || "");
|
|
4757
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
4758
|
+
}
|
|
4759
|
+
return res;
|
|
4760
|
+
}
|
|
4761
|
+
async loginByCode(data) {
|
|
4762
|
+
const res = await this.post({ path: "sms", key: "login", data });
|
|
4763
|
+
if (res.code === 200) {
|
|
4764
|
+
const { accessToken, refreshToken } = res?.data || {};
|
|
4765
|
+
this.storage.setItem("token", accessToken || "");
|
|
4766
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
4767
|
+
}
|
|
4768
|
+
return res;
|
|
4769
|
+
}
|
|
4770
|
+
async setLoginToken(token) {
|
|
4771
|
+
const { accessToken, refreshToken } = token;
|
|
4772
|
+
this.storage.setItem("token", accessToken || "");
|
|
4773
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
4774
|
+
}
|
|
4775
|
+
async loginByWechat(data) {
|
|
4776
|
+
const res = await this.post({ path: "wx", key: "open-login", code: data.code });
|
|
4777
|
+
if (res.code === 200) {
|
|
4778
|
+
const { accessToken, refreshToken } = res?.data || {};
|
|
4779
|
+
this.storage.setItem("token", accessToken || "");
|
|
4780
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
4781
|
+
}
|
|
4782
|
+
return res;
|
|
4783
|
+
}
|
|
4784
|
+
async checkWechat({ onSuccess, onError }) {
|
|
4785
|
+
const url = new URL(window.location.href);
|
|
4786
|
+
const code = url.searchParams.get("code");
|
|
4787
|
+
const state = url.searchParams.get("state");
|
|
4788
|
+
if (code && state) {
|
|
4789
|
+
const res = await this.loginByWechat({ code });
|
|
4790
|
+
if (res.code === 200) {
|
|
4791
|
+
onSuccess?.(res.data);
|
|
4792
|
+
} else {
|
|
4793
|
+
onError?.(res);
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
async beforeSetLoginUser({ accessToken, refreshToken, check401 }) {
|
|
4798
|
+
if (accessToken && refreshToken) {
|
|
4799
|
+
const resUser = await this.getMe(accessToken, check401);
|
|
4800
|
+
if (resUser.code === 200) {
|
|
4801
|
+
const user = resUser.data;
|
|
4802
|
+
if (user) {
|
|
4803
|
+
this.cacheStore.setLoginUser({
|
|
4804
|
+
user,
|
|
4805
|
+
id: user.id,
|
|
4806
|
+
accessToken,
|
|
4807
|
+
refreshToken
|
|
4808
|
+
});
|
|
4809
|
+
} else {
|
|
4810
|
+
console.error("登录失败");
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
async queryRefreshToken(refreshToken) {
|
|
4816
|
+
const _refreshToken = refreshToken || this.cacheStore.getRefreshToken();
|
|
4817
|
+
let data = { refreshToken: _refreshToken };
|
|
4818
|
+
if (!_refreshToken) {
|
|
4819
|
+
await this.cacheStore.clearCurrentUser();
|
|
4820
|
+
return {
|
|
4821
|
+
code: 401,
|
|
4822
|
+
message: "请先登录",
|
|
4823
|
+
data: {}
|
|
4824
|
+
};
|
|
4825
|
+
}
|
|
4826
|
+
return this.post({ key: "refreshToken", data }, {
|
|
4827
|
+
afterResponse: async (response, ctx) => {
|
|
4828
|
+
setBaseResponse(response);
|
|
4829
|
+
return response;
|
|
4830
|
+
}
|
|
4831
|
+
});
|
|
4832
|
+
}
|
|
4833
|
+
async afterCheck401ToRefreshToken(response, ctx, refetch) {
|
|
4834
|
+
const that = this;
|
|
4835
|
+
if (response?.code === 401) {
|
|
4836
|
+
const hasRefreshToken = await that.cacheStore.getRefreshToken();
|
|
4837
|
+
if (hasRefreshToken) {
|
|
4838
|
+
const res = await that.queryRefreshToken(hasRefreshToken);
|
|
4839
|
+
if (res.code === 200) {
|
|
4840
|
+
const { accessToken, refreshToken } = res?.data || {};
|
|
4841
|
+
that.storage.setItem("token", accessToken || "");
|
|
4842
|
+
await that.beforeSetLoginUser({ accessToken, refreshToken, check401: false });
|
|
4843
|
+
if (refetch && ctx && ctx.req && ctx.req.url && ctx.fetch) {
|
|
4844
|
+
await new Promise((resolve) => setTimeout(resolve, 1500));
|
|
4845
|
+
const url = ctx.req?.url;
|
|
4846
|
+
const body = ctx.req?.body;
|
|
4847
|
+
const headers = ctx.req?.headers;
|
|
4848
|
+
const res2 = await ctx.fetch(url, {
|
|
4849
|
+
method: "POST",
|
|
4850
|
+
body,
|
|
4851
|
+
headers: { ...headers, Authorization: `Bearer ${accessToken}` }
|
|
4852
|
+
});
|
|
4853
|
+
setBaseResponse(res2);
|
|
4854
|
+
return res2;
|
|
4855
|
+
}
|
|
4856
|
+
} else {
|
|
4857
|
+
that.storage.removeItem("token");
|
|
4858
|
+
await that.cacheStore.clearCurrentUser();
|
|
4859
|
+
}
|
|
4860
|
+
return res;
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
return response;
|
|
4864
|
+
}
|
|
4865
|
+
async run401Action(response, ctx, opts) {
|
|
4866
|
+
const that = this;
|
|
4867
|
+
const refetch = opts?.refetch ?? false;
|
|
4868
|
+
if (response?.code === 401) {
|
|
4869
|
+
if (that.query.stop === true) {
|
|
4870
|
+
return { code: 500, success: false, message: "refresh token loading..." };
|
|
4871
|
+
}
|
|
4872
|
+
that.query.stop = true;
|
|
4873
|
+
const res = await that.afterCheck401ToRefreshToken(response, ctx, refetch);
|
|
4874
|
+
that.query.stop = false;
|
|
4875
|
+
opts?.afterCheck?.(res);
|
|
4876
|
+
if (res.code === 401) {
|
|
4877
|
+
opts?.afterAlso401?.(res);
|
|
4878
|
+
}
|
|
4879
|
+
return res;
|
|
4880
|
+
} else {
|
|
4881
|
+
return response;
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
async getMe(token, check401 = true) {
|
|
4885
|
+
const _token = token || this.storage.getItem("token");
|
|
4886
|
+
const that = this;
|
|
4887
|
+
return that.post({ key: "me" }, {
|
|
4888
|
+
beforeRequest: async (config) => {
|
|
4889
|
+
if (config.headers) {
|
|
4890
|
+
config.headers["Authorization"] = `Bearer ${_token}`;
|
|
4891
|
+
}
|
|
4892
|
+
if (!_token) {
|
|
4893
|
+
return false;
|
|
4894
|
+
}
|
|
4895
|
+
return config;
|
|
4896
|
+
},
|
|
4897
|
+
afterResponse: async (response, ctx) => {
|
|
4898
|
+
if (response?.code === 401 && check401 && !token) {
|
|
4899
|
+
return await that.afterCheck401ToRefreshToken(response, ctx);
|
|
4900
|
+
}
|
|
4901
|
+
return response;
|
|
4902
|
+
}
|
|
4903
|
+
});
|
|
4904
|
+
}
|
|
4905
|
+
async checkLocalUser() {
|
|
4906
|
+
const user = await this.cacheStore.getCurrentUser();
|
|
4907
|
+
if (user) {
|
|
4908
|
+
return user;
|
|
4909
|
+
}
|
|
4910
|
+
return null;
|
|
4911
|
+
}
|
|
4912
|
+
async checkLocalToken() {
|
|
4913
|
+
const token = this.storage.getItem("token");
|
|
4914
|
+
return !!token;
|
|
4915
|
+
}
|
|
4916
|
+
async getToken() {
|
|
4917
|
+
const token = this.storage.getItem("token");
|
|
4918
|
+
return token || "";
|
|
4919
|
+
}
|
|
4920
|
+
async beforeRequest(opts = {}) {
|
|
4921
|
+
const token = this.storage.getItem("token");
|
|
4922
|
+
if (token) {
|
|
4923
|
+
opts.headers = { ...opts.headers, Authorization: `Bearer ${token}` };
|
|
4924
|
+
}
|
|
4925
|
+
return opts;
|
|
4926
|
+
}
|
|
4927
|
+
async postSwitchUser(username) {
|
|
4928
|
+
return this.post({ key: "switchCheck", data: { username } });
|
|
4929
|
+
}
|
|
4930
|
+
async switchUser(username) {
|
|
4931
|
+
const localUserList = await this.cacheStore.getCurrentUserList();
|
|
4932
|
+
const user = localUserList.find((userItem) => userItem.user.username === username);
|
|
4933
|
+
if (user) {
|
|
4934
|
+
this.storage.setItem("token", user.accessToken || "");
|
|
4935
|
+
await this.beforeSetLoginUser({ accessToken: user.accessToken, refreshToken: user.refreshToken });
|
|
4936
|
+
return {
|
|
4937
|
+
code: 200,
|
|
4938
|
+
data: {
|
|
4939
|
+
accessToken: user.accessToken,
|
|
4940
|
+
refreshToken: user.refreshToken
|
|
4941
|
+
},
|
|
4942
|
+
success: true,
|
|
4943
|
+
message: "切换用户成功"
|
|
4944
|
+
};
|
|
4945
|
+
}
|
|
4946
|
+
const res = await this.postSwitchUser(username);
|
|
4947
|
+
if (res.code === 200) {
|
|
4948
|
+
const { accessToken, refreshToken } = res?.data || {};
|
|
4949
|
+
this.storage.setItem("token", accessToken || "");
|
|
4950
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken });
|
|
4951
|
+
}
|
|
4952
|
+
return res;
|
|
4953
|
+
}
|
|
4954
|
+
async logout() {
|
|
4955
|
+
this.storage.removeItem("token");
|
|
4956
|
+
const users = await this.cacheStore.getCurrentUserList();
|
|
4957
|
+
const tokens = users.map((user) => {
|
|
4958
|
+
return user?.accessToken;
|
|
4959
|
+
}).filter(Boolean);
|
|
4960
|
+
this.cacheStore.delValue();
|
|
4961
|
+
return this.post({ key: "logout", data: { tokens } });
|
|
4962
|
+
}
|
|
4963
|
+
async hasUser(username) {
|
|
4964
|
+
const that = this;
|
|
4965
|
+
return this.post({
|
|
4966
|
+
path: "org",
|
|
4967
|
+
key: "hasUser",
|
|
4968
|
+
data: {
|
|
4969
|
+
username
|
|
4970
|
+
}
|
|
4971
|
+
}, {
|
|
4972
|
+
afterResponse: async (response, ctx) => {
|
|
4973
|
+
if (response?.code === 401) {
|
|
4974
|
+
const res = await that.afterCheck401ToRefreshToken(response, ctx, true);
|
|
4975
|
+
return res;
|
|
4976
|
+
}
|
|
4977
|
+
return response;
|
|
4978
|
+
}
|
|
4979
|
+
});
|
|
4980
|
+
}
|
|
4981
|
+
async checkLoginStatus(token) {
|
|
4982
|
+
const res = await this.post({
|
|
4983
|
+
path: "user",
|
|
4984
|
+
key: "checkLoginStatus",
|
|
4985
|
+
loginToken: token
|
|
4986
|
+
});
|
|
4987
|
+
if (res.code === 200) {
|
|
4988
|
+
const accessToken = res.data?.accessToken;
|
|
4989
|
+
this.storage.setItem("token", accessToken || "");
|
|
4990
|
+
await this.beforeSetLoginUser({ accessToken, refreshToken: res.data?.refreshToken });
|
|
4991
|
+
return res;
|
|
4992
|
+
}
|
|
4993
|
+
return false;
|
|
4994
|
+
}
|
|
4995
|
+
loginWithWeb(baseURL, { MD5, jsonwebtoken }) {
|
|
4996
|
+
const randomId = Math.random().toString(36).substring(2, 15);
|
|
4997
|
+
const timestamp = Date.now();
|
|
4998
|
+
const tokenSecret = "xiao" + randomId;
|
|
4999
|
+
let sign = "";
|
|
5000
|
+
if (MD5) {
|
|
5001
|
+
sign = MD5(`${tokenSecret}${timestamp}`).toString();
|
|
5002
|
+
}
|
|
5003
|
+
let token = "";
|
|
5004
|
+
if (jsonwebtoken) {
|
|
5005
|
+
token = jsonwebtoken.sign({ randomId, timestamp, sign }, tokenSecret, {
|
|
5006
|
+
expiresIn: 60 * 10
|
|
5007
|
+
});
|
|
5008
|
+
} else {
|
|
5009
|
+
token = tokenSecret;
|
|
5010
|
+
}
|
|
5011
|
+
const url = `${baseURL}/api/router?path=user&key=webLogin&p&loginToken=${token}&sign=${sign}&randomId=${randomId}`;
|
|
5012
|
+
return { url, token, tokenSecret };
|
|
5013
|
+
}
|
|
5014
|
+
async pollLoginStatus(data) {
|
|
5015
|
+
const token = data.token;
|
|
5016
|
+
const load = new BaseLoad;
|
|
5017
|
+
load.load(async () => {
|
|
5018
|
+
const res2 = await this.checkLoginStatus(token);
|
|
5019
|
+
if (res2.code === 500) {
|
|
5020
|
+
load.cancel("check-login-status");
|
|
5021
|
+
}
|
|
5022
|
+
return res2;
|
|
5023
|
+
}, {
|
|
5024
|
+
key: "check-login-status",
|
|
5025
|
+
isReRun: true,
|
|
5026
|
+
checkSuccess: (data2) => {
|
|
5027
|
+
return data2?.code === 200;
|
|
5028
|
+
}
|
|
5029
|
+
});
|
|
5030
|
+
const res = await load.hasLoaded("check-login-status", {
|
|
5031
|
+
timeout: 60 * 3 * 1000
|
|
5032
|
+
});
|
|
5033
|
+
if (res.code === 200 && res.data?.code === 200) {
|
|
5034
|
+
try {
|
|
5035
|
+
console.log("网页登录成功");
|
|
5036
|
+
return true;
|
|
5037
|
+
} catch (error) {
|
|
5038
|
+
console.log("登录失败", error);
|
|
5039
|
+
return false;
|
|
5040
|
+
}
|
|
5041
|
+
}
|
|
5042
|
+
console.log("登录失败", res);
|
|
5043
|
+
return false;
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
|
|
5047
|
+
// ../../node_modules/.pnpm/@kevisual+api@0.0.8/node_modules/@kevisual/api/query/query-login/query-login-browser.ts
|
|
5048
|
+
class QueryLoginBrowser2 extends QueryLogin2 {
|
|
5049
|
+
constructor(opts) {
|
|
5050
|
+
super({
|
|
5051
|
+
...opts,
|
|
5052
|
+
cache: new MyCache("login")
|
|
5053
|
+
});
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
// src/modules/login-handle.ts
|
|
5058
|
+
var message = createMessage();
|
|
5059
|
+
var redirectHome = () => {
|
|
5060
|
+
const href = window.location.href;
|
|
5061
|
+
const url = new URL(href);
|
|
5062
|
+
const redirect = url.searchParams.get("redirect");
|
|
5063
|
+
if (redirect) {
|
|
5064
|
+
const href2 = decodeURIComponent(redirect);
|
|
5065
|
+
window.open(href2, "_self");
|
|
5066
|
+
}
|
|
5067
|
+
emit({ type: "login-success", data: {} });
|
|
5068
|
+
setTimeout(() => {
|
|
5069
|
+
clearCode();
|
|
5070
|
+
}, 1500);
|
|
5071
|
+
};
|
|
5072
|
+
var loginHandle = async (opts) => {
|
|
5073
|
+
const { loginMethod, data, el } = opts;
|
|
5074
|
+
switch (loginMethod) {
|
|
5075
|
+
case "password":
|
|
5076
|
+
await loginByPassword(data);
|
|
5077
|
+
break;
|
|
5078
|
+
case "phone":
|
|
5079
|
+
await loginByPhone(data);
|
|
5080
|
+
break;
|
|
5081
|
+
case "wechat-mp":
|
|
5082
|
+
await loginByWeChatMp(data);
|
|
5083
|
+
break;
|
|
5084
|
+
case "wechat":
|
|
5085
|
+
await loginByWeChat(data);
|
|
5086
|
+
break;
|
|
5087
|
+
case "web":
|
|
5088
|
+
await loginByWeb(data);
|
|
5089
|
+
break;
|
|
5090
|
+
default:
|
|
5091
|
+
console.warn("未知的登录方式:", loginMethod);
|
|
5092
|
+
}
|
|
5093
|
+
};
|
|
5094
|
+
var loginByWeb = async (data) => {
|
|
5095
|
+
const url = new URL("https://kevisual.cn/api/router");
|
|
5096
|
+
const query2 = new Query({ url: "https://kevisual.cn/api/router" });
|
|
5097
|
+
const login = new QueryLoginBrowser2({ query: query2 });
|
|
5098
|
+
const res = login.loginWithWeb(url.origin, {});
|
|
5099
|
+
console.log("打开网页登录:", res);
|
|
5100
|
+
window.open(res.url, "_blank");
|
|
5101
|
+
const status = await login.pollLoginStatus(res);
|
|
5102
|
+
if (status) {
|
|
5103
|
+
redirectHome();
|
|
5104
|
+
} else {
|
|
5105
|
+
message.error("网页登录失败,请重试");
|
|
5106
|
+
}
|
|
5107
|
+
};
|
|
5108
|
+
var loginByPassword = async (data) => {
|
|
5109
|
+
console.log("使用用户名密码登录:", data);
|
|
5110
|
+
let needLogin = true;
|
|
5111
|
+
const isLogin = await query.checkLocalToken();
|
|
5112
|
+
if (isLogin) {
|
|
5113
|
+
const loginUser = await query.checkLocalUser();
|
|
5114
|
+
if (loginUser?.username === data?.username) {
|
|
5115
|
+
const res2 = await query.getMe();
|
|
5116
|
+
if (res2.code === 200) {
|
|
5117
|
+
needLogin = false;
|
|
5118
|
+
console.log("已登录,跳过登录步骤");
|
|
5119
|
+
message.success("已登录");
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5122
|
+
}
|
|
5123
|
+
if (!needLogin) {
|
|
5124
|
+
redirectHome();
|
|
5125
|
+
return;
|
|
5126
|
+
}
|
|
5127
|
+
const res = await query.login({
|
|
5128
|
+
username: data.username,
|
|
5129
|
+
password: data.password
|
|
5130
|
+
});
|
|
5131
|
+
if (res.code === 200) {
|
|
5132
|
+
console.log("登录成功");
|
|
5133
|
+
message.success("登录成功");
|
|
5134
|
+
redirectHome();
|
|
5135
|
+
} else {
|
|
5136
|
+
message.error(`登录失败: ${res.message}`);
|
|
5137
|
+
}
|
|
5138
|
+
};
|
|
5139
|
+
var loginByPhone = async (data) => {
|
|
5140
|
+
console.log("使用手机号登录:", data);
|
|
5141
|
+
};
|
|
5142
|
+
var loginByWeChat = async (data) => {
|
|
5143
|
+
console.log("使用微信登录:", data);
|
|
5144
|
+
};
|
|
5145
|
+
var loginByWeChatMp = async (data) => {
|
|
5146
|
+
console.log("使用微信公众号登录:", data);
|
|
5147
|
+
};
|
|
5148
|
+
var clearCode = () => {
|
|
5149
|
+
const url = new URL(window.location.href);
|
|
5150
|
+
url.searchParams.delete("code");
|
|
5151
|
+
url.searchParams.delete("state");
|
|
5152
|
+
url.searchParams.delete("user-check");
|
|
5153
|
+
url.searchParams.delete("redirect");
|
|
5154
|
+
window.history.replaceState({}, document.title, url.toString());
|
|
5155
|
+
};
|
|
5156
|
+
var checkWechat = async () => {
|
|
5157
|
+
const url = new URL(window.location.href);
|
|
5158
|
+
const code = url.searchParams.get("code");
|
|
5159
|
+
const state = url.searchParams.get("state");
|
|
5160
|
+
if (state?.includes?.("-")) {
|
|
5161
|
+
return;
|
|
5162
|
+
}
|
|
5163
|
+
if (!code) {
|
|
5164
|
+
return;
|
|
5165
|
+
}
|
|
5166
|
+
const res = await query.loginByWechat({ code });
|
|
5167
|
+
if (res.code === 200) {
|
|
5168
|
+
message.success("登录成功");
|
|
5169
|
+
redirectHome();
|
|
5170
|
+
} else {
|
|
5171
|
+
message.error(res.message || "登录失败");
|
|
5172
|
+
clearCode();
|
|
5173
|
+
}
|
|
5174
|
+
};
|
|
5175
|
+
var checkMpWechat = async () => {
|
|
5176
|
+
const url = new URL(window.location.href);
|
|
5177
|
+
const originState = url.searchParams.get("state");
|
|
5178
|
+
const [mpLogin, state] = originState ? originState.split("-") : [null, null];
|
|
5179
|
+
console.log("检查微信公众号登录流程:", mpLogin, state, originState);
|
|
5180
|
+
if (mpLogin === "1") {
|
|
5181
|
+
checkMpWechatInWx();
|
|
5182
|
+
} else if (mpLogin === "2") {
|
|
5183
|
+
const code = url.searchParams.get("code");
|
|
5184
|
+
const res2 = await query.post({
|
|
5185
|
+
path: "wx",
|
|
5186
|
+
key: "mplogin",
|
|
5187
|
+
state,
|
|
5188
|
+
code
|
|
5189
|
+
});
|
|
5190
|
+
if (res2.code === 200) {
|
|
5191
|
+
message.success("登录成功");
|
|
5192
|
+
} else {
|
|
5193
|
+
message.error(res2.message || "登录失败");
|
|
5194
|
+
}
|
|
5195
|
+
closePage();
|
|
5196
|
+
}
|
|
5197
|
+
};
|
|
5198
|
+
var checkPluginLogin = async () => {
|
|
5199
|
+
const userCheck = "user-check";
|
|
5200
|
+
const url = new URL(location.href);
|
|
5201
|
+
const redirect = url.searchParams.get("redirect");
|
|
5202
|
+
const redirectUrl = redirect ? decodeURIComponent(redirect) : "";
|
|
5203
|
+
const checkKey = url.searchParams.get(userCheck);
|
|
5204
|
+
if (redirect && checkKey) {
|
|
5205
|
+
const me = await query.getMe();
|
|
5206
|
+
if (me.code === 200) {
|
|
5207
|
+
message.success("登录插件中...");
|
|
5208
|
+
const token = await query.cacheStore.getAccessToken();
|
|
5209
|
+
const newRedirectUrl = new URL(redirectUrl);
|
|
5210
|
+
newRedirectUrl.searchParams.set("token", token + "");
|
|
5211
|
+
setTimeout(() => {
|
|
5212
|
+
window.open(newRedirectUrl.toString(), "_blank");
|
|
5213
|
+
}, 2000);
|
|
5214
|
+
return;
|
|
5215
|
+
}
|
|
5216
|
+
}
|
|
5217
|
+
console.log("checkKey", checkKey, redirectUrl);
|
|
5218
|
+
};
|
|
5219
|
+
var isWechat = () => {
|
|
5220
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
5221
|
+
return /micromessenger/i.test(ua);
|
|
5222
|
+
};
|
|
5223
|
+
var closePage = (time = 2000) => {
|
|
5224
|
+
if (!isWechat()) {
|
|
5225
|
+
setTimeout(() => {
|
|
5226
|
+
window.close();
|
|
5227
|
+
}, time);
|
|
5228
|
+
return;
|
|
5229
|
+
}
|
|
5230
|
+
if (window.WeixinJSBridge) {
|
|
5231
|
+
setTimeout(() => {
|
|
5232
|
+
window.WeixinJSBridge.call("closeWindow");
|
|
5233
|
+
}, time);
|
|
5234
|
+
} else {
|
|
5235
|
+
setTimeout(() => {
|
|
5236
|
+
window.close();
|
|
5237
|
+
}, time);
|
|
5238
|
+
}
|
|
5239
|
+
};
|
|
5240
|
+
var checkMpWechatInWx = async () => {
|
|
5241
|
+
const wxAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`;
|
|
5242
|
+
const appid = WX_MP_APP_ID;
|
|
5243
|
+
const url = new URL(window.location.href);
|
|
5244
|
+
const originState = url.searchParams.get("state");
|
|
5245
|
+
let [mpLogin, state] = originState ? originState.split("-") : [null, null];
|
|
5246
|
+
const redirectURL = new URL(url.pathname, url.origin);
|
|
5247
|
+
state = "2-" + state;
|
|
5248
|
+
const redirect_uri = encodeURIComponent(redirectURL.toString());
|
|
5249
|
+
document.body.innerHTML = `<p>正在准备跳转到微信公众号授权页面...</p>`;
|
|
5250
|
+
const scope = `snsapi_userinfo`;
|
|
5251
|
+
if (!state) {
|
|
5252
|
+
alert("Invalid state. Please try again later.");
|
|
5253
|
+
closePage();
|
|
5254
|
+
return;
|
|
5255
|
+
}
|
|
5256
|
+
const link = wxAuthUrl.replace("APPID", appid).replace("REDIRECT_URI", redirect_uri).replace("SCOPE", scope).replace("STATE", state);
|
|
5257
|
+
setTimeout(() => {
|
|
5258
|
+
window.location.href = link;
|
|
5259
|
+
}, 100);
|
|
5260
|
+
};
|
|
5261
|
+
setTimeout(() => {
|
|
5262
|
+
checkMpWechat();
|
|
5263
|
+
}, 100);
|
|
5264
|
+
var getQrCode = async () => {
|
|
5265
|
+
const res = await query.post({
|
|
4332
5266
|
path: "wx",
|
|
4333
5267
|
key: "get-qrcode-ticket"
|
|
4334
5268
|
});
|
|
@@ -4478,15 +5412,15 @@ var useCreateLoginQRCode = (el) => {
|
|
|
4478
5412
|
|
|
4479
5413
|
// ../../node_modules/.pnpm/@kevisual+context@0.0.4/node_modules/@kevisual/context/dist/app.js
|
|
4480
5414
|
var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
4481
|
-
function
|
|
5415
|
+
function getDefaultExportFromCjs2(x) {
|
|
4482
5416
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4483
5417
|
}
|
|
4484
|
-
var
|
|
4485
|
-
var
|
|
4486
|
-
function
|
|
4487
|
-
if (
|
|
4488
|
-
return
|
|
4489
|
-
|
|
5418
|
+
var eventemitter32 = { exports: {} };
|
|
5419
|
+
var hasRequiredEventemitter32;
|
|
5420
|
+
function requireEventemitter32() {
|
|
5421
|
+
if (hasRequiredEventemitter32)
|
|
5422
|
+
return eventemitter32.exports;
|
|
5423
|
+
hasRequiredEventemitter32 = 1;
|
|
4490
5424
|
(function(module) {
|
|
4491
5425
|
var has = Object.prototype.hasOwnProperty, prefix = "~";
|
|
4492
5426
|
function Events() {}
|
|
@@ -4519,11 +5453,11 @@ function requireEventemitter3() {
|
|
|
4519
5453
|
else
|
|
4520
5454
|
delete emitter._events[evt];
|
|
4521
5455
|
}
|
|
4522
|
-
function
|
|
5456
|
+
function EventEmitter3() {
|
|
4523
5457
|
this._events = new Events;
|
|
4524
5458
|
this._eventsCount = 0;
|
|
4525
5459
|
}
|
|
4526
|
-
|
|
5460
|
+
EventEmitter3.prototype.eventNames = function eventNames() {
|
|
4527
5461
|
var names = [], events, name;
|
|
4528
5462
|
if (this._eventsCount === 0)
|
|
4529
5463
|
return names;
|
|
@@ -4536,7 +5470,7 @@ function requireEventemitter3() {
|
|
|
4536
5470
|
}
|
|
4537
5471
|
return names;
|
|
4538
5472
|
};
|
|
4539
|
-
|
|
5473
|
+
EventEmitter3.prototype.listeners = function listeners(event) {
|
|
4540
5474
|
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
4541
5475
|
if (!handlers)
|
|
4542
5476
|
return [];
|
|
@@ -4547,7 +5481,7 @@ function requireEventemitter3() {
|
|
|
4547
5481
|
}
|
|
4548
5482
|
return ee;
|
|
4549
5483
|
};
|
|
4550
|
-
|
|
5484
|
+
EventEmitter3.prototype.listenerCount = function listenerCount(event) {
|
|
4551
5485
|
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
4552
5486
|
if (!listeners)
|
|
4553
5487
|
return 0;
|
|
@@ -4555,7 +5489,7 @@ function requireEventemitter3() {
|
|
|
4555
5489
|
return 1;
|
|
4556
5490
|
return listeners.length;
|
|
4557
5491
|
};
|
|
4558
|
-
|
|
5492
|
+
EventEmitter3.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
4559
5493
|
var evt = prefix ? prefix + event : event;
|
|
4560
5494
|
if (!this._events[evt])
|
|
4561
5495
|
return false;
|
|
@@ -4610,13 +5544,13 @@ function requireEventemitter3() {
|
|
|
4610
5544
|
}
|
|
4611
5545
|
return true;
|
|
4612
5546
|
};
|
|
4613
|
-
|
|
5547
|
+
EventEmitter3.prototype.on = function on(event, fn, context) {
|
|
4614
5548
|
return addListener(this, event, fn, context, false);
|
|
4615
5549
|
};
|
|
4616
|
-
|
|
5550
|
+
EventEmitter3.prototype.once = function once(event, fn, context) {
|
|
4617
5551
|
return addListener(this, event, fn, context, true);
|
|
4618
5552
|
};
|
|
4619
|
-
|
|
5553
|
+
EventEmitter3.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
4620
5554
|
var evt = prefix ? prefix + event : event;
|
|
4621
5555
|
if (!this._events[evt])
|
|
4622
5556
|
return this;
|
|
@@ -4642,7 +5576,7 @@ function requireEventemitter3() {
|
|
|
4642
5576
|
}
|
|
4643
5577
|
return this;
|
|
4644
5578
|
};
|
|
4645
|
-
|
|
5579
|
+
EventEmitter3.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
4646
5580
|
var evt;
|
|
4647
5581
|
if (event) {
|
|
4648
5582
|
evt = prefix ? prefix + event : event;
|
|
@@ -4654,19 +5588,19 @@ function requireEventemitter3() {
|
|
|
4654
5588
|
}
|
|
4655
5589
|
return this;
|
|
4656
5590
|
};
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
5591
|
+
EventEmitter3.prototype.off = EventEmitter3.prototype.removeListener;
|
|
5592
|
+
EventEmitter3.prototype.addListener = EventEmitter3.prototype.on;
|
|
5593
|
+
EventEmitter3.prefixed = prefix;
|
|
5594
|
+
EventEmitter3.EventEmitter = EventEmitter3;
|
|
4661
5595
|
{
|
|
4662
|
-
module.exports =
|
|
5596
|
+
module.exports = EventEmitter3;
|
|
4663
5597
|
}
|
|
4664
|
-
})(
|
|
4665
|
-
return
|
|
5598
|
+
})(eventemitter32);
|
|
5599
|
+
return eventemitter32.exports;
|
|
4666
5600
|
}
|
|
4667
|
-
var
|
|
4668
|
-
var
|
|
4669
|
-
var
|
|
5601
|
+
var eventemitter3Exports2 = requireEventemitter32();
|
|
5602
|
+
var EventEmitter3 = /* @__PURE__ */ getDefaultExportFromCjs2(eventemitter3Exports2);
|
|
5603
|
+
var reRunFn2 = (promiseOpts) => {
|
|
4670
5604
|
const timeout = promiseOpts.timeout || 5 * 60 * 1000;
|
|
4671
5605
|
const interval = promiseOpts.interval || 1000;
|
|
4672
5606
|
const checkSuccess = promiseOpts?.checkSuccess || (() => true);
|
|
@@ -4718,14 +5652,14 @@ var reRunFn = (promiseOpts) => {
|
|
|
4718
5652
|
});
|
|
4719
5653
|
};
|
|
4720
5654
|
|
|
4721
|
-
class
|
|
5655
|
+
class BaseLoad2 {
|
|
4722
5656
|
modules = new Map;
|
|
4723
5657
|
event;
|
|
4724
5658
|
loading;
|
|
4725
|
-
static reRunFn =
|
|
5659
|
+
static reRunFn = reRunFn2;
|
|
4726
5660
|
timeout = 5 * 60 * 1000;
|
|
4727
5661
|
constructor() {
|
|
4728
|
-
this.event = new
|
|
5662
|
+
this.event = new EventEmitter3;
|
|
4729
5663
|
this.loading = false;
|
|
4730
5664
|
}
|
|
4731
5665
|
listenKey(key, listenOpts) {
|
|
@@ -4827,7 +5761,7 @@ class BaseLoad {
|
|
|
4827
5761
|
newModule.controller = new AbortController;
|
|
4828
5762
|
const signal = newModule.controller.signal;
|
|
4829
5763
|
this.modules.set(key, newModule);
|
|
4830
|
-
const data = await
|
|
5764
|
+
const data = await reRunFn2({
|
|
4831
5765
|
timeout: opts.timeout,
|
|
4832
5766
|
interval: opts.interval,
|
|
4833
5767
|
checkSuccess: opts.checkSuccess,
|
|
@@ -4963,7 +5897,7 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
4963
5897
|
return _env[key];
|
|
4964
5898
|
}
|
|
4965
5899
|
if (key) {
|
|
4966
|
-
const baseLoad = new
|
|
5900
|
+
const baseLoad = new BaseLoad2;
|
|
4967
5901
|
const voidFn = async () => {
|
|
4968
5902
|
return _env[key];
|
|
4969
5903
|
};
|
|
@@ -5022,7 +5956,7 @@ class InitEnv {
|
|
|
5022
5956
|
gt.useContextKey = useContextKey;
|
|
5023
5957
|
gt.use = use;
|
|
5024
5958
|
gt.webEnv = { useConfigKey, useContextKey, use };
|
|
5025
|
-
load && (gt.Load =
|
|
5959
|
+
load && (gt.Load = BaseLoad2);
|
|
5026
5960
|
}
|
|
5027
5961
|
}
|
|
5028
5962
|
InitEnv.init();
|
|
@@ -5034,26 +5968,29 @@ var wxmpSvg = `<svg t="1764510467010" class="icon" viewBox="0 0 1024 1024" versi
|
|
|
5034
5968
|
var wxOpenSvg = `<svg t="1764511395617" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3882" width="32" height="32"><path d="M256 259.584c-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.184 0 44.032-14.848 44.032-44.032s-22.016-44.032-44.032-44.032zM541.184 303.616c0-29.184-14.848-44.032-44.032-44.032-29.184 0-51.2 14.848-51.2 44.032s29.184 44.032 51.2 44.032c29.696 0 44.032-22.016 44.032-44.032zM614.4 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.848-36.352-44.032-36.352z" p-id="3883"></path><path d="M1024 625.152c0-138.752-124.416-256-285.184-270.848-29.184-153.6-189.952-263.168-373.248-263.168C160.768 91.648 0 230.4 0 406.016c0 95.232 44.032 175.616 138.752 241.152L109.568 742.4c0 7.168 0 14.848 7.168 22.016h14.848l117.248-58.368h14.848c36.352 7.168 66.048 14.848 109.568 14.848 14.848 0 44.032-7.168 44.032-7.168C460.8 822.784 578.048 896 716.8 896c36.352 0 73.216-7.168 102.4-14.848l87.552 51.2h14.848c7.168-7.168 7.168-7.168 7.168-14.848l-22.016-87.552c80.896-58.368 117.248-131.584 117.248-204.8z m-621.568 51.2h-36.352c-36.352 0-66.048-7.168-95.232-14.848l-22.016-7.168h-7.168L153.6 698.368l22.016-66.048c0-7.168 0-14.848-7.168-14.848C80.384 559.616 36.352 486.4 36.352 398.848 36.352 245.248 182.784 128 358.4 128c160.768 0 300.032 95.232 329.216 226.816-168.448 0-300.032 117.248-300.032 263.168 7.168 22.016 14.848 44.032 14.848 58.368z m467.968 132.096c-7.168 7.168-7.168 7.168-7.168 14.848l14.848 51.2L819.2 844.8h-14.848c-29.184 7.168-66.048 14.848-95.232 14.848-146.432 0-270.848-102.4-270.848-226.816 0-131.584 124.416-233.984 270.848-233.984s270.848 102.4 270.848 226.816c0 65.536-36.352 123.904-109.568 182.784z" p-id="3884"></path><path d="M804.352 508.416c-14.848 0-36.352 14.848-36.352 36.352 0 14.848 14.848 36.352 36.352 36.352 29.184 0 44.032-14.848 44.032-36.352 0-14.336-14.336-36.352-44.032-36.352z" p-id="3885"></path></svg>`;
|
|
5035
5969
|
var phone = `<svg t="1764511425462" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5097" width="32" height="32"><path d="M820.409449 797.228346q0 25.19685-10.07874 46.866142t-27.716535 38.299213-41.322835 26.204724-50.897638 9.574803l-357.795276 0q-27.212598 0-50.897638-9.574803t-41.322835-26.204724-27.716535-38.299213-10.07874-46.866142l0-675.275591q0-25.19685 10.07874-47.370079t27.716535-38.80315 41.322835-26.204724 50.897638-9.574803l357.795276 0q27.212598 0 50.897638 9.574803t41.322835 26.204724 27.716535 38.80315 10.07874 47.370079l0 675.275591zM738.771654 170.330709l-455.559055 0 0 577.511811 455.559055 0 0-577.511811zM510.992126 776.062992q-21.165354 0-36.787402 15.11811t-15.622047 37.291339q0 21.165354 15.622047 36.787402t36.787402 15.622047q22.173228 0 37.291339-15.622047t15.11811-36.787402q0-22.173228-15.11811-37.291339t-37.291339-15.11811zM591.622047 84.661417q0-8.062992-5.03937-12.598425t-11.086614-4.535433l-128 0q-5.03937 0-10.582677 4.535433t-5.543307 12.598425 5.03937 12.598425 11.086614 4.535433l128 0q6.047244 0 11.086614-4.535433t5.03937-12.598425z" p-id="5098"></path></svg>`;
|
|
5036
5970
|
var pwd = `<svg t="1764511500570" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="10511" width="32" height="32"><path d="M768.9216 422.72768 372.06016 422.72768C378.88 365.21984 329.37984 131.42016 512.2048 125.72672c173.83424-6.59456 146.78016 213.34016 146.78016 213.34016l85.13536 0.57344c0 0 24.73984-294.4-231.91552-295.8336C232.09984 58.01984 297.82016 377.18016 289.28 422.72768c1.98656 0 4.56704 0 7.29088 0-55.88992 0-101.21216 45.34272-101.21216 101.21216l0 337.38752c0 55.88992 45.34272 101.21216 101.21216 101.21216l472.35072 0c55.88992 0 101.21216-45.34272 101.21216-101.21216L870.13376 523.93984C870.13376 468.0704 824.79104 422.72768 768.9216 422.72768zM566.4768 717.02528l0 76.84096c0 18.57536-15.1552 33.73056-33.73056 33.73056-18.57536 0-33.73056-15.1552-33.73056-33.73056l0-76.84096c-20.09088-11.69408-33.73056-33.21856-33.73056-58.12224 0-37.2736 30.208-67.4816 67.4816-67.4816 37.2736 0 67.4816 30.208 67.4816 67.4816C600.22784 683.80672 586.58816 705.3312 566.4768 717.02528z" fill="#272636" p-id="10512"></path></svg>`;
|
|
5971
|
+
var web = `<svg t="1764511538113" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="11994" width="32" height="32"><path d="M512 85.333333C264.533333 85.333333 64 285.866667 64 533.333333s200.533333 448 448 448 448-200.533333 448-448S759.466667 85.333333 512 85.333333z m0 810.666667c-200.533333 0-362.666667-162.133333-362.666667-362.666667S311.466667 170.666667 512 170.666667s362.666667 162.133333 362.666667 362.666667-162.133333 362.666667-362.666667 362.666667z" p-id="11995"></path><path d="M512 298.666667c-119.466667 0-216.533333 97.066667-216.533333 216.533333s97.066667 216.533333 216.533333 216.533333 216.533333-97.066667 216.533333-216.533333-97.066667-216.533333-216.533333-216.533333z m0 362.666666c-80.853333 0-146.133333-65.28-146.133333-146.133333s65.28-146.133333 146.133333-146.133333 146.133333 65.28 146.133333 146.133333-65.28 146.133333-146.133333 146.133333z" p-id="11996"></path></svg>`;
|
|
5037
5972
|
var icons = {
|
|
5038
5973
|
pwd,
|
|
5974
|
+
web,
|
|
5039
5975
|
phone,
|
|
5040
5976
|
wxmpSvg,
|
|
5041
5977
|
wxOpenSvg
|
|
5042
5978
|
};
|
|
5043
5979
|
var DefaultLoginMethods = [
|
|
5044
5980
|
{ id: "password", name: "密码登录", icon: "pwd" },
|
|
5981
|
+
{ id: "web", name: "网页登录", icon: "web" },
|
|
5045
5982
|
{ id: "wechat", name: "微信登录", icon: "wxmpSvg", appid: "wx9378885c8390e09b" },
|
|
5046
5983
|
{ id: "wechat-mp", name: "微信公众号", icon: "wxOpenSvg", appid: WX_MP_APP_ID },
|
|
5047
5984
|
{ id: "wechat-mp-ticket", name: "微信公众号", icon: "wxOpenSvg" },
|
|
5048
5985
|
{ id: "phone", name: "手机号登录", icon: "phone" }
|
|
5049
5986
|
];
|
|
5050
|
-
var LoginMethods = ["password", "phone", "wechat", "wechat-mp", "wechat-mp-ticket"];
|
|
5987
|
+
var LoginMethods = ["password", "web", "phone", "wechat", "wechat-mp", "wechat-mp-ticket"];
|
|
5051
5988
|
var getLoginMethodByDomain = () => {
|
|
5052
5989
|
let domain = window.location.host;
|
|
5053
5990
|
let methods = [];
|
|
5054
|
-
const
|
|
5055
|
-
if (
|
|
5056
|
-
domain = "localhost
|
|
5991
|
+
const has51 = domain.includes("localhost") && (domain.endsWith("51515") || domain.endsWith("51015"));
|
|
5992
|
+
if (has51) {
|
|
5993
|
+
domain = "localhost";
|
|
5057
5994
|
}
|
|
5058
5995
|
switch (domain) {
|
|
5059
5996
|
case "kevisual.xiongxiao.me":
|
|
@@ -5062,11 +5999,11 @@ var getLoginMethodByDomain = () => {
|
|
|
5062
5999
|
case "kevisual.cn":
|
|
5063
6000
|
methods = ["password", "wechat-mp-ticket", "wechat"];
|
|
5064
6001
|
break;
|
|
5065
|
-
case "localhost
|
|
5066
|
-
methods = ["password"];
|
|
6002
|
+
case "localhost":
|
|
6003
|
+
methods = ["password", "web"];
|
|
5067
6004
|
break;
|
|
5068
6005
|
default:
|
|
5069
|
-
methods = ["password", "phone", "wechat", "wechat-mp", "wechat-mp-ticket"];
|
|
6006
|
+
methods = ["password", "web", "phone", "wechat", "wechat-mp", "wechat-mp-ticket"];
|
|
5070
6007
|
break;
|
|
5071
6008
|
}
|
|
5072
6009
|
return DefaultLoginMethods.filter((method) => methods.includes(method.id));
|
|
@@ -5167,6 +6104,8 @@ class KvLogin extends HTMLElement {
|
|
|
5167
6104
|
username: username?.value || "",
|
|
5168
6105
|
password: password?.value || ""
|
|
5169
6106
|
};
|
|
6107
|
+
case "web":
|
|
6108
|
+
return {};
|
|
5170
6109
|
case "phone":
|
|
5171
6110
|
const phone2 = this.shadowRoot.querySelector("#phone");
|
|
5172
6111
|
const code = this.shadowRoot.querySelector("#code");
|
|
@@ -5213,6 +6152,14 @@ class KvLogin extends HTMLElement {
|
|
|
5213
6152
|
</form>
|
|
5214
6153
|
`;
|
|
5215
6154
|
}
|
|
6155
|
+
renderWebForm() {
|
|
6156
|
+
return html`
|
|
6157
|
+
<div class="web-login">
|
|
6158
|
+
<button type="button" class="refresh-button" @click=${this.handleLogin.bind(this)}>点击登录</button>
|
|
6159
|
+
<slot></slot>
|
|
6160
|
+
</div>
|
|
6161
|
+
`;
|
|
6162
|
+
}
|
|
5216
6163
|
renderPhoneForm() {
|
|
5217
6164
|
return html`
|
|
5218
6165
|
<form id="loginForm" class="login-form">
|
|
@@ -5302,6 +6249,8 @@ class KvLogin extends HTMLElement {
|
|
|
5302
6249
|
switch (this.selectedMethod) {
|
|
5303
6250
|
case "password":
|
|
5304
6251
|
return this.renderPasswordForm();
|
|
6252
|
+
case "web":
|
|
6253
|
+
return this.renderWebForm();
|
|
5305
6254
|
case "phone":
|
|
5306
6255
|
return this.renderPhoneForm();
|
|
5307
6256
|
case "wechat":
|
|
@@ -5563,5 +6512,7 @@ class KvLogin extends HTMLElement {
|
|
|
5563
6512
|
}
|
|
5564
6513
|
customElements.define("kv-login", KvLogin);
|
|
5565
6514
|
export {
|
|
5566
|
-
loginEmitter
|
|
6515
|
+
loginEmitter,
|
|
6516
|
+
clearCode,
|
|
6517
|
+
checkPluginLogin
|
|
5567
6518
|
};
|