lgsso-sdk 1.2.3 → 1.2.5
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/lgsso-sdk.cjs +63 -40
- package/dist/lgsso-sdk.esm.js +63 -40
- package/dist/lgsso-sdk.js +63 -40
- package/dist/lgsso-sdk.min.js +1 -1
- package/package.json +1 -1
- package/src/sso.js +63 -40
package/dist/lgsso-sdk.cjs
CHANGED
|
@@ -4101,7 +4101,7 @@ function isIOS() {
|
|
|
4101
4101
|
platform.includes('ipad') ||
|
|
4102
4102
|
// 场景2:iPadOS 13+ 伪装Mac(UA含macintosh + 触摸+ 非Mac平台)
|
|
4103
4103
|
(
|
|
4104
|
-
userAgent.includes('macintosh') &&
|
|
4104
|
+
userAgent.includes('macintosh') &&
|
|
4105
4105
|
maxTouchPoints > 0 && // iPad Air 触摸点≥5,Mac几乎为0
|
|
4106
4106
|
!platform.includes('mac') && // 排除真Mac
|
|
4107
4107
|
!window.MSStream
|
|
@@ -4198,17 +4198,33 @@ function createSSO() {
|
|
|
4198
4198
|
* @returns {Promise<Object>} 接口返回结果
|
|
4199
4199
|
*/
|
|
4200
4200
|
async logout() {
|
|
4201
|
+
// 1. 前置校验:初始化状态
|
|
4201
4202
|
if (!config) {
|
|
4202
4203
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4203
4204
|
}
|
|
4204
4205
|
|
|
4206
|
+
// 2. 工具函数:统一构建登录跳转URL(确保完整编码当前URL的所有参数/hash)
|
|
4207
|
+
const buildLoginUrl = () => {
|
|
4208
|
+
if (!config.logOutUrl || !isBrowser()) return '';
|
|
4209
|
+
// 关键:获取当前完整URL(含query、hash)并完整编码,避免参数丢失
|
|
4210
|
+
const currentFullUrl = window.location.href;
|
|
4211
|
+
const encodedRedirectUri = encodeURIComponent(currentFullUrl);
|
|
4212
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4213
|
+
};
|
|
4214
|
+
|
|
4215
|
+
// 3. 校验logoutApi配置(仅接口调用时需要,跳转登录页不受此影响)
|
|
4205
4216
|
if (!config.logoutApi) {
|
|
4217
|
+
// 无logoutApi时仍清除token并跳转登录页,保证基础退出逻辑
|
|
4218
|
+
this.removeToken();
|
|
4219
|
+
const loginUrl = buildLoginUrl();
|
|
4220
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4206
4221
|
return { code: -102, msg: '未配置logoutApi', success: false };
|
|
4207
4222
|
}
|
|
4208
4223
|
|
|
4209
4224
|
const token = this.getToken();
|
|
4210
4225
|
if (token) {
|
|
4211
4226
|
try {
|
|
4227
|
+
// 调用退出接口
|
|
4212
4228
|
const result = await request(
|
|
4213
4229
|
config.logoutApi,
|
|
4214
4230
|
{
|
|
@@ -4217,31 +4233,37 @@ function createSSO() {
|
|
|
4217
4233
|
timeout: config.timeout
|
|
4218
4234
|
}
|
|
4219
4235
|
);
|
|
4236
|
+
// 无论接口返回结果如何,都清除token
|
|
4220
4237
|
this.removeToken();
|
|
4221
4238
|
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4239
|
+
// 跳转登录页(携带完整的当前URL)
|
|
4240
|
+
const loginUrl = buildLoginUrl();
|
|
4241
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4225
4242
|
return result;
|
|
4226
4243
|
} catch (error) {
|
|
4244
|
+
// 接口调用失败,仍清除token并跳转登录页
|
|
4245
|
+
this.removeToken();
|
|
4246
|
+
const loginUrl = buildLoginUrl();
|
|
4247
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4227
4248
|
return { code: -103, msg: `退出失败: ${error.message}`, success: false };
|
|
4228
4249
|
}
|
|
4229
4250
|
} else {
|
|
4251
|
+
// 无token时直接清除(兜底)并跳转登录页
|
|
4230
4252
|
this.removeToken();
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
}
|
|
4253
|
+
const loginUrl = buildLoginUrl();
|
|
4254
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4234
4255
|
return { code: 0, msg: '已成功清除token', success: true };
|
|
4235
4256
|
}
|
|
4236
4257
|
},
|
|
4237
4258
|
|
|
4238
4259
|
/**
|
|
4239
4260
|
* 用token换取新accessCode并跳转到指定URL
|
|
4240
|
-
* @param {string} redirectUrl -
|
|
4261
|
+
* @param {string} redirectUrl - 目标跳转地址(支持带query/hash参数)
|
|
4241
4262
|
* @param {string} target - 当前页面:_self、新页面打开:_blank,默认当前页_self
|
|
4242
4263
|
* @returns {Promise<Object>} 接口返回结果
|
|
4243
4264
|
*/
|
|
4244
4265
|
async toUrl(redirectUrl, target = '_self') {
|
|
4266
|
+
// 1. 前置校验:初始化状态、参数合法性
|
|
4245
4267
|
if (!config) {
|
|
4246
4268
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4247
4269
|
}
|
|
@@ -4250,35 +4272,43 @@ function createSSO() {
|
|
|
4250
4272
|
return { code: -104, msg: '请提供跳转地址', success: false };
|
|
4251
4273
|
}
|
|
4252
4274
|
|
|
4253
|
-
//
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4275
|
+
// ========== 新增核心逻辑:判断当前URL是否包含platType=screen ==========
|
|
4276
|
+
// 优先级最高:只要当前地址有platType=screen,强制用_self
|
|
4277
|
+
const isPlatTypeScreen = isBrowser() && getQueryParam('platType') === 'screen';
|
|
4278
|
+
|
|
4279
|
+
// 2. 处理target参数:platType=screen > iOS > 传入的target
|
|
4280
|
+
const finalTarget = isPlatTypeScreen
|
|
4281
|
+
? '_self' // platType=screen时强制_self
|
|
4282
|
+
: (isIOS() ? '_self' : target); // 否则沿用原iOS判断逻辑
|
|
4283
|
+
|
|
4284
|
+
if (!['_self', '_blank'].includes(finalTarget)) {
|
|
4260
4285
|
return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
|
|
4261
4286
|
}
|
|
4262
4287
|
|
|
4288
|
+
// 3. 工具函数:统一构建登录跳转URL(避免重复代码,确保参数完整编码)
|
|
4289
|
+
const buildLoginUrl = (redirectUrl) => {
|
|
4290
|
+
if (!config.logOutUrl) return '';
|
|
4291
|
+
// 关键:encodeURIComponent 会完整编码redirectUrl的所有部分(query/hash),避免参数丢失
|
|
4292
|
+
const encodedRedirectUri = encodeURIComponent(redirectUrl);
|
|
4293
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4294
|
+
};
|
|
4295
|
+
|
|
4296
|
+
// 4. 校验refreshCodeApi配置
|
|
4263
4297
|
if (!config.refreshCodeApi) {
|
|
4264
4298
|
return { code: -105, msg: '未配置refreshCodeApi', success: false };
|
|
4265
4299
|
}
|
|
4266
4300
|
|
|
4301
|
+
// 5. 获取token,无token则直接跳登录页
|
|
4267
4302
|
const token = this.getToken();
|
|
4268
4303
|
if (!token) {
|
|
4269
4304
|
if (isBrowser() && config.logOutUrl) {
|
|
4270
|
-
const loginUrl =
|
|
4271
|
-
|
|
4272
|
-
// 根据target决定打开方式
|
|
4273
|
-
if (target === '_blank') {
|
|
4274
|
-
window.open(loginUrl, '_blank');
|
|
4275
|
-
} else {
|
|
4276
|
-
window.location.href = loginUrl;
|
|
4277
|
-
}
|
|
4305
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4306
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4278
4307
|
}
|
|
4279
4308
|
return { code: -106, msg: '未找到有效token', success: false };
|
|
4280
4309
|
}
|
|
4281
4310
|
|
|
4311
|
+
// 6. 有token则尝试换取accessCode并跳转
|
|
4282
4312
|
try {
|
|
4283
4313
|
const result = await request(
|
|
4284
4314
|
config.refreshCodeApi,
|
|
@@ -4290,32 +4320,25 @@ function createSSO() {
|
|
|
4290
4320
|
);
|
|
4291
4321
|
|
|
4292
4322
|
if (result.code === 0 && result.data && isBrowser()) {
|
|
4323
|
+
// 拼接accessCode到目标URL,保留原URL的所有参数/hash
|
|
4293
4324
|
const url = new URL(redirectUrl);
|
|
4294
4325
|
url.searchParams.set(config.accessCodeKey, result.data);
|
|
4295
4326
|
const targetUrl = url.toString();
|
|
4296
|
-
|
|
4297
|
-
// 根据target参数决定跳转方式
|
|
4298
|
-
if (target === '_blank') {
|
|
4299
|
-
window.open(targetUrl, '_blank');
|
|
4300
|
-
} else {
|
|
4301
|
-
window.location.href = targetUrl;
|
|
4302
|
-
}
|
|
4327
|
+
finalTarget === '_blank' ? window.open(targetUrl, '_blank') : window.location.href = targetUrl;
|
|
4303
4328
|
} else {
|
|
4304
|
-
|
|
4305
|
-
if (
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
window.location.href = loginUrl;
|
|
4329
|
+
// 接口返回失败,跳登录页(复用统一的登录URL构建逻辑)
|
|
4330
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4331
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4332
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4309
4333
|
}
|
|
4310
4334
|
}
|
|
4311
4335
|
|
|
4312
4336
|
return result;
|
|
4313
4337
|
} catch (error) {
|
|
4314
|
-
|
|
4315
|
-
if (
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
window.location.href = loginUrl;
|
|
4338
|
+
// 接口异常,跳登录页(复用统一的登录URL构建逻辑)
|
|
4339
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4340
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4341
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4319
4342
|
}
|
|
4320
4343
|
return { code: -107, msg: `跳转失败: ${error.message}`, success: false };
|
|
4321
4344
|
}
|
package/dist/lgsso-sdk.esm.js
CHANGED
|
@@ -4097,7 +4097,7 @@ function isIOS() {
|
|
|
4097
4097
|
platform.includes('ipad') ||
|
|
4098
4098
|
// 场景2:iPadOS 13+ 伪装Mac(UA含macintosh + 触摸+ 非Mac平台)
|
|
4099
4099
|
(
|
|
4100
|
-
userAgent.includes('macintosh') &&
|
|
4100
|
+
userAgent.includes('macintosh') &&
|
|
4101
4101
|
maxTouchPoints > 0 && // iPad Air 触摸点≥5,Mac几乎为0
|
|
4102
4102
|
!platform.includes('mac') && // 排除真Mac
|
|
4103
4103
|
!window.MSStream
|
|
@@ -4194,17 +4194,33 @@ function createSSO() {
|
|
|
4194
4194
|
* @returns {Promise<Object>} 接口返回结果
|
|
4195
4195
|
*/
|
|
4196
4196
|
async logout() {
|
|
4197
|
+
// 1. 前置校验:初始化状态
|
|
4197
4198
|
if (!config) {
|
|
4198
4199
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4199
4200
|
}
|
|
4200
4201
|
|
|
4202
|
+
// 2. 工具函数:统一构建登录跳转URL(确保完整编码当前URL的所有参数/hash)
|
|
4203
|
+
const buildLoginUrl = () => {
|
|
4204
|
+
if (!config.logOutUrl || !isBrowser()) return '';
|
|
4205
|
+
// 关键:获取当前完整URL(含query、hash)并完整编码,避免参数丢失
|
|
4206
|
+
const currentFullUrl = window.location.href;
|
|
4207
|
+
const encodedRedirectUri = encodeURIComponent(currentFullUrl);
|
|
4208
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4209
|
+
};
|
|
4210
|
+
|
|
4211
|
+
// 3. 校验logoutApi配置(仅接口调用时需要,跳转登录页不受此影响)
|
|
4201
4212
|
if (!config.logoutApi) {
|
|
4213
|
+
// 无logoutApi时仍清除token并跳转登录页,保证基础退出逻辑
|
|
4214
|
+
this.removeToken();
|
|
4215
|
+
const loginUrl = buildLoginUrl();
|
|
4216
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4202
4217
|
return { code: -102, msg: '未配置logoutApi', success: false };
|
|
4203
4218
|
}
|
|
4204
4219
|
|
|
4205
4220
|
const token = this.getToken();
|
|
4206
4221
|
if (token) {
|
|
4207
4222
|
try {
|
|
4223
|
+
// 调用退出接口
|
|
4208
4224
|
const result = await request(
|
|
4209
4225
|
config.logoutApi,
|
|
4210
4226
|
{
|
|
@@ -4213,31 +4229,37 @@ function createSSO() {
|
|
|
4213
4229
|
timeout: config.timeout
|
|
4214
4230
|
}
|
|
4215
4231
|
);
|
|
4232
|
+
// 无论接口返回结果如何,都清除token
|
|
4216
4233
|
this.removeToken();
|
|
4217
4234
|
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4235
|
+
// 跳转登录页(携带完整的当前URL)
|
|
4236
|
+
const loginUrl = buildLoginUrl();
|
|
4237
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4221
4238
|
return result;
|
|
4222
4239
|
} catch (error) {
|
|
4240
|
+
// 接口调用失败,仍清除token并跳转登录页
|
|
4241
|
+
this.removeToken();
|
|
4242
|
+
const loginUrl = buildLoginUrl();
|
|
4243
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4223
4244
|
return { code: -103, msg: `退出失败: ${error.message}`, success: false };
|
|
4224
4245
|
}
|
|
4225
4246
|
} else {
|
|
4247
|
+
// 无token时直接清除(兜底)并跳转登录页
|
|
4226
4248
|
this.removeToken();
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
}
|
|
4249
|
+
const loginUrl = buildLoginUrl();
|
|
4250
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4230
4251
|
return { code: 0, msg: '已成功清除token', success: true };
|
|
4231
4252
|
}
|
|
4232
4253
|
},
|
|
4233
4254
|
|
|
4234
4255
|
/**
|
|
4235
4256
|
* 用token换取新accessCode并跳转到指定URL
|
|
4236
|
-
* @param {string} redirectUrl -
|
|
4257
|
+
* @param {string} redirectUrl - 目标跳转地址(支持带query/hash参数)
|
|
4237
4258
|
* @param {string} target - 当前页面:_self、新页面打开:_blank,默认当前页_self
|
|
4238
4259
|
* @returns {Promise<Object>} 接口返回结果
|
|
4239
4260
|
*/
|
|
4240
4261
|
async toUrl(redirectUrl, target = '_self') {
|
|
4262
|
+
// 1. 前置校验:初始化状态、参数合法性
|
|
4241
4263
|
if (!config) {
|
|
4242
4264
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4243
4265
|
}
|
|
@@ -4246,35 +4268,43 @@ function createSSO() {
|
|
|
4246
4268
|
return { code: -104, msg: '请提供跳转地址', success: false };
|
|
4247
4269
|
}
|
|
4248
4270
|
|
|
4249
|
-
//
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4271
|
+
// ========== 新增核心逻辑:判断当前URL是否包含platType=screen ==========
|
|
4272
|
+
// 优先级最高:只要当前地址有platType=screen,强制用_self
|
|
4273
|
+
const isPlatTypeScreen = isBrowser() && getQueryParam('platType') === 'screen';
|
|
4274
|
+
|
|
4275
|
+
// 2. 处理target参数:platType=screen > iOS > 传入的target
|
|
4276
|
+
const finalTarget = isPlatTypeScreen
|
|
4277
|
+
? '_self' // platType=screen时强制_self
|
|
4278
|
+
: (isIOS() ? '_self' : target); // 否则沿用原iOS判断逻辑
|
|
4279
|
+
|
|
4280
|
+
if (!['_self', '_blank'].includes(finalTarget)) {
|
|
4256
4281
|
return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
|
|
4257
4282
|
}
|
|
4258
4283
|
|
|
4284
|
+
// 3. 工具函数:统一构建登录跳转URL(避免重复代码,确保参数完整编码)
|
|
4285
|
+
const buildLoginUrl = (redirectUrl) => {
|
|
4286
|
+
if (!config.logOutUrl) return '';
|
|
4287
|
+
// 关键:encodeURIComponent 会完整编码redirectUrl的所有部分(query/hash),避免参数丢失
|
|
4288
|
+
const encodedRedirectUri = encodeURIComponent(redirectUrl);
|
|
4289
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4290
|
+
};
|
|
4291
|
+
|
|
4292
|
+
// 4. 校验refreshCodeApi配置
|
|
4259
4293
|
if (!config.refreshCodeApi) {
|
|
4260
4294
|
return { code: -105, msg: '未配置refreshCodeApi', success: false };
|
|
4261
4295
|
}
|
|
4262
4296
|
|
|
4297
|
+
// 5. 获取token,无token则直接跳登录页
|
|
4263
4298
|
const token = this.getToken();
|
|
4264
4299
|
if (!token) {
|
|
4265
4300
|
if (isBrowser() && config.logOutUrl) {
|
|
4266
|
-
const loginUrl =
|
|
4267
|
-
|
|
4268
|
-
// 根据target决定打开方式
|
|
4269
|
-
if (target === '_blank') {
|
|
4270
|
-
window.open(loginUrl, '_blank');
|
|
4271
|
-
} else {
|
|
4272
|
-
window.location.href = loginUrl;
|
|
4273
|
-
}
|
|
4301
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4302
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4274
4303
|
}
|
|
4275
4304
|
return { code: -106, msg: '未找到有效token', success: false };
|
|
4276
4305
|
}
|
|
4277
4306
|
|
|
4307
|
+
// 6. 有token则尝试换取accessCode并跳转
|
|
4278
4308
|
try {
|
|
4279
4309
|
const result = await request(
|
|
4280
4310
|
config.refreshCodeApi,
|
|
@@ -4286,32 +4316,25 @@ function createSSO() {
|
|
|
4286
4316
|
);
|
|
4287
4317
|
|
|
4288
4318
|
if (result.code === 0 && result.data && isBrowser()) {
|
|
4319
|
+
// 拼接accessCode到目标URL,保留原URL的所有参数/hash
|
|
4289
4320
|
const url = new URL(redirectUrl);
|
|
4290
4321
|
url.searchParams.set(config.accessCodeKey, result.data);
|
|
4291
4322
|
const targetUrl = url.toString();
|
|
4292
|
-
|
|
4293
|
-
// 根据target参数决定跳转方式
|
|
4294
|
-
if (target === '_blank') {
|
|
4295
|
-
window.open(targetUrl, '_blank');
|
|
4296
|
-
} else {
|
|
4297
|
-
window.location.href = targetUrl;
|
|
4298
|
-
}
|
|
4323
|
+
finalTarget === '_blank' ? window.open(targetUrl, '_blank') : window.location.href = targetUrl;
|
|
4299
4324
|
} else {
|
|
4300
|
-
|
|
4301
|
-
if (
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
window.location.href = loginUrl;
|
|
4325
|
+
// 接口返回失败,跳登录页(复用统一的登录URL构建逻辑)
|
|
4326
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4327
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4328
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4305
4329
|
}
|
|
4306
4330
|
}
|
|
4307
4331
|
|
|
4308
4332
|
return result;
|
|
4309
4333
|
} catch (error) {
|
|
4310
|
-
|
|
4311
|
-
if (
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
window.location.href = loginUrl;
|
|
4334
|
+
// 接口异常,跳登录页(复用统一的登录URL构建逻辑)
|
|
4335
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4336
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4337
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4315
4338
|
}
|
|
4316
4339
|
return { code: -107, msg: `跳转失败: ${error.message}`, success: false };
|
|
4317
4340
|
}
|
package/dist/lgsso-sdk.js
CHANGED
|
@@ -4103,7 +4103,7 @@
|
|
|
4103
4103
|
platform.includes('ipad') ||
|
|
4104
4104
|
// 场景2:iPadOS 13+ 伪装Mac(UA含macintosh + 触摸+ 非Mac平台)
|
|
4105
4105
|
(
|
|
4106
|
-
userAgent.includes('macintosh') &&
|
|
4106
|
+
userAgent.includes('macintosh') &&
|
|
4107
4107
|
maxTouchPoints > 0 && // iPad Air 触摸点≥5,Mac几乎为0
|
|
4108
4108
|
!platform.includes('mac') && // 排除真Mac
|
|
4109
4109
|
!window.MSStream
|
|
@@ -4200,17 +4200,33 @@
|
|
|
4200
4200
|
* @returns {Promise<Object>} 接口返回结果
|
|
4201
4201
|
*/
|
|
4202
4202
|
async logout() {
|
|
4203
|
+
// 1. 前置校验:初始化状态
|
|
4203
4204
|
if (!config) {
|
|
4204
4205
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4205
4206
|
}
|
|
4206
4207
|
|
|
4208
|
+
// 2. 工具函数:统一构建登录跳转URL(确保完整编码当前URL的所有参数/hash)
|
|
4209
|
+
const buildLoginUrl = () => {
|
|
4210
|
+
if (!config.logOutUrl || !isBrowser()) return '';
|
|
4211
|
+
// 关键:获取当前完整URL(含query、hash)并完整编码,避免参数丢失
|
|
4212
|
+
const currentFullUrl = window.location.href;
|
|
4213
|
+
const encodedRedirectUri = encodeURIComponent(currentFullUrl);
|
|
4214
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4215
|
+
};
|
|
4216
|
+
|
|
4217
|
+
// 3. 校验logoutApi配置(仅接口调用时需要,跳转登录页不受此影响)
|
|
4207
4218
|
if (!config.logoutApi) {
|
|
4219
|
+
// 无logoutApi时仍清除token并跳转登录页,保证基础退出逻辑
|
|
4220
|
+
this.removeToken();
|
|
4221
|
+
const loginUrl = buildLoginUrl();
|
|
4222
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4208
4223
|
return { code: -102, msg: '未配置logoutApi', success: false };
|
|
4209
4224
|
}
|
|
4210
4225
|
|
|
4211
4226
|
const token = this.getToken();
|
|
4212
4227
|
if (token) {
|
|
4213
4228
|
try {
|
|
4229
|
+
// 调用退出接口
|
|
4214
4230
|
const result = await request(
|
|
4215
4231
|
config.logoutApi,
|
|
4216
4232
|
{
|
|
@@ -4219,31 +4235,37 @@
|
|
|
4219
4235
|
timeout: config.timeout
|
|
4220
4236
|
}
|
|
4221
4237
|
);
|
|
4238
|
+
// 无论接口返回结果如何,都清除token
|
|
4222
4239
|
this.removeToken();
|
|
4223
4240
|
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4241
|
+
// 跳转登录页(携带完整的当前URL)
|
|
4242
|
+
const loginUrl = buildLoginUrl();
|
|
4243
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4227
4244
|
return result;
|
|
4228
4245
|
} catch (error) {
|
|
4246
|
+
// 接口调用失败,仍清除token并跳转登录页
|
|
4247
|
+
this.removeToken();
|
|
4248
|
+
const loginUrl = buildLoginUrl();
|
|
4249
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4229
4250
|
return { code: -103, msg: `退出失败: ${error.message}`, success: false };
|
|
4230
4251
|
}
|
|
4231
4252
|
} else {
|
|
4253
|
+
// 无token时直接清除(兜底)并跳转登录页
|
|
4232
4254
|
this.removeToken();
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
}
|
|
4255
|
+
const loginUrl = buildLoginUrl();
|
|
4256
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
4236
4257
|
return { code: 0, msg: '已成功清除token', success: true };
|
|
4237
4258
|
}
|
|
4238
4259
|
},
|
|
4239
4260
|
|
|
4240
4261
|
/**
|
|
4241
4262
|
* 用token换取新accessCode并跳转到指定URL
|
|
4242
|
-
* @param {string} redirectUrl -
|
|
4263
|
+
* @param {string} redirectUrl - 目标跳转地址(支持带query/hash参数)
|
|
4243
4264
|
* @param {string} target - 当前页面:_self、新页面打开:_blank,默认当前页_self
|
|
4244
4265
|
* @returns {Promise<Object>} 接口返回结果
|
|
4245
4266
|
*/
|
|
4246
4267
|
async toUrl(redirectUrl, target = '_self') {
|
|
4268
|
+
// 1. 前置校验:初始化状态、参数合法性
|
|
4247
4269
|
if (!config) {
|
|
4248
4270
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
4249
4271
|
}
|
|
@@ -4252,35 +4274,43 @@
|
|
|
4252
4274
|
return { code: -104, msg: '请提供跳转地址', success: false };
|
|
4253
4275
|
}
|
|
4254
4276
|
|
|
4255
|
-
//
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4277
|
+
// ========== 新增核心逻辑:判断当前URL是否包含platType=screen ==========
|
|
4278
|
+
// 优先级最高:只要当前地址有platType=screen,强制用_self
|
|
4279
|
+
const isPlatTypeScreen = isBrowser() && getQueryParam('platType') === 'screen';
|
|
4280
|
+
|
|
4281
|
+
// 2. 处理target参数:platType=screen > iOS > 传入的target
|
|
4282
|
+
const finalTarget = isPlatTypeScreen
|
|
4283
|
+
? '_self' // platType=screen时强制_self
|
|
4284
|
+
: (isIOS() ? '_self' : target); // 否则沿用原iOS判断逻辑
|
|
4285
|
+
|
|
4286
|
+
if (!['_self', '_blank'].includes(finalTarget)) {
|
|
4262
4287
|
return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
|
|
4263
4288
|
}
|
|
4264
4289
|
|
|
4290
|
+
// 3. 工具函数:统一构建登录跳转URL(避免重复代码,确保参数完整编码)
|
|
4291
|
+
const buildLoginUrl = (redirectUrl) => {
|
|
4292
|
+
if (!config.logOutUrl) return '';
|
|
4293
|
+
// 关键:encodeURIComponent 会完整编码redirectUrl的所有部分(query/hash),避免参数丢失
|
|
4294
|
+
const encodedRedirectUri = encodeURIComponent(redirectUrl);
|
|
4295
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
4296
|
+
};
|
|
4297
|
+
|
|
4298
|
+
// 4. 校验refreshCodeApi配置
|
|
4265
4299
|
if (!config.refreshCodeApi) {
|
|
4266
4300
|
return { code: -105, msg: '未配置refreshCodeApi', success: false };
|
|
4267
4301
|
}
|
|
4268
4302
|
|
|
4303
|
+
// 5. 获取token,无token则直接跳登录页
|
|
4269
4304
|
const token = this.getToken();
|
|
4270
4305
|
if (!token) {
|
|
4271
4306
|
if (isBrowser() && config.logOutUrl) {
|
|
4272
|
-
const loginUrl =
|
|
4273
|
-
|
|
4274
|
-
// 根据target决定打开方式
|
|
4275
|
-
if (target === '_blank') {
|
|
4276
|
-
window.open(loginUrl, '_blank');
|
|
4277
|
-
} else {
|
|
4278
|
-
window.location.href = loginUrl;
|
|
4279
|
-
}
|
|
4307
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4308
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4280
4309
|
}
|
|
4281
4310
|
return { code: -106, msg: '未找到有效token', success: false };
|
|
4282
4311
|
}
|
|
4283
4312
|
|
|
4313
|
+
// 6. 有token则尝试换取accessCode并跳转
|
|
4284
4314
|
try {
|
|
4285
4315
|
const result = await request(
|
|
4286
4316
|
config.refreshCodeApi,
|
|
@@ -4292,32 +4322,25 @@
|
|
|
4292
4322
|
);
|
|
4293
4323
|
|
|
4294
4324
|
if (result.code === 0 && result.data && isBrowser()) {
|
|
4325
|
+
// 拼接accessCode到目标URL,保留原URL的所有参数/hash
|
|
4295
4326
|
const url = new URL(redirectUrl);
|
|
4296
4327
|
url.searchParams.set(config.accessCodeKey, result.data);
|
|
4297
4328
|
const targetUrl = url.toString();
|
|
4298
|
-
|
|
4299
|
-
// 根据target参数决定跳转方式
|
|
4300
|
-
if (target === '_blank') {
|
|
4301
|
-
window.open(targetUrl, '_blank');
|
|
4302
|
-
} else {
|
|
4303
|
-
window.location.href = targetUrl;
|
|
4304
|
-
}
|
|
4329
|
+
finalTarget === '_blank' ? window.open(targetUrl, '_blank') : window.location.href = targetUrl;
|
|
4305
4330
|
} else {
|
|
4306
|
-
|
|
4307
|
-
if (
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
window.location.href = loginUrl;
|
|
4331
|
+
// 接口返回失败,跳登录页(复用统一的登录URL构建逻辑)
|
|
4332
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4333
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4334
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4311
4335
|
}
|
|
4312
4336
|
}
|
|
4313
4337
|
|
|
4314
4338
|
return result;
|
|
4315
4339
|
} catch (error) {
|
|
4316
|
-
|
|
4317
|
-
if (
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
window.location.href = loginUrl;
|
|
4340
|
+
// 接口异常,跳登录页(复用统一的登录URL构建逻辑)
|
|
4341
|
+
if (isBrowser() && config.logOutUrl) {
|
|
4342
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
4343
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
4321
4344
|
}
|
|
4322
4345
|
return { code: -107, msg: `跳转失败: ${error.message}`, success: false };
|
|
4323
4346
|
}
|
package/dist/lgsso-sdk.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).lgsso={})}(this,function(e){"use strict";function t(){return"undefined"!=typeof window&&"undefined"!=typeof document}function n(){return t()?window.location.href:""}function r(e,t){return function(){return e.apply(t,arguments)}}const{toString:o}=Object.prototype,{getPrototypeOf:s}=Object,{iterator:i,toStringTag:a}=Symbol,c=(u=Object.create(null),e=>{const t=o.call(e);return u[t]||(u[t]=t.slice(8,-1).toLowerCase())});var u;const l=e=>(e=e.toLowerCase(),t=>c(t)===e),d=e=>t=>typeof t===e,{isArray:f}=Array,h=d("undefined");function p(e){return null!==e&&!h(e)&&null!==e.constructor&&!h(e.constructor)&&y(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const m=l("ArrayBuffer");const g=d("string"),y=d("function"),w=d("number"),b=e=>null!==e&&"object"==typeof e,E=e=>{if("object"!==c(e))return!1;const t=s(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||a in e||i in e)},O=l("Date"),R=l("File"),S=l("Blob"),T=l("FileList"),A=l("URLSearchParams"),[C,v,P,k]=["ReadableStream","Request","Response","Headers"].map(l);function U(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),f(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(p(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(r=0;r<s;r++)i=o[r],t.call(null,e[i],i,e)}}function x(e,t){if(p(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const _="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,j=e=>!h(e)&&e!==_;const N=(L="undefined"!=typeof Uint8Array&&s(Uint8Array),e=>L&&e instanceof L);var L;const F=l("HTMLFormElement"),B=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),D=l("RegExp"),K=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};U(n,(n,o)=>{let s;!1!==(s=t(n,o,e))&&(r[o]=s||n)}),Object.defineProperties(e,r)};const q=l("AsyncFunction"),I=(M="function"==typeof setImmediate,$=y(_.postMessage),M?setImmediate:$?(z=`axios@${Math.random()}`,H=[],_.addEventListener("message",({source:e,data:t})=>{e===_&&t===z&&H.length&&H.shift()()},!1),e=>{H.push(e),_.postMessage(z,"*")}):e=>setTimeout(e));var M,$,z,H;const J="undefined"!=typeof queueMicrotask?queueMicrotask.bind(_):"undefined"!=typeof process&&process.nextTick||I;var W={isArray:f,isArrayBuffer:m,isBuffer:p,isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||y(e.append)&&("formdata"===(t=c(e))||"object"===t&&y(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&m(e.buffer),t},isString:g,isNumber:w,isBoolean:e=>!0===e||!1===e,isObject:b,isPlainObject:E,isEmptyObject:e=>{if(!b(e)||p(e))return!1;try{return 0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype}catch(e){return!1}},isReadableStream:C,isRequest:v,isResponse:P,isHeaders:k,isUndefined:h,isDate:O,isFile:R,isBlob:S,isRegExp:D,isFunction:y,isStream:e=>b(e)&&y(e.pipe),isURLSearchParams:A,isTypedArray:N,isFileList:T,forEach:U,merge:function e(){const{caseless:t}=j(this)&&this||{},n={},r=(r,o)=>{const s=t&&x(n,o)||o;E(n[s])&&E(r)?n[s]=e(n[s],r):E(r)?n[s]=e({},r):f(r)?n[s]=r.slice():n[s]=r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&U(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:o}={})=>(U(t,(t,o)=>{n&&y(t)?e[o]=r(t,n):e[o]=t},{allOwnKeys:o}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,i,a;const c={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),i=o.length;i-- >0;)a=o[i],r&&!r(a,e,t)||c[a]||(t[a]=e[a],c[a]=!0);e=!1!==n&&s(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:c,kindOfTest:l,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(f(e))return e;let t=e.length;if(!w(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[i]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:F,hasOwnProperty:B,hasOwnProp:B,reduceDescriptors:K,freezeMethods:e=>{K(e,(t,n)=>{if(y(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const r=e[n];y(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))})},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach(e=>{n[e]=!0})};return f(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(e,t,n){return t.toUpperCase()+n}),noop:()=>{},toFiniteNumber:(e,t)=>null!=e&&Number.isFinite(e=+e)?e:t,findKey:x,global:_,isContextDefined:j,isSpecCompliantForm:function(e){return!!(e&&y(e.append)&&"FormData"===e[a]&&e[i])},toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(b(e)){if(t.indexOf(e)>=0)return;if(p(e))return e;if(!("toJSON"in e)){t[r]=e;const o=f(e)?[]:{};return U(e,(e,t)=>{const s=n(e,r+1);!h(s)&&(o[t]=s)}),t[r]=void 0,o}}return e};return n(e,0)},isAsyncFn:q,isThenable:e=>e&&(b(e)||y(e))&&y(e.then)&&y(e.catch),setImmediate:I,asap:J,isIterable:e=>null!=e&&y(e[i])};function V(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}W.inherits(V,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:W.toJSONObject(this.config),code:this.code,status:this.status}}});const G=V.prototype,X={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{X[e]={value:e}}),Object.defineProperties(V,X),Object.defineProperty(G,"isAxiosError",{value:!0}),V.from=(e,t,n,r,o,s)=>{const i=Object.create(G);return W.toFlatObject(e,i,function(e){return e!==Error.prototype},e=>"isAxiosError"!==e),V.call(i,e.message,t,n,r,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};function Q(e){return W.isPlainObject(e)||W.isArray(e)}function Z(e){return W.endsWith(e,"[]")?e.slice(0,-2):e}function Y(e,t,n){return e?e.concat(t).map(function(e,t){return e=Z(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}const ee=W.toFlatObject(W,{},null,function(e){return/^is[A-Z]/.test(e)});function te(e,t,n){if(!W.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=W.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!W.isUndefined(t[e])})).metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&W.isSpecCompliantForm(t);if(!W.isFunction(o))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(W.isDate(e))return e.toISOString();if(W.isBoolean(e))return e.toString();if(!a&&W.isBlob(e))throw new V("Blob is not supported. Use a Buffer instead.");return W.isArrayBuffer(e)||W.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(W.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(W.isArray(e)&&function(e){return W.isArray(e)&&!e.some(Q)}(e)||(W.isFileList(e)||W.endsWith(n,"[]"))&&(a=W.toArray(e)))return n=Z(n),a.forEach(function(e,r){!W.isUndefined(e)&&null!==e&&t.append(!0===i?Y([n],r,s):null===i?n:n+"[]",c(e))}),!1;return!!Q(e)||(t.append(Y(o,n,s),c(e)),!1)}const l=[],d=Object.assign(ee,{defaultVisitor:u,convertValue:c,isVisitable:Q});if(!W.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!W.isUndefined(n)){if(-1!==l.indexOf(n))throw Error("Circular reference detected in "+r.join("."));l.push(n),W.forEach(n,function(n,s){!0===(!(W.isUndefined(n)||null===n)&&o.call(t,n,W.isString(s)?s.trim():s,r,d))&&e(n,r?r.concat(s):[s])}),l.pop()}}(e),t}function ne(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(e){return t[e]})}function re(e,t){this._pairs=[],e&&te(e,this,t)}const oe=re.prototype;function se(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function ie(e,t,n){if(!t)return e;const r=n&&n.encode||se;W.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(s=o?o(t,n):W.isURLSearchParams(t)?t.toString():new re(t,n).toString(r),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}oe.append=function(e,t){this._pairs.push([e,t])},oe.toString=function(e){const t=e?function(t){return e.call(this,t,ne)}:ne;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var ae=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){W.forEach(this.handlers,function(t){null!==t&&e(t)})}},ce={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ue={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:re,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const le="undefined"!=typeof window&&"undefined"!=typeof document,de="object"==typeof navigator&&navigator||void 0,fe=le&&(!de||["ReactNative","NativeScript","NS"].indexOf(de.product)<0),he="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,pe=le&&window.location.href||"http://localhost";var me={...Object.freeze({__proto__:null,hasBrowserEnv:le,hasStandardBrowserEnv:fe,hasStandardBrowserWebWorkerEnv:he,navigator:de,origin:pe}),...ue};function ge(e){function t(e,n,r,o){let s=e[o++];if("__proto__"===s)return!0;const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&W.isArray(r)?r.length:s,a)return W.hasOwnProp(r,s)?r[s]=[r[s],n]:r[s]=n,!i;r[s]&&W.isObject(r[s])||(r[s]=[]);return t(e,n,r[s],o)&&W.isArray(r[s])&&(r[s]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}(r[s])),!i}if(W.isFormData(e)&&W.isFunction(e.entries)){const n={};return W.forEachEntry(e,(e,r)=>{t(function(e){return W.matchAll(/\w+|\[(\w*)]/g,e).map(e=>"[]"===e[0]?"":e[1]||e[0])}(e),r,n,0)}),n}return null}const ye={transitional:ce,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=W.isObject(e);o&&W.isHTMLForm(e)&&(e=new FormData(e));if(W.isFormData(e))return r?JSON.stringify(ge(e)):e;if(W.isArrayBuffer(e)||W.isBuffer(e)||W.isStream(e)||W.isFile(e)||W.isBlob(e)||W.isReadableStream(e))return e;if(W.isArrayBufferView(e))return e.buffer;if(W.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return te(e,new me.classes.URLSearchParams,{visitor:function(e,t,n,r){return me.isNode&&W.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)},...t})}(e,this.formSerializer).toString();if((s=W.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return te(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(W.isString(e))try{return(t||JSON.parse)(e),W.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||ye.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(W.isResponse(e)||W.isReadableStream(e))return e;if(e&&W.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw V.from(e,V.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:me.classes.FormData,Blob:me.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};W.forEach(["delete","get","head","post","put","patch"],e=>{ye.headers[e]={}});var we=ye;const be=W.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const Ee=Symbol("internals");function Oe(e){return e&&String(e).trim().toLowerCase()}function Re(e){return!1===e||null==e?e:W.isArray(e)?e.map(Re):String(e)}function Se(e,t,n,r,o){return W.isFunction(r)?r.call(this,t,n):(o&&(t=n),W.isString(t)?W.isString(r)?-1!==t.indexOf(r):W.isRegExp(r)?r.test(t):void 0:void 0)}class Te{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=Oe(t);if(!o)throw new Error("header name must be a non-empty string");const s=W.findKey(r,o);(!s||void 0===r[s]||!0===n||void 0===n&&!1!==r[s])&&(r[s||t]=Re(e))}const s=(e,t)=>W.forEach(e,(e,n)=>o(e,n,t));if(W.isPlainObject(e)||e instanceof this.constructor)s(e,t);else if(W.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim()))s((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach(function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim(),!n||t[n]&&be[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t})(e),t);else if(W.isObject(e)&&W.isIterable(e)){let n,r,o={};for(const t of e){if(!W.isArray(t))throw TypeError("Object iterator must return a key-value pair");o[r=t[0]]=(n=o[r])?W.isArray(n)?[...n,t[1]]:[n,t[1]]:t[1]}s(o,t)}else null!=e&&o(t,e,n);return this}get(e,t){if(e=Oe(e)){const n=W.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(W.isFunction(t))return t.call(this,e,n);if(W.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=Oe(e)){const n=W.findKey(this,e);return!(!n||void 0===this[n]||t&&!Se(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=Oe(e)){const o=W.findKey(n,e);!o||t&&!Se(0,n[o],o,t)||(delete n[o],r=!0)}}return W.isArray(e)?e.forEach(o):o(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const o=t[n];e&&!Se(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return W.forEach(this,(r,o)=>{const s=W.findKey(n,o);if(s)return t[s]=Re(r),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,n)=>t.toUpperCase()+n)}(o):String(o).trim();i!==o&&delete t[o],t[i]=Re(r),n[i]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return W.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&W.isArray(n)?n.join(", "):n)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join("\n")}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[Ee]=this[Ee]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=Oe(e);t[r]||(!function(e,t){const n=W.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return W.isArray(e)?e.forEach(r):r(e),this}}Te.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),W.reduceDescriptors(Te.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),W.freezeMethods(Te);var Ae=Te;function Ce(e,t){const n=this||we,r=t||n,o=Ae.from(r.headers);let s=r.data;return W.forEach(e,function(e){s=e.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ve(e){return!(!e||!e.__CANCEL__)}function Pe(e,t,n){V.call(this,null==e?"canceled":e,V.ERR_CANCELED,t,n),this.name="CanceledError"}function ke(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new V("Request failed with status code "+n.status,[V.ERR_BAD_REQUEST,V.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}W.inherits(Pe,V,{__CANCEL__:!0});const Ue=(e,t,n=3)=>{let r=0;const o=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),u=r[i];o||(o=c),n[s]=a,r[s]=c;let l=i,d=0;for(;l!==s;)d+=n[l++],l%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const f=u&&c-u;return f?Math.round(1e3*d/f):void 0}}(50,250);return function(e,t){let n,r,o=0,s=1e3/t;const i=(t,s=Date.now())=>{o=s,n=null,r&&(clearTimeout(r),r=null),e(...t)};return[(...e)=>{const t=Date.now(),a=t-o;a>=s?i(e,t):(n=e,r||(r=setTimeout(()=>{r=null,i(n)},s-a)))},()=>n&&i(n)]}(n=>{const s=n.loaded,i=n.lengthComputable?n.total:void 0,a=s-r,c=o(a);r=s;e({loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:n,lengthComputable:null!=i,[t?"download":"upload"]:!0})},n)},xe=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},_e=e=>(...t)=>W.asap(()=>e(...t));var je=me.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,me.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(me.origin),me.navigator&&/(msie|trident)/i.test(me.navigator.userAgent)):()=>!0,Ne=me.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];W.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),W.isString(r)&&i.push("path="+r),W.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function Le(e,t,n){let r=!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);return e&&(r||0==n)?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const Fe=e=>e instanceof Ae?{...e}:e;function Be(e,t){t=t||{};const n={};function r(e,t,n,r){return W.isPlainObject(e)&&W.isPlainObject(t)?W.merge.call({caseless:r},e,t):W.isPlainObject(t)?W.merge({},t):W.isArray(t)?t.slice():t}function o(e,t,n,o){return W.isUndefined(t)?W.isUndefined(e)?void 0:r(void 0,e,0,o):r(e,t,0,o)}function s(e,t){if(!W.isUndefined(t))return r(void 0,t)}function i(e,t){return W.isUndefined(t)?W.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,s){return s in t?r(n,o):s in e?r(void 0,n):void 0}const c={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(e,t,n)=>o(Fe(e),Fe(t),0,!0)};return W.forEach(Object.keys({...e,...t}),function(r){const s=c[r]||o,i=s(e[r],t[r],r);W.isUndefined(i)&&s!==a||(n[r]=i)}),n}var De=e=>{const t=Be({},e);let n,{data:r,withXSRFToken:o,xsrfHeaderName:s,xsrfCookieName:i,headers:a,auth:c}=t;if(t.headers=a=Ae.from(a),t.url=ie(Le(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&a.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),W.isFormData(r))if(me.hasStandardBrowserEnv||me.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if(!1!==(n=a.getContentType())){const[e,...t]=n?n.split(";").map(e=>e.trim()).filter(Boolean):[];a.setContentType([e||"multipart/form-data",...t].join("; "))}if(me.hasStandardBrowserEnv&&(o&&W.isFunction(o)&&(o=o(t)),o||!1!==o&&je(t.url))){const e=s&&i&&Ne.read(i);e&&a.set(s,e)}return t};var Ke="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=De(e);let o=r.data;const s=Ae.from(r.headers).normalize();let i,a,c,u,l,{responseType:d,onUploadProgress:f,onDownloadProgress:h}=r;function p(){u&&u(),l&&l(),r.cancelToken&&r.cancelToken.unsubscribe(i),r.signal&&r.signal.removeEventListener("abort",i)}let m=new XMLHttpRequest;function g(){if(!m)return;const r=Ae.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());ke(function(e){t(e),p()},function(e){n(e),p()},{data:d&&"text"!==d&&"json"!==d?m.response:m.responseText,status:m.status,statusText:m.statusText,headers:r,config:e,request:m}),m=null}m.open(r.method.toUpperCase(),r.url,!0),m.timeout=r.timeout,"onloadend"in m?m.onloadend=g:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&0===m.responseURL.indexOf("file:"))&&setTimeout(g)},m.onabort=function(){m&&(n(new V("Request aborted",V.ECONNABORTED,e,m)),m=null)},m.onerror=function(){n(new V("Network Error",V.ERR_NETWORK,e,m)),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const o=r.transitional||ce;r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new V(t,o.clarifyTimeoutError?V.ETIMEDOUT:V.ECONNABORTED,e,m)),m=null},void 0===o&&s.setContentType(null),"setRequestHeader"in m&&W.forEach(s.toJSON(),function(e,t){m.setRequestHeader(t,e)}),W.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),d&&"json"!==d&&(m.responseType=r.responseType),h&&([c,l]=Ue(h,!0),m.addEventListener("progress",c)),f&&m.upload&&([a,u]=Ue(f),m.upload.addEventListener("progress",a),m.upload.addEventListener("loadend",u)),(r.cancelToken||r.signal)&&(i=t=>{m&&(n(!t||t.type?new Pe(null,e,m):t),m.abort(),m=null)},r.cancelToken&&r.cancelToken.subscribe(i),r.signal&&(r.signal.aborted?i():r.signal.addEventListener("abort",i)));const y=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(r.url);y&&-1===me.protocols.indexOf(y)?n(new V("Unsupported protocol "+y+":",V.ERR_BAD_REQUEST,e)):m.send(o||null)})};var qe=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let n,r=new AbortController;const o=function(e){if(!n){n=!0,i();const t=e instanceof Error?e:this.reason;r.abort(t instanceof V?t:new Pe(t instanceof Error?t.message:t))}};let s=t&&setTimeout(()=>{s=null,o(new V(`timeout ${t} of ms exceeded`,V.ETIMEDOUT))},t);const i=()=>{e&&(s&&clearTimeout(s),s=null,e.forEach(e=>{e.unsubscribe?e.unsubscribe(o):e.removeEventListener("abort",o)}),e=null)};e.forEach(e=>e.addEventListener("abort",o));const{signal:a}=r;return a.unsubscribe=()=>W.asap(i),a}};const Ie=function*(e,t){let n=e.byteLength;if(!t||n<t)return void(yield e);let r,o=0;for(;o<n;)r=o+t,yield e.slice(o,r),o=r},Me=async function*(e){if(e[Symbol.asyncIterator])return void(yield*e);const t=e.getReader();try{for(;;){const{done:e,value:n}=await t.read();if(e)break;yield n}}finally{await t.cancel()}},$e=(e,t,n,r)=>{const o=async function*(e,t){for await(const n of Me(e))yield*Ie(n,t)}(e,t);let s,i=0,a=e=>{s||(s=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await o.next();if(t)return a(),void e.close();let s=r.byteLength;if(n){let e=i+=s;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw a(e),e}},cancel:e=>(a(e),o.return())},{highWaterMark:2})},ze="function"==typeof fetch&&"function"==typeof Request&&"function"==typeof Response,He=ze&&"function"==typeof ReadableStream,Je=ze&&("function"==typeof TextEncoder?(We=new TextEncoder,e=>We.encode(e)):async e=>new Uint8Array(await new Response(e).arrayBuffer()));var We;const Ve=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},Ge=He&&Ve(()=>{let e=!1;const t=new Request(me.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Xe=He&&Ve(()=>W.isReadableStream(new Response("").body)),Qe={stream:Xe&&(e=>e.body)};var Ze;ze&&(Ze=new Response,["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!Qe[e]&&(Qe[e]=W.isFunction(Ze[e])?t=>t[e]():(t,n)=>{throw new V(`Response type '${e}' is not supported`,V.ERR_NOT_SUPPORT,n)})}));const Ye=async(e,t)=>{const n=W.toFiniteNumber(e.getContentLength());return null==n?(async e=>{if(null==e)return 0;if(W.isBlob(e))return e.size;if(W.isSpecCompliantForm(e)){const t=new Request(me.origin,{method:"POST",body:e});return(await t.arrayBuffer()).byteLength}return W.isArrayBufferView(e)||W.isArrayBuffer(e)?e.byteLength:(W.isURLSearchParams(e)&&(e+=""),W.isString(e)?(await Je(e)).byteLength:void 0)})(t):n};var et=ze&&(async e=>{let{url:t,method:n,data:r,signal:o,cancelToken:s,timeout:i,onDownloadProgress:a,onUploadProgress:c,responseType:u,headers:l,withCredentials:d="same-origin",fetchOptions:f}=De(e);u=u?(u+"").toLowerCase():"text";let h,p=qe([o,s&&s.toAbortSignal()],i);const m=p&&p.unsubscribe&&(()=>{p.unsubscribe()});let g;try{if(c&&Ge&&"get"!==n&&"head"!==n&&0!==(g=await Ye(l,r))){let e,n=new Request(t,{method:"POST",body:r,duplex:"half"});if(W.isFormData(r)&&(e=n.headers.get("content-type"))&&l.setContentType(e),n.body){const[e,t]=xe(g,Ue(_e(c)));r=$e(n.body,65536,e,t)}}W.isString(d)||(d=d?"include":"omit");const o="credentials"in Request.prototype;h=new Request(t,{...f,signal:p,method:n.toUpperCase(),headers:l.normalize().toJSON(),body:r,duplex:"half",credentials:o?d:void 0});let s=await fetch(h,f);const i=Xe&&("stream"===u||"response"===u);if(Xe&&(a||i&&m)){const e={};["status","statusText","headers"].forEach(t=>{e[t]=s[t]});const t=W.toFiniteNumber(s.headers.get("content-length")),[n,r]=a&&xe(t,Ue(_e(a),!0))||[];s=new Response($e(s.body,65536,n,()=>{r&&r(),m&&m()}),e)}u=u||"text";let y=await Qe[W.findKey(Qe,u)||"text"](s,e);return!i&&m&&m(),await new Promise((t,n)=>{ke(t,n,{data:y,headers:Ae.from(s.headers),status:s.status,statusText:s.statusText,config:e,request:h})})}catch(t){if(m&&m(),t&&"TypeError"===t.name&&/Load failed|fetch/i.test(t.message))throw Object.assign(new V("Network Error",V.ERR_NETWORK,e,h),{cause:t.cause||t});throw V.from(t,t&&t.code,e,h)}});const tt={http:null,xhr:Ke,fetch:et};W.forEach(tt,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}});const nt=e=>`- ${e}`,rt=e=>W.isFunction(e)||null===e||!1===e;var ot=e=>{e=W.isArray(e)?e:[e];const{length:t}=e;let n,r;const o={};for(let s=0;s<t;s++){let t;if(n=e[s],r=n,!rt(n)&&(r=tt[(t=String(n)).toLowerCase()],void 0===r))throw new V(`Unknown adapter '${t}'`);if(r)break;o[t||"#"+s]=r}if(!r){const e=Object.entries(o).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));throw new V("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(nt).join("\n"):" "+nt(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return r};function st(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Pe(null,e)}function it(e){st(e),e.headers=Ae.from(e.headers),e.data=Ce.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return ot(e.adapter||we.adapter)(e).then(function(t){return st(e),t.data=Ce.call(e,e.transformResponse,t),t.headers=Ae.from(t.headers),t},function(t){return ve(t)||(st(e),t&&t.response&&(t.response.data=Ce.call(e,e.transformResponse,t.response),t.response.headers=Ae.from(t.response.headers))),Promise.reject(t)})}const at="1.11.0",ct={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ct[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const ut={};ct.transitional=function(e,t,n){function r(e,t){return"[Axios v"+at+"] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,s)=>{if(!1===e)throw new V(r(o," has been removed"+(t?" in "+t:"")),V.ERR_DEPRECATED);return t&&!ut[o]&&(ut[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,s)}},ct.spelling=function(e){return(t,n)=>(console.warn(`${n} is likely a misspelling of ${e}`),!0)};var lt={assertOptions:function(e,t,n){if("object"!=typeof e)throw new V("options must be an object",V.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const t=e[s],n=void 0===t||i(t,s,e);if(!0!==n)throw new V("option "+s+" must be "+n,V.ERR_BAD_OPTION_VALUE);continue}if(!0!==n)throw new V("Unknown option "+s,V.ERR_BAD_OPTION)}},validators:ct};const dt=lt.validators;class ft{constructor(e){this.defaults=e||{},this.interceptors={request:new ae,response:new ae}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t={};Error.captureStackTrace?Error.captureStackTrace(t):t=new Error;const n=t.stack?t.stack.replace(/^.+\n/,""):"";try{e.stack?n&&!String(e.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+n):e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Be(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&<.assertOptions(n,{silentJSONParsing:dt.transitional(dt.boolean),forcedJSONParsing:dt.transitional(dt.boolean),clarifyTimeoutError:dt.transitional(dt.boolean)},!1),null!=r&&(W.isFunction(r)?t.paramsSerializer={serialize:r}:lt.assertOptions(r,{encode:dt.function,serialize:dt.function},!0)),void 0!==t.allowAbsoluteUrls||(void 0!==this.defaults.allowAbsoluteUrls?t.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:t.allowAbsoluteUrls=!0),lt.assertOptions(t,{baseUrl:dt.spelling("baseURL"),withXsrfToken:dt.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let s=o&&W.merge(o.common,o[t.method]);o&&W.forEach(["delete","get","head","post","put","patch","common"],e=>{delete o[e]}),t.headers=Ae.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach(function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))});const c=[];let u;this.interceptors.response.forEach(function(e){c.push(e.fulfilled,e.rejected)});let l,d=0;if(!a){const e=[it.bind(this),void 0];for(e.unshift(...i),e.push(...c),l=e.length,u=Promise.resolve(t);d<l;)u=u.then(e[d++],e[d++]);return u}l=i.length;let f=t;for(d=0;d<l;){const e=i[d++],t=i[d++];try{f=e(f)}catch(e){t.call(this,e);break}}try{u=it.call(this,f)}catch(e){return Promise.reject(e)}for(d=0,l=c.length;d<l;)u=u.then(c[d++],c[d++]);return u}getUri(e){return ie(Le((e=Be(this.defaults,e)).baseURL,e.url,e.allowAbsoluteUrls),e.params,e.paramsSerializer)}}W.forEach(["delete","get","head","options"],function(e){ft.prototype[e]=function(t,n){return this.request(Be(n||{},{method:e,url:t,data:(n||{}).data}))}}),W.forEach(["post","put","patch"],function(e){function t(t){return function(n,r,o){return this.request(Be(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}ft.prototype[e]=t(),ft.prototype[e+"Form"]=t(!0)});var ht=ft;class pt{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(e){t=e});const n=this;this.promise.then(e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null}),this.promise.then=e=>{let t;const r=new Promise(e=>{n.subscribe(e),t=e}).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e(function(e,r,o){n.reason||(n.reason=new Pe(e,r,o),t(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}toAbortSignal(){const e=new AbortController,t=t=>{e.abort(t)};return this.subscribe(t),e.signal.unsubscribe=()=>this.unsubscribe(t),e.signal}static source(){let e;return{token:new pt(function(t){e=t}),cancel:e}}}var mt=pt;const gt={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(gt).forEach(([e,t])=>{gt[t]=e});var yt=gt;const wt=function e(t){const n=new ht(t),o=r(ht.prototype.request,n);return W.extend(o,ht.prototype,n,{allOwnKeys:!0}),W.extend(o,n,null,{allOwnKeys:!0}),o.create=function(n){return e(Be(t,n))},o}(we);wt.Axios=ht,wt.CanceledError=Pe,wt.CancelToken=mt,wt.isCancel=ve,wt.VERSION=at,wt.toFormData=te,wt.AxiosError=V,wt.Cancel=wt.CanceledError,wt.all=function(e){return Promise.all(e)},wt.spread=function(e){return function(t){return e.apply(null,t)}},wt.isAxiosError=function(e){return W.isObject(e)&&!0===e.isAxiosError},wt.mergeConfig=Be,wt.AxiosHeaders=Ae,wt.formToJSON=e=>ge(W.isHTMLForm(e)?new FormData(e):e),wt.getAdapter=ot,wt.HttpStatusCode=yt,wt.default=wt;var bt=wt;async function Et(e,{method:n="GET",data:r={},headers:o={},timeout:s=5e3}={}){return t()?"fetch"in window&&"AbortController"in window?async function(e,t){const{method:n="GET",data:r={},headers:o={},timeout:s=5e3}=t,i=new AbortController,a=setTimeout(()=>i.abort(),s),c={method:n.toUpperCase(),headers:{"Content-Type":"application/json",...o},signal:i.signal};"GET"!==c.method&&r&&(c.body=JSON.stringify(r));try{const t=await fetch(e,c);if(clearTimeout(a),!t.ok)return{code:t.status,msg:`HTTP请求失败: ${t.statusText}`,success:!1};try{return await t.json()}catch(e){return{code:-201,msg:"响应数据不是有效的JSON格式",success:!1}}}catch(e){return clearTimeout(a),"AbortError"===e.name?{code:-202,msg:`请求超时(${s}ms)`,success:!1}:{code:-203,msg:`网络请求失败: ${e.message}`,success:!1}}}(e,{method:n,data:r,headers:o,timeout:s}):async function(e,t){const{method:n="GET",data:r={},headers:o={},timeout:s=5e3}=t,i={url:e,method:n.toUpperCase(),headers:{"Content-Type":"application/json",...o},timeout:s,["GET"===n.toUpperCase()?"params":"data"]:r};try{return(await bt(i)).data}catch(e){return"ECONNABORTED"===e.code?{code:-202,msg:`请求超时(${s}ms)`,success:!1}:e.response?{code:e.response.status,msg:`HTTP请求失败: ${e.response.statusText}`,success:!1}:{code:-203,msg:`网络请求失败: ${e.message}`,success:!1}}}(e,{method:n,data:r,headers:o,timeout:s}):{code:-200,msg:"request方法只能在浏览器环境使用",success:!1}}const Ot={accessCodeKey:"accessCode",tokenKey:"scm_token",timeout:5e3,headers:{},tokenApi:"",refreshCodeApi:"",logoutApi:"",logOutUrl:"",storage:localStorage,oldPwdKey:"oldPwd",newPwdKey:"newPwd",changePasswordApi:"",sendCaptchaCodeApi:"",typeKey:"type",codeKey:"code"};let Rt=null;function St(){return{async init(e={}){try{Rt=function(e,t){if(!t)return{...e};const n={...e};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);return n}(Ot,e),function(e){if("string"!=typeof e.accessCodeKey||""===e.accessCodeKey.trim())throw new Error("accessCodeKey必须是有效的字符串");if("string"!=typeof e.tokenKey||""===e.tokenKey.trim())throw new Error("tokenKey必须是有效的字符串");if(e.storage&&("function"!=typeof e.storage.setItem||"function"!=typeof e.storage.getItem))throw new Error("storage必须实现setItem和getItem方法")}(Rt);const r=function(e,n){if(!t())return null;const r=n||window.location.href,o=new URL(r);let s=o.searchParams.get(e);if(null!==s)return s;if(o.hash.includes("?")){const t=o.hash.split("?")[1];return new URLSearchParams(t).get(e)}return null}(Rt.accessCodeKey);if(!Rt.tokenApi)return{code:-100,msg:"缺少tokenApi配置",success:!1};if(r){const e=await Et(Rt.tokenApi,{method:"POST",data:{accessCode:r},headers:Rt.headers,timeout:Rt.timeout});return 0===e.code&&e.data&&(Rt.storage.setItem(Rt.tokenKey,e.data),function(e){if(!t())return;const n=new URL(window.location.href);let r,o;if(n.hash.includes("?")){const[t,s]=n.hash.split("?");if(r=new URLSearchParams(s),r.has(e)){r.delete(e);const s=r.toString()?`${t}?${r.toString()}`:t;n.hash=s,o=n.toString()}}else r=new URLSearchParams(n.search),r.has(e)&&(r.delete(e),n.search=r.toString(),o=n.toString());o&&o!==window.location.href&&window.location.replace(o)}(Rt.accessCodeKey)),e}return this.getToken()||t()&&Rt.logOutUrl&&(window.location.href=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(n())}`),{code:0,msg:"初始化成功",success:!0}}catch(e){return{code:-100,msg:`初始化失败: ${e.message}`,success:!1}}},getToken:()=>Rt&&t()?Rt.storage.getItem(Rt.tokenKey):null,removeToken(){Rt&&t()&&Rt.storage.removeItem(Rt.tokenKey)},async logout(){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};if(!Rt.logoutApi)return{code:-102,msg:"未配置logoutApi",success:!1};const e=this.getToken();if(!e)return this.removeToken(),t()&&Rt.logOutUrl&&(window.location.href=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(n())}`),{code:0,msg:"已成功清除token",success:!0};try{const r=await Et(Rt.logoutApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:e},timeout:Rt.timeout});return this.removeToken(),t()&&Rt.logOutUrl&&(window.location.href=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(n())}`),r}catch(e){return{code:-103,msg:`退出失败: ${e.message}`,success:!1}}},async toUrl(e,n="_self"){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};if(!e)return{code:-104,msg:"请提供跳转地址",success:!1};if(function(){const e=navigator.userAgent.toLowerCase(),t=navigator.platform.toLowerCase(),n=navigator.maxTouchPoints||0,r=screen.width/screen.height,o=/iphone|ipod/.test(e)&&!window.MSStream,s=t.includes("ipad")||e.includes("macintosh")&&n>0&&!t.includes("mac")&&!window.MSStream||e.includes("ipados")||n>=5&&!t.includes("android")&&r>.7&&r<1.4;return o||s}()&&(n="_self"),!["_self","_blank"].includes(n))return{code:-108,msg:'target参数必须是"_self"或"_blank"',success:!1};if(!Rt.refreshCodeApi)return{code:-105,msg:"未配置refreshCodeApi",success:!1};const r=this.getToken();if(!r){if(t()&&Rt.logOutUrl){const t=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(e)}`;"_blank"===n?window.open(t,"_blank"):window.location.href=t}return{code:-106,msg:"未找到有效token",success:!1}}try{const o=await Et(Rt.refreshCodeApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:r},timeout:Rt.timeout});if(0===o.code&&o.data&&t()){const t=new URL(e);t.searchParams.set(Rt.accessCodeKey,o.data);const r=t.toString();"_blank"===n?window.open(r,"_blank"):window.location.href=r}else{const t=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(e)}`;"_blank"===n?window.open(t,"_blank"):window.location.href=t}return o}catch(t){const r=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(e)}`;return"_blank"===n?window.open(r,"_blank"):window.location.href=r,{code:-107,msg:`跳转失败: ${t.message}`,success:!1}}},async getAccessCode(){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};const e=this.getToken();return e?Rt.refreshCodeApi?Et(Rt.refreshCodeApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:e},timeout:Rt.timeout}):{code:-105,msg:"未配置refreshCodeApi",success:!1}:{code:-106,msg:"未找到有效token",success:!1}},getConfig:()=>({...Rt}),async changePassword(e={}){if(!e[Rt.oldPwdKey]&&"CAPTCHA"!==e[Rt.typeKey])return{code:-1,msg:"请输入旧密码",success:!1};if(!e[Rt.newPwdKey])return{code:-1,msg:"请输入新密码",success:!1};if("CAPTCHA"===e[Rt.typeKey]&&!e[Rt.codeKey])return{code:-1,msg:"请输入验证码",success:!1};const t=this.getToken();return Et(Rt.changePasswordApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:t},timeout:Rt.timeout,data:{[Rt.oldPwdKey]:e[Rt.oldPwdKey],[Rt.newPwdKey]:e[Rt.newPwdKey],...e}})},async getPhoneCode(){const e=this.getToken();return Et(Rt.sendCaptchaCodeApi,{method:"GET",headers:{...Rt.headers,[Rt.tokenKey]:e},timeout:Rt.timeout})}}}const Tt=St();e.createSSO=St,e.default=Tt,e.lgsso=Tt,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).lgsso={})}(this,function(e){"use strict";function t(){return"undefined"!=typeof window&&"undefined"!=typeof document}function n(e,n){if(!t())return null;const r=n||window.location.href,o=new URL(r);let s=o.searchParams.get(e);if(null!==s)return s;if(o.hash.includes("?")){const t=o.hash.split("?")[1];return new URLSearchParams(t).get(e)}return null}function r(e,t){return function(){return e.apply(t,arguments)}}const{toString:o}=Object.prototype,{getPrototypeOf:s}=Object,{iterator:i,toStringTag:a}=Symbol,c=(u=Object.create(null),e=>{const t=o.call(e);return u[t]||(u[t]=t.slice(8,-1).toLowerCase())});var u;const l=e=>(e=e.toLowerCase(),t=>c(t)===e),d=e=>t=>typeof t===e,{isArray:f}=Array,h=d("undefined");function p(e){return null!==e&&!h(e)&&null!==e.constructor&&!h(e.constructor)&&y(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const m=l("ArrayBuffer");const g=d("string"),y=d("function"),w=d("number"),b=e=>null!==e&&"object"==typeof e,E=e=>{if("object"!==c(e))return!1;const t=s(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||a in e||i in e)},O=l("Date"),R=l("File"),S=l("Blob"),T=l("FileList"),A=l("URLSearchParams"),[v,C,P,k]=["ReadableStream","Request","Response","Headers"].map(l);function U(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),f(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(p(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),s=o.length;let i;for(r=0;r<s;r++)i=o[r],t.call(null,e[i],i,e)}}function x(e,t){if(p(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,_=e=>!h(e)&&e!==j;const N=(L="undefined"!=typeof Uint8Array&&s(Uint8Array),e=>L&&e instanceof L);var L;const F=l("HTMLFormElement"),B=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),D=l("RegExp"),K=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};U(n,(n,o)=>{let s;!1!==(s=t(n,o,e))&&(r[o]=s||n)}),Object.defineProperties(e,r)};const q=l("AsyncFunction"),I=(M="function"==typeof setImmediate,z=y(j.postMessage),M?setImmediate:z?($=`axios@${Math.random()}`,H=[],j.addEventListener("message",({source:e,data:t})=>{e===j&&t===$&&H.length&&H.shift()()},!1),e=>{H.push(e),j.postMessage($,"*")}):e=>setTimeout(e));var M,z,$,H;const J="undefined"!=typeof queueMicrotask?queueMicrotask.bind(j):"undefined"!=typeof process&&process.nextTick||I;var W={isArray:f,isArrayBuffer:m,isBuffer:p,isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||y(e.append)&&("formdata"===(t=c(e))||"object"===t&&y(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&m(e.buffer),t},isString:g,isNumber:w,isBoolean:e=>!0===e||!1===e,isObject:b,isPlainObject:E,isEmptyObject:e=>{if(!b(e)||p(e))return!1;try{return 0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype}catch(e){return!1}},isReadableStream:v,isRequest:C,isResponse:P,isHeaders:k,isUndefined:h,isDate:O,isFile:R,isBlob:S,isRegExp:D,isFunction:y,isStream:e=>b(e)&&y(e.pipe),isURLSearchParams:A,isTypedArray:N,isFileList:T,forEach:U,merge:function e(){const{caseless:t}=_(this)&&this||{},n={},r=(r,o)=>{const s=t&&x(n,o)||o;E(n[s])&&E(r)?n[s]=e(n[s],r):E(r)?n[s]=e({},r):f(r)?n[s]=r.slice():n[s]=r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&U(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:o}={})=>(U(t,(t,o)=>{n&&y(t)?e[o]=r(t,n):e[o]=t},{allOwnKeys:o}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,i,a;const c={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),i=o.length;i-- >0;)a=o[i],r&&!r(a,e,t)||c[a]||(t[a]=e[a],c[a]=!0);e=!1!==n&&s(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:c,kindOfTest:l,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(f(e))return e;let t=e.length;if(!w(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[i]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:F,hasOwnProperty:B,hasOwnProp:B,reduceDescriptors:K,freezeMethods:e=>{K(e,(t,n)=>{if(y(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;const r=e[n];y(r)&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))})},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach(e=>{n[e]=!0})};return f(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(e,t,n){return t.toUpperCase()+n}),noop:()=>{},toFiniteNumber:(e,t)=>null!=e&&Number.isFinite(e=+e)?e:t,findKey:x,global:j,isContextDefined:_,isSpecCompliantForm:function(e){return!!(e&&y(e.append)&&"FormData"===e[a]&&e[i])},toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(b(e)){if(t.indexOf(e)>=0)return;if(p(e))return e;if(!("toJSON"in e)){t[r]=e;const o=f(e)?[]:{};return U(e,(e,t)=>{const s=n(e,r+1);!h(s)&&(o[t]=s)}),t[r]=void 0,o}}return e};return n(e,0)},isAsyncFn:q,isThenable:e=>e&&(b(e)||y(e))&&y(e.then)&&y(e.catch),setImmediate:I,asap:J,isIterable:e=>null!=e&&y(e[i])};function V(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}W.inherits(V,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:W.toJSONObject(this.config),code:this.code,status:this.status}}});const G=V.prototype,X={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{X[e]={value:e}}),Object.defineProperties(V,X),Object.defineProperty(G,"isAxiosError",{value:!0}),V.from=(e,t,n,r,o,s)=>{const i=Object.create(G);return W.toFlatObject(e,i,function(e){return e!==Error.prototype},e=>"isAxiosError"!==e),V.call(i,e.message,t,n,r,o),i.cause=e,i.name=e.name,s&&Object.assign(i,s),i};function Q(e){return W.isPlainObject(e)||W.isArray(e)}function Z(e){return W.endsWith(e,"[]")?e.slice(0,-2):e}function Y(e,t,n){return e?e.concat(t).map(function(e,t){return e=Z(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}const ee=W.toFlatObject(W,{},null,function(e){return/^is[A-Z]/.test(e)});function te(e,t,n){if(!W.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=W.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!W.isUndefined(t[e])})).metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&W.isSpecCompliantForm(t);if(!W.isFunction(o))throw new TypeError("visitor must be a function");function c(e){if(null===e)return"";if(W.isDate(e))return e.toISOString();if(W.isBoolean(e))return e.toString();if(!a&&W.isBlob(e))throw new V("Blob is not supported. Use a Buffer instead.");return W.isArrayBuffer(e)||W.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function u(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(W.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(W.isArray(e)&&function(e){return W.isArray(e)&&!e.some(Q)}(e)||(W.isFileList(e)||W.endsWith(n,"[]"))&&(a=W.toArray(e)))return n=Z(n),a.forEach(function(e,r){!W.isUndefined(e)&&null!==e&&t.append(!0===i?Y([n],r,s):null===i?n:n+"[]",c(e))}),!1;return!!Q(e)||(t.append(Y(o,n,s),c(e)),!1)}const l=[],d=Object.assign(ee,{defaultVisitor:u,convertValue:c,isVisitable:Q});if(!W.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!W.isUndefined(n)){if(-1!==l.indexOf(n))throw Error("Circular reference detected in "+r.join("."));l.push(n),W.forEach(n,function(n,s){!0===(!(W.isUndefined(n)||null===n)&&o.call(t,n,W.isString(s)?s.trim():s,r,d))&&e(n,r?r.concat(s):[s])}),l.pop()}}(e),t}function ne(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(e){return t[e]})}function re(e,t){this._pairs=[],e&&te(e,this,t)}const oe=re.prototype;function se(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function ie(e,t,n){if(!t)return e;const r=n&&n.encode||se;W.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(s=o?o(t,n):W.isURLSearchParams(t)?t.toString():new re(t,n).toString(r),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}oe.append=function(e,t){this._pairs.push([e,t])},oe.toString=function(e){const t=e?function(t){return e.call(this,t,ne)}:ne;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var ae=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){W.forEach(this.handlers,function(t){null!==t&&e(t)})}},ce={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ue={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:re,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const le="undefined"!=typeof window&&"undefined"!=typeof document,de="object"==typeof navigator&&navigator||void 0,fe=le&&(!de||["ReactNative","NativeScript","NS"].indexOf(de.product)<0),he="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,pe=le&&window.location.href||"http://localhost";var me={...Object.freeze({__proto__:null,hasBrowserEnv:le,hasStandardBrowserEnv:fe,hasStandardBrowserWebWorkerEnv:he,navigator:de,origin:pe}),...ue};function ge(e){function t(e,n,r,o){let s=e[o++];if("__proto__"===s)return!0;const i=Number.isFinite(+s),a=o>=e.length;if(s=!s&&W.isArray(r)?r.length:s,a)return W.hasOwnProp(r,s)?r[s]=[r[s],n]:r[s]=n,!i;r[s]&&W.isObject(r[s])||(r[s]=[]);return t(e,n,r[s],o)&&W.isArray(r[s])&&(r[s]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}(r[s])),!i}if(W.isFormData(e)&&W.isFunction(e.entries)){const n={};return W.forEachEntry(e,(e,r)=>{t(function(e){return W.matchAll(/\w+|\[(\w*)]/g,e).map(e=>"[]"===e[0]?"":e[1]||e[0])}(e),r,n,0)}),n}return null}const ye={transitional:ce,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=W.isObject(e);o&&W.isHTMLForm(e)&&(e=new FormData(e));if(W.isFormData(e))return r?JSON.stringify(ge(e)):e;if(W.isArrayBuffer(e)||W.isBuffer(e)||W.isStream(e)||W.isFile(e)||W.isBlob(e)||W.isReadableStream(e))return e;if(W.isArrayBufferView(e))return e.buffer;if(W.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let s;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return te(e,new me.classes.URLSearchParams,{visitor:function(e,t,n,r){return me.isNode&&W.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)},...t})}(e,this.formSerializer).toString();if((s=W.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return te(s?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(W.isString(e))try{return(t||JSON.parse)(e),W.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(n||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||ye.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(W.isResponse(e)||W.isReadableStream(e))return e;if(e&&W.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw V.from(e,V.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:me.classes.FormData,Blob:me.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};W.forEach(["delete","get","head","post","put","patch"],e=>{ye.headers[e]={}});var we=ye;const be=W.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]);const Ee=Symbol("internals");function Oe(e){return e&&String(e).trim().toLowerCase()}function Re(e){return!1===e||null==e?e:W.isArray(e)?e.map(Re):String(e)}function Se(e,t,n,r,o){return W.isFunction(r)?r.call(this,t,n):(o&&(t=n),W.isString(t)?W.isString(r)?-1!==t.indexOf(r):W.isRegExp(r)?r.test(t):void 0:void 0)}class Te{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=Oe(t);if(!o)throw new Error("header name must be a non-empty string");const s=W.findKey(r,o);(!s||void 0===r[s]||!0===n||void 0===n&&!1!==r[s])&&(r[s||t]=Re(e))}const s=(e,t)=>W.forEach(e,(e,n)=>o(e,n,t));if(W.isPlainObject(e)||e instanceof this.constructor)s(e,t);else if(W.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim()))s((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach(function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim(),!n||t[n]&&be[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t})(e),t);else if(W.isObject(e)&&W.isIterable(e)){let n,r,o={};for(const t of e){if(!W.isArray(t))throw TypeError("Object iterator must return a key-value pair");o[r=t[0]]=(n=o[r])?W.isArray(n)?[...n,t[1]]:[n,t[1]]:t[1]}s(o,t)}else null!=e&&o(t,e,n);return this}get(e,t){if(e=Oe(e)){const n=W.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(W.isFunction(t))return t.call(this,e,n);if(W.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=Oe(e)){const n=W.findKey(this,e);return!(!n||void 0===this[n]||t&&!Se(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=Oe(e)){const o=W.findKey(n,e);!o||t&&!Se(0,n[o],o,t)||(delete n[o],r=!0)}}return W.isArray(e)?e.forEach(o):o(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const o=t[n];e&&!Se(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return W.forEach(this,(r,o)=>{const s=W.findKey(n,o);if(s)return t[s]=Re(r),void delete t[o];const i=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,n)=>t.toUpperCase()+n)}(o):String(o).trim();i!==o&&delete t[o],t[i]=Re(r),n[i]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return W.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&W.isArray(n)?n.join(", "):n)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join("\n")}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[Ee]=this[Ee]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=Oe(e);t[r]||(!function(e,t){const n=W.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return W.isArray(e)?e.forEach(r):r(e),this}}Te.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),W.reduceDescriptors(Te.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),W.freezeMethods(Te);var Ae=Te;function ve(e,t){const n=this||we,r=t||n,o=Ae.from(r.headers);let s=r.data;return W.forEach(e,function(e){s=e.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Ce(e){return!(!e||!e.__CANCEL__)}function Pe(e,t,n){V.call(this,null==e?"canceled":e,V.ERR_CANCELED,t,n),this.name="CanceledError"}function ke(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new V("Request failed with status code "+n.status,[V.ERR_BAD_REQUEST,V.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}W.inherits(Pe,V,{__CANCEL__:!0});const Ue=(e,t,n=3)=>{let r=0;const o=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,s=0,i=0;return t=void 0!==t?t:1e3,function(a){const c=Date.now(),u=r[i];o||(o=c),n[s]=a,r[s]=c;let l=i,d=0;for(;l!==s;)d+=n[l++],l%=e;if(s=(s+1)%e,s===i&&(i=(i+1)%e),c-o<t)return;const f=u&&c-u;return f?Math.round(1e3*d/f):void 0}}(50,250);return function(e,t){let n,r,o=0,s=1e3/t;const i=(t,s=Date.now())=>{o=s,n=null,r&&(clearTimeout(r),r=null),e(...t)};return[(...e)=>{const t=Date.now(),a=t-o;a>=s?i(e,t):(n=e,r||(r=setTimeout(()=>{r=null,i(n)},s-a)))},()=>n&&i(n)]}(n=>{const s=n.loaded,i=n.lengthComputable?n.total:void 0,a=s-r,c=o(a);r=s;e({loaded:s,total:i,progress:i?s/i:void 0,bytes:a,rate:c||void 0,estimated:c&&i&&s<=i?(i-s)/c:void 0,event:n,lengthComputable:null!=i,[t?"download":"upload"]:!0})},n)},xe=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},je=e=>(...t)=>W.asap(()=>e(...t));var _e=me.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,me.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(me.origin),me.navigator&&/(msie|trident)/i.test(me.navigator.userAgent)):()=>!0,Ne=me.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];W.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),W.isString(r)&&i.push("path="+r),W.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function Le(e,t,n){let r=!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t);return e&&(r||0==n)?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const Fe=e=>e instanceof Ae?{...e}:e;function Be(e,t){t=t||{};const n={};function r(e,t,n,r){return W.isPlainObject(e)&&W.isPlainObject(t)?W.merge.call({caseless:r},e,t):W.isPlainObject(t)?W.merge({},t):W.isArray(t)?t.slice():t}function o(e,t,n,o){return W.isUndefined(t)?W.isUndefined(e)?void 0:r(void 0,e,0,o):r(e,t,0,o)}function s(e,t){if(!W.isUndefined(t))return r(void 0,t)}function i(e,t){return W.isUndefined(t)?W.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,s){return s in t?r(n,o):s in e?r(void 0,n):void 0}const c={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(e,t,n)=>o(Fe(e),Fe(t),0,!0)};return W.forEach(Object.keys({...e,...t}),function(r){const s=c[r]||o,i=s(e[r],t[r],r);W.isUndefined(i)&&s!==a||(n[r]=i)}),n}var De=e=>{const t=Be({},e);let n,{data:r,withXSRFToken:o,xsrfHeaderName:s,xsrfCookieName:i,headers:a,auth:c}=t;if(t.headers=a=Ae.from(a),t.url=ie(Le(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),c&&a.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):""))),W.isFormData(r))if(me.hasStandardBrowserEnv||me.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if(!1!==(n=a.getContentType())){const[e,...t]=n?n.split(";").map(e=>e.trim()).filter(Boolean):[];a.setContentType([e||"multipart/form-data",...t].join("; "))}if(me.hasStandardBrowserEnv&&(o&&W.isFunction(o)&&(o=o(t)),o||!1!==o&&_e(t.url))){const e=s&&i&&Ne.read(i);e&&a.set(s,e)}return t};var Ke="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=De(e);let o=r.data;const s=Ae.from(r.headers).normalize();let i,a,c,u,l,{responseType:d,onUploadProgress:f,onDownloadProgress:h}=r;function p(){u&&u(),l&&l(),r.cancelToken&&r.cancelToken.unsubscribe(i),r.signal&&r.signal.removeEventListener("abort",i)}let m=new XMLHttpRequest;function g(){if(!m)return;const r=Ae.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());ke(function(e){t(e),p()},function(e){n(e),p()},{data:d&&"text"!==d&&"json"!==d?m.response:m.responseText,status:m.status,statusText:m.statusText,headers:r,config:e,request:m}),m=null}m.open(r.method.toUpperCase(),r.url,!0),m.timeout=r.timeout,"onloadend"in m?m.onloadend=g:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&0===m.responseURL.indexOf("file:"))&&setTimeout(g)},m.onabort=function(){m&&(n(new V("Request aborted",V.ECONNABORTED,e,m)),m=null)},m.onerror=function(){n(new V("Network Error",V.ERR_NETWORK,e,m)),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const o=r.transitional||ce;r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new V(t,o.clarifyTimeoutError?V.ETIMEDOUT:V.ECONNABORTED,e,m)),m=null},void 0===o&&s.setContentType(null),"setRequestHeader"in m&&W.forEach(s.toJSON(),function(e,t){m.setRequestHeader(t,e)}),W.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),d&&"json"!==d&&(m.responseType=r.responseType),h&&([c,l]=Ue(h,!0),m.addEventListener("progress",c)),f&&m.upload&&([a,u]=Ue(f),m.upload.addEventListener("progress",a),m.upload.addEventListener("loadend",u)),(r.cancelToken||r.signal)&&(i=t=>{m&&(n(!t||t.type?new Pe(null,e,m):t),m.abort(),m=null)},r.cancelToken&&r.cancelToken.subscribe(i),r.signal&&(r.signal.aborted?i():r.signal.addEventListener("abort",i)));const y=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(r.url);y&&-1===me.protocols.indexOf(y)?n(new V("Unsupported protocol "+y+":",V.ERR_BAD_REQUEST,e)):m.send(o||null)})};var qe=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let n,r=new AbortController;const o=function(e){if(!n){n=!0,i();const t=e instanceof Error?e:this.reason;r.abort(t instanceof V?t:new Pe(t instanceof Error?t.message:t))}};let s=t&&setTimeout(()=>{s=null,o(new V(`timeout ${t} of ms exceeded`,V.ETIMEDOUT))},t);const i=()=>{e&&(s&&clearTimeout(s),s=null,e.forEach(e=>{e.unsubscribe?e.unsubscribe(o):e.removeEventListener("abort",o)}),e=null)};e.forEach(e=>e.addEventListener("abort",o));const{signal:a}=r;return a.unsubscribe=()=>W.asap(i),a}};const Ie=function*(e,t){let n=e.byteLength;if(!t||n<t)return void(yield e);let r,o=0;for(;o<n;)r=o+t,yield e.slice(o,r),o=r},Me=async function*(e){if(e[Symbol.asyncIterator])return void(yield*e);const t=e.getReader();try{for(;;){const{done:e,value:n}=await t.read();if(e)break;yield n}}finally{await t.cancel()}},ze=(e,t,n,r)=>{const o=async function*(e,t){for await(const n of Me(e))yield*Ie(n,t)}(e,t);let s,i=0,a=e=>{s||(s=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await o.next();if(t)return a(),void e.close();let s=r.byteLength;if(n){let e=i+=s;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw a(e),e}},cancel:e=>(a(e),o.return())},{highWaterMark:2})},$e="function"==typeof fetch&&"function"==typeof Request&&"function"==typeof Response,He=$e&&"function"==typeof ReadableStream,Je=$e&&("function"==typeof TextEncoder?(We=new TextEncoder,e=>We.encode(e)):async e=>new Uint8Array(await new Response(e).arrayBuffer()));var We;const Ve=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},Ge=He&&Ve(()=>{let e=!1;const t=new Request(me.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Xe=He&&Ve(()=>W.isReadableStream(new Response("").body)),Qe={stream:Xe&&(e=>e.body)};var Ze;$e&&(Ze=new Response,["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!Qe[e]&&(Qe[e]=W.isFunction(Ze[e])?t=>t[e]():(t,n)=>{throw new V(`Response type '${e}' is not supported`,V.ERR_NOT_SUPPORT,n)})}));const Ye=async(e,t)=>{const n=W.toFiniteNumber(e.getContentLength());return null==n?(async e=>{if(null==e)return 0;if(W.isBlob(e))return e.size;if(W.isSpecCompliantForm(e)){const t=new Request(me.origin,{method:"POST",body:e});return(await t.arrayBuffer()).byteLength}return W.isArrayBufferView(e)||W.isArrayBuffer(e)?e.byteLength:(W.isURLSearchParams(e)&&(e+=""),W.isString(e)?(await Je(e)).byteLength:void 0)})(t):n};var et=$e&&(async e=>{let{url:t,method:n,data:r,signal:o,cancelToken:s,timeout:i,onDownloadProgress:a,onUploadProgress:c,responseType:u,headers:l,withCredentials:d="same-origin",fetchOptions:f}=De(e);u=u?(u+"").toLowerCase():"text";let h,p=qe([o,s&&s.toAbortSignal()],i);const m=p&&p.unsubscribe&&(()=>{p.unsubscribe()});let g;try{if(c&&Ge&&"get"!==n&&"head"!==n&&0!==(g=await Ye(l,r))){let e,n=new Request(t,{method:"POST",body:r,duplex:"half"});if(W.isFormData(r)&&(e=n.headers.get("content-type"))&&l.setContentType(e),n.body){const[e,t]=xe(g,Ue(je(c)));r=ze(n.body,65536,e,t)}}W.isString(d)||(d=d?"include":"omit");const o="credentials"in Request.prototype;h=new Request(t,{...f,signal:p,method:n.toUpperCase(),headers:l.normalize().toJSON(),body:r,duplex:"half",credentials:o?d:void 0});let s=await fetch(h,f);const i=Xe&&("stream"===u||"response"===u);if(Xe&&(a||i&&m)){const e={};["status","statusText","headers"].forEach(t=>{e[t]=s[t]});const t=W.toFiniteNumber(s.headers.get("content-length")),[n,r]=a&&xe(t,Ue(je(a),!0))||[];s=new Response(ze(s.body,65536,n,()=>{r&&r(),m&&m()}),e)}u=u||"text";let y=await Qe[W.findKey(Qe,u)||"text"](s,e);return!i&&m&&m(),await new Promise((t,n)=>{ke(t,n,{data:y,headers:Ae.from(s.headers),status:s.status,statusText:s.statusText,config:e,request:h})})}catch(t){if(m&&m(),t&&"TypeError"===t.name&&/Load failed|fetch/i.test(t.message))throw Object.assign(new V("Network Error",V.ERR_NETWORK,e,h),{cause:t.cause||t});throw V.from(t,t&&t.code,e,h)}});const tt={http:null,xhr:Ke,fetch:et};W.forEach(tt,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}});const nt=e=>`- ${e}`,rt=e=>W.isFunction(e)||null===e||!1===e;var ot=e=>{e=W.isArray(e)?e:[e];const{length:t}=e;let n,r;const o={};for(let s=0;s<t;s++){let t;if(n=e[s],r=n,!rt(n)&&(r=tt[(t=String(n)).toLowerCase()],void 0===r))throw new V(`Unknown adapter '${t}'`);if(r)break;o[t||"#"+s]=r}if(!r){const e=Object.entries(o).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));throw new V("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(nt).join("\n"):" "+nt(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return r};function st(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Pe(null,e)}function it(e){st(e),e.headers=Ae.from(e.headers),e.data=ve.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1);return ot(e.adapter||we.adapter)(e).then(function(t){return st(e),t.data=ve.call(e,e.transformResponse,t),t.headers=Ae.from(t.headers),t},function(t){return Ce(t)||(st(e),t&&t.response&&(t.response.data=ve.call(e,e.transformResponse,t.response),t.response.headers=Ae.from(t.response.headers))),Promise.reject(t)})}const at="1.11.0",ct={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ct[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const ut={};ct.transitional=function(e,t,n){function r(e,t){return"[Axios v"+at+"] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,s)=>{if(!1===e)throw new V(r(o," has been removed"+(t?" in "+t:"")),V.ERR_DEPRECATED);return t&&!ut[o]&&(ut[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,s)}},ct.spelling=function(e){return(t,n)=>(console.warn(`${n} is likely a misspelling of ${e}`),!0)};var lt={assertOptions:function(e,t,n){if("object"!=typeof e)throw new V("options must be an object",V.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const t=e[s],n=void 0===t||i(t,s,e);if(!0!==n)throw new V("option "+s+" must be "+n,V.ERR_BAD_OPTION_VALUE);continue}if(!0!==n)throw new V("Unknown option "+s,V.ERR_BAD_OPTION)}},validators:ct};const dt=lt.validators;class ft{constructor(e){this.defaults=e||{},this.interceptors={request:new ae,response:new ae}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t={};Error.captureStackTrace?Error.captureStackTrace(t):t=new Error;const n=t.stack?t.stack.replace(/^.+\n/,""):"";try{e.stack?n&&!String(e.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+n):e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=Be(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&<.assertOptions(n,{silentJSONParsing:dt.transitional(dt.boolean),forcedJSONParsing:dt.transitional(dt.boolean),clarifyTimeoutError:dt.transitional(dt.boolean)},!1),null!=r&&(W.isFunction(r)?t.paramsSerializer={serialize:r}:lt.assertOptions(r,{encode:dt.function,serialize:dt.function},!0)),void 0!==t.allowAbsoluteUrls||(void 0!==this.defaults.allowAbsoluteUrls?t.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:t.allowAbsoluteUrls=!0),lt.assertOptions(t,{baseUrl:dt.spelling("baseURL"),withXsrfToken:dt.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let s=o&&W.merge(o.common,o[t.method]);o&&W.forEach(["delete","get","head","post","put","patch","common"],e=>{delete o[e]}),t.headers=Ae.concat(s,o);const i=[];let a=!0;this.interceptors.request.forEach(function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,i.unshift(e.fulfilled,e.rejected))});const c=[];let u;this.interceptors.response.forEach(function(e){c.push(e.fulfilled,e.rejected)});let l,d=0;if(!a){const e=[it.bind(this),void 0];for(e.unshift(...i),e.push(...c),l=e.length,u=Promise.resolve(t);d<l;)u=u.then(e[d++],e[d++]);return u}l=i.length;let f=t;for(d=0;d<l;){const e=i[d++],t=i[d++];try{f=e(f)}catch(e){t.call(this,e);break}}try{u=it.call(this,f)}catch(e){return Promise.reject(e)}for(d=0,l=c.length;d<l;)u=u.then(c[d++],c[d++]);return u}getUri(e){return ie(Le((e=Be(this.defaults,e)).baseURL,e.url,e.allowAbsoluteUrls),e.params,e.paramsSerializer)}}W.forEach(["delete","get","head","options"],function(e){ft.prototype[e]=function(t,n){return this.request(Be(n||{},{method:e,url:t,data:(n||{}).data}))}}),W.forEach(["post","put","patch"],function(e){function t(t){return function(n,r,o){return this.request(Be(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}ft.prototype[e]=t(),ft.prototype[e+"Form"]=t(!0)});var ht=ft;class pt{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(e){t=e});const n=this;this.promise.then(e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null}),this.promise.then=e=>{let t;const r=new Promise(e=>{n.subscribe(e),t=e}).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e(function(e,r,o){n.reason||(n.reason=new Pe(e,r,o),t(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}toAbortSignal(){const e=new AbortController,t=t=>{e.abort(t)};return this.subscribe(t),e.signal.unsubscribe=()=>this.unsubscribe(t),e.signal}static source(){let e;return{token:new pt(function(t){e=t}),cancel:e}}}var mt=pt;const gt={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(gt).forEach(([e,t])=>{gt[t]=e});var yt=gt;const wt=function e(t){const n=new ht(t),o=r(ht.prototype.request,n);return W.extend(o,ht.prototype,n,{allOwnKeys:!0}),W.extend(o,n,null,{allOwnKeys:!0}),o.create=function(n){return e(Be(t,n))},o}(we);wt.Axios=ht,wt.CanceledError=Pe,wt.CancelToken=mt,wt.isCancel=Ce,wt.VERSION=at,wt.toFormData=te,wt.AxiosError=V,wt.Cancel=wt.CanceledError,wt.all=function(e){return Promise.all(e)},wt.spread=function(e){return function(t){return e.apply(null,t)}},wt.isAxiosError=function(e){return W.isObject(e)&&!0===e.isAxiosError},wt.mergeConfig=Be,wt.AxiosHeaders=Ae,wt.formToJSON=e=>ge(W.isHTMLForm(e)?new FormData(e):e),wt.getAdapter=ot,wt.HttpStatusCode=yt,wt.default=wt;var bt=wt;async function Et(e,{method:n="GET",data:r={},headers:o={},timeout:s=5e3}={}){return t()?"fetch"in window&&"AbortController"in window?async function(e,t){const{method:n="GET",data:r={},headers:o={},timeout:s=5e3}=t,i=new AbortController,a=setTimeout(()=>i.abort(),s),c={method:n.toUpperCase(),headers:{"Content-Type":"application/json",...o},signal:i.signal};"GET"!==c.method&&r&&(c.body=JSON.stringify(r));try{const t=await fetch(e,c);if(clearTimeout(a),!t.ok)return{code:t.status,msg:`HTTP请求失败: ${t.statusText}`,success:!1};try{return await t.json()}catch(e){return{code:-201,msg:"响应数据不是有效的JSON格式",success:!1}}}catch(e){return clearTimeout(a),"AbortError"===e.name?{code:-202,msg:`请求超时(${s}ms)`,success:!1}:{code:-203,msg:`网络请求失败: ${e.message}`,success:!1}}}(e,{method:n,data:r,headers:o,timeout:s}):async function(e,t){const{method:n="GET",data:r={},headers:o={},timeout:s=5e3}=t,i={url:e,method:n.toUpperCase(),headers:{"Content-Type":"application/json",...o},timeout:s,["GET"===n.toUpperCase()?"params":"data"]:r};try{return(await bt(i)).data}catch(e){return"ECONNABORTED"===e.code?{code:-202,msg:`请求超时(${s}ms)`,success:!1}:e.response?{code:e.response.status,msg:`HTTP请求失败: ${e.response.statusText}`,success:!1}:{code:-203,msg:`网络请求失败: ${e.message}`,success:!1}}}(e,{method:n,data:r,headers:o,timeout:s}):{code:-200,msg:"request方法只能在浏览器环境使用",success:!1}}const Ot={accessCodeKey:"accessCode",tokenKey:"scm_token",timeout:5e3,headers:{},tokenApi:"",refreshCodeApi:"",logoutApi:"",logOutUrl:"",storage:localStorage,oldPwdKey:"oldPwd",newPwdKey:"newPwd",changePasswordApi:"",sendCaptchaCodeApi:"",typeKey:"type",codeKey:"code"};let Rt=null;function St(){return{async init(e={}){try{Rt=function(e,t){if(!t)return{...e};const n={...e};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);return n}(Ot,e),function(e){if("string"!=typeof e.accessCodeKey||""===e.accessCodeKey.trim())throw new Error("accessCodeKey必须是有效的字符串");if("string"!=typeof e.tokenKey||""===e.tokenKey.trim())throw new Error("tokenKey必须是有效的字符串");if(e.storage&&("function"!=typeof e.storage.setItem||"function"!=typeof e.storage.getItem))throw new Error("storage必须实现setItem和getItem方法")}(Rt);const r=n(Rt.accessCodeKey);if(!Rt.tokenApi)return{code:-100,msg:"缺少tokenApi配置",success:!1};if(r){const e=await Et(Rt.tokenApi,{method:"POST",data:{accessCode:r},headers:Rt.headers,timeout:Rt.timeout});return 0===e.code&&e.data&&(Rt.storage.setItem(Rt.tokenKey,e.data),function(e){if(!t())return;const n=new URL(window.location.href);let r,o;if(n.hash.includes("?")){const[t,s]=n.hash.split("?");if(r=new URLSearchParams(s),r.has(e)){r.delete(e);const s=r.toString()?`${t}?${r.toString()}`:t;n.hash=s,o=n.toString()}}else r=new URLSearchParams(n.search),r.has(e)&&(r.delete(e),n.search=r.toString(),o=n.toString());o&&o!==window.location.href&&window.location.replace(o)}(Rt.accessCodeKey)),e}return this.getToken()||t()&&Rt.logOutUrl&&(window.location.href=`${Rt.logOutUrl}?redirect_uri=${encodeURIComponent(t()?window.location.href:"")}`),{code:0,msg:"初始化成功",success:!0}}catch(e){return{code:-100,msg:`初始化失败: ${e.message}`,success:!1}}},getToken:()=>Rt&&t()?Rt.storage.getItem(Rt.tokenKey):null,removeToken(){Rt&&t()&&Rt.storage.removeItem(Rt.tokenKey)},async logout(){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};const e=()=>{if(!Rt.logOutUrl||!t())return"";const e=window.location.href,n=encodeURIComponent(e);return`${Rt.logOutUrl}?redirect_uri=${n}`};if(!Rt.logoutApi){this.removeToken();const t=e();return t&&(window.location.href=t),{code:-102,msg:"未配置logoutApi",success:!1}}const n=this.getToken();if(!n){this.removeToken();const t=e();return t&&(window.location.href=t),{code:0,msg:"已成功清除token",success:!0}}try{const t=await Et(Rt.logoutApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:n},timeout:Rt.timeout});this.removeToken();const r=e();return r&&(window.location.href=r),t}catch(t){this.removeToken();const n=e();return n&&(window.location.href=n),{code:-103,msg:`退出失败: ${t.message}`,success:!1}}},async toUrl(e,r="_self"){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};if(!e)return{code:-104,msg:"请提供跳转地址",success:!1};const o=t()&&"screen"===n("platType")||function(){const e=navigator.userAgent.toLowerCase(),t=navigator.platform.toLowerCase(),n=navigator.maxTouchPoints||0,r=screen.width/screen.height,o=/iphone|ipod/.test(e)&&!window.MSStream,s=t.includes("ipad")||e.includes("macintosh")&&n>0&&!t.includes("mac")&&!window.MSStream||e.includes("ipados")||n>=5&&!t.includes("android")&&r>.7&&r<1.4;return o||s}()?"_self":r;if(!["_self","_blank"].includes(o))return{code:-108,msg:'target参数必须是"_self"或"_blank"',success:!1};const s=e=>{if(!Rt.logOutUrl)return"";const t=encodeURIComponent(e);return`${Rt.logOutUrl}?redirect_uri=${t}`};if(!Rt.refreshCodeApi)return{code:-105,msg:"未配置refreshCodeApi",success:!1};const i=this.getToken();if(!i){if(t()&&Rt.logOutUrl){const t=s(e);"_blank"===o?window.open(t,"_blank"):window.location.href=t}return{code:-106,msg:"未找到有效token",success:!1}}try{const n=await Et(Rt.refreshCodeApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:i},timeout:Rt.timeout});if(0===n.code&&n.data&&t()){const t=new URL(e);t.searchParams.set(Rt.accessCodeKey,n.data);const r=t.toString();"_blank"===o?window.open(r,"_blank"):window.location.href=r}else if(t()&&Rt.logOutUrl){const t=s(e);"_blank"===o?window.open(t,"_blank"):window.location.href=t}return n}catch(n){if(t()&&Rt.logOutUrl){const t=s(e);"_blank"===o?window.open(t,"_blank"):window.location.href=t}return{code:-107,msg:`跳转失败: ${n.message}`,success:!1}}},async getAccessCode(){if(!Rt)return{code:-101,msg:"请先调用init方法初始化",success:!1};const e=this.getToken();return e?Rt.refreshCodeApi?Et(Rt.refreshCodeApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:e},timeout:Rt.timeout}):{code:-105,msg:"未配置refreshCodeApi",success:!1}:{code:-106,msg:"未找到有效token",success:!1}},getConfig:()=>({...Rt}),async changePassword(e={}){if(!e[Rt.oldPwdKey]&&"CAPTCHA"!==e[Rt.typeKey])return{code:-1,msg:"请输入旧密码",success:!1};if(!e[Rt.newPwdKey])return{code:-1,msg:"请输入新密码",success:!1};if("CAPTCHA"===e[Rt.typeKey]&&!e[Rt.codeKey])return{code:-1,msg:"请输入验证码",success:!1};const t=this.getToken();return Et(Rt.changePasswordApi,{method:"POST",headers:{...Rt.headers,[Rt.tokenKey]:t},timeout:Rt.timeout,data:{[Rt.oldPwdKey]:e[Rt.oldPwdKey],[Rt.newPwdKey]:e[Rt.newPwdKey],...e}})},async getPhoneCode(){const e=this.getToken();return Et(Rt.sendCaptchaCodeApi,{method:"GET",headers:{...Rt.headers,[Rt.tokenKey]:e},timeout:Rt.timeout})}}}const Tt=St();e.createSSO=St,e.default=Tt,e.lgsso=Tt,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
2
|
//# sourceMappingURL=lgsso-sdk.min.js.map
|
package/package.json
CHANGED
package/src/sso.js
CHANGED
|
@@ -62,7 +62,7 @@ function isIOS() {
|
|
|
62
62
|
platform.includes('ipad') ||
|
|
63
63
|
// 场景2:iPadOS 13+ 伪装Mac(UA含macintosh + 触摸+ 非Mac平台)
|
|
64
64
|
(
|
|
65
|
-
userAgent.includes('macintosh') &&
|
|
65
|
+
userAgent.includes('macintosh') &&
|
|
66
66
|
maxTouchPoints > 0 && // iPad Air 触摸点≥5,Mac几乎为0
|
|
67
67
|
!platform.includes('mac') && // 排除真Mac
|
|
68
68
|
!window.MSStream
|
|
@@ -159,17 +159,33 @@ export function createSSO() {
|
|
|
159
159
|
* @returns {Promise<Object>} 接口返回结果
|
|
160
160
|
*/
|
|
161
161
|
async logout() {
|
|
162
|
+
// 1. 前置校验:初始化状态
|
|
162
163
|
if (!config) {
|
|
163
164
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
// 2. 工具函数:统一构建登录跳转URL(确保完整编码当前URL的所有参数/hash)
|
|
168
|
+
const buildLoginUrl = () => {
|
|
169
|
+
if (!config.logOutUrl || !isBrowser()) return '';
|
|
170
|
+
// 关键:获取当前完整URL(含query、hash)并完整编码,避免参数丢失
|
|
171
|
+
const currentFullUrl = window.location.href;
|
|
172
|
+
const encodedRedirectUri = encodeURIComponent(currentFullUrl);
|
|
173
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// 3. 校验logoutApi配置(仅接口调用时需要,跳转登录页不受此影响)
|
|
166
177
|
if (!config.logoutApi) {
|
|
178
|
+
// 无logoutApi时仍清除token并跳转登录页,保证基础退出逻辑
|
|
179
|
+
this.removeToken();
|
|
180
|
+
const loginUrl = buildLoginUrl();
|
|
181
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
167
182
|
return { code: -102, msg: '未配置logoutApi', success: false };
|
|
168
183
|
}
|
|
169
184
|
|
|
170
185
|
const token = this.getToken();
|
|
171
186
|
if (token) {
|
|
172
187
|
try {
|
|
188
|
+
// 调用退出接口
|
|
173
189
|
const result = await request(
|
|
174
190
|
config.logoutApi,
|
|
175
191
|
{
|
|
@@ -178,31 +194,37 @@ export function createSSO() {
|
|
|
178
194
|
timeout: config.timeout
|
|
179
195
|
}
|
|
180
196
|
);
|
|
197
|
+
// 无论接口返回结果如何,都清除token
|
|
181
198
|
this.removeToken();
|
|
182
199
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
200
|
+
// 跳转登录页(携带完整的当前URL)
|
|
201
|
+
const loginUrl = buildLoginUrl();
|
|
202
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
186
203
|
return result;
|
|
187
204
|
} catch (error) {
|
|
205
|
+
// 接口调用失败,仍清除token并跳转登录页
|
|
206
|
+
this.removeToken();
|
|
207
|
+
const loginUrl = buildLoginUrl();
|
|
208
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
188
209
|
return { code: -103, msg: `退出失败: ${error.message}`, success: false };
|
|
189
210
|
}
|
|
190
211
|
} else {
|
|
212
|
+
// 无token时直接清除(兜底)并跳转登录页
|
|
191
213
|
this.removeToken();
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
214
|
+
const loginUrl = buildLoginUrl();
|
|
215
|
+
if (loginUrl) window.location.href = loginUrl;
|
|
195
216
|
return { code: 0, msg: '已成功清除token', success: true };
|
|
196
217
|
}
|
|
197
218
|
},
|
|
198
219
|
|
|
199
220
|
/**
|
|
200
221
|
* 用token换取新accessCode并跳转到指定URL
|
|
201
|
-
* @param {string} redirectUrl -
|
|
222
|
+
* @param {string} redirectUrl - 目标跳转地址(支持带query/hash参数)
|
|
202
223
|
* @param {string} target - 当前页面:_self、新页面打开:_blank,默认当前页_self
|
|
203
224
|
* @returns {Promise<Object>} 接口返回结果
|
|
204
225
|
*/
|
|
205
226
|
async toUrl(redirectUrl, target = '_self') {
|
|
227
|
+
// 1. 前置校验:初始化状态、参数合法性
|
|
206
228
|
if (!config) {
|
|
207
229
|
return { code: -101, msg: '请先调用init方法初始化', success: false };
|
|
208
230
|
}
|
|
@@ -211,35 +233,43 @@ export function createSSO() {
|
|
|
211
233
|
return { code: -104, msg: '请提供跳转地址', success: false };
|
|
212
234
|
}
|
|
213
235
|
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
236
|
+
// ========== 新增核心逻辑:判断当前URL是否包含platType=screen ==========
|
|
237
|
+
// 优先级最高:只要当前地址有platType=screen,强制用_self
|
|
238
|
+
const isPlatTypeScreen = isBrowser() && getQueryParam('platType') === 'screen';
|
|
239
|
+
|
|
240
|
+
// 2. 处理target参数:platType=screen > iOS > 传入的target
|
|
241
|
+
const finalTarget = isPlatTypeScreen
|
|
242
|
+
? '_self' // platType=screen时强制_self
|
|
243
|
+
: (isIOS() ? '_self' : target); // 否则沿用原iOS判断逻辑
|
|
244
|
+
|
|
245
|
+
if (!['_self', '_blank'].includes(finalTarget)) {
|
|
221
246
|
return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
|
|
222
247
|
}
|
|
223
248
|
|
|
249
|
+
// 3. 工具函数:统一构建登录跳转URL(避免重复代码,确保参数完整编码)
|
|
250
|
+
const buildLoginUrl = (redirectUrl) => {
|
|
251
|
+
if (!config.logOutUrl) return '';
|
|
252
|
+
// 关键:encodeURIComponent 会完整编码redirectUrl的所有部分(query/hash),避免参数丢失
|
|
253
|
+
const encodedRedirectUri = encodeURIComponent(redirectUrl);
|
|
254
|
+
return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// 4. 校验refreshCodeApi配置
|
|
224
258
|
if (!config.refreshCodeApi) {
|
|
225
259
|
return { code: -105, msg: '未配置refreshCodeApi', success: false };
|
|
226
260
|
}
|
|
227
261
|
|
|
262
|
+
// 5. 获取token,无token则直接跳登录页
|
|
228
263
|
const token = this.getToken();
|
|
229
264
|
if (!token) {
|
|
230
265
|
if (isBrowser() && config.logOutUrl) {
|
|
231
|
-
const loginUrl =
|
|
232
|
-
|
|
233
|
-
// 根据target决定打开方式
|
|
234
|
-
if (target === '_blank') {
|
|
235
|
-
window.open(loginUrl, '_blank');
|
|
236
|
-
} else {
|
|
237
|
-
window.location.href = loginUrl;
|
|
238
|
-
}
|
|
266
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
267
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
239
268
|
}
|
|
240
269
|
return { code: -106, msg: '未找到有效token', success: false };
|
|
241
270
|
}
|
|
242
271
|
|
|
272
|
+
// 6. 有token则尝试换取accessCode并跳转
|
|
243
273
|
try {
|
|
244
274
|
const result = await request(
|
|
245
275
|
config.refreshCodeApi,
|
|
@@ -251,32 +281,25 @@ export function createSSO() {
|
|
|
251
281
|
);
|
|
252
282
|
|
|
253
283
|
if (result.code === 0 && result.data && isBrowser()) {
|
|
284
|
+
// 拼接accessCode到目标URL,保留原URL的所有参数/hash
|
|
254
285
|
const url = new URL(redirectUrl);
|
|
255
286
|
url.searchParams.set(config.accessCodeKey, result.data);
|
|
256
287
|
const targetUrl = url.toString();
|
|
257
|
-
|
|
258
|
-
// 根据target参数决定跳转方式
|
|
259
|
-
if (target === '_blank') {
|
|
260
|
-
window.open(targetUrl, '_blank');
|
|
261
|
-
} else {
|
|
262
|
-
window.location.href = targetUrl;
|
|
263
|
-
}
|
|
288
|
+
finalTarget === '_blank' ? window.open(targetUrl, '_blank') : window.location.href = targetUrl;
|
|
264
289
|
} else {
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
window.location.href = loginUrl;
|
|
290
|
+
// 接口返回失败,跳登录页(复用统一的登录URL构建逻辑)
|
|
291
|
+
if (isBrowser() && config.logOutUrl) {
|
|
292
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
293
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
270
294
|
}
|
|
271
295
|
}
|
|
272
296
|
|
|
273
297
|
return result;
|
|
274
298
|
} catch (error) {
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
window.location.href = loginUrl;
|
|
299
|
+
// 接口异常,跳登录页(复用统一的登录URL构建逻辑)
|
|
300
|
+
if (isBrowser() && config.logOutUrl) {
|
|
301
|
+
const loginUrl = buildLoginUrl(redirectUrl);
|
|
302
|
+
finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
|
|
280
303
|
}
|
|
281
304
|
return { code: -107, msg: `跳转失败: ${error.message}`, success: false };
|
|
282
305
|
}
|