lgsso-sdk 1.2.6 → 1.2.9

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.
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: Robin LEI
3
3
  * @Date: 2025-08-21 15:09:15
4
- * @LastEditTime: 2025-08-21 15:22:11
5
- * @FilePath: \lg-wms-admind:\业务代码\中联钢信\五服一管\lg-ssosdk\src\utils.js
4
+ * @LastEditTime: 2026-01-23 11:28:26
5
+ * @FilePath: \lims-frontd:\业务代码\中联钢信\五服一管\lg-ssosdk\src\utils.js
6
6
  */
7
7
  /**
8
8
  * 检查是否在浏览器环境
@@ -38,38 +38,58 @@ function getQueryParam(name, url) {
38
38
  }
39
39
 
40
40
  /**
41
- * 移除URL中的指定参数
42
- * @param {string} name - 参数名
41
+ * 移除URL中的指定参数(支持单个或多个)
42
+ * @param {string|string[]} names - 要删除的参数名(单个字符串或字符串数组)
43
43
  */
44
- function removeQueryParam(name) {
44
+ function removeQueryParam(names) {
45
45
  if (!isBrowser()) return;
46
46
 
47
+ // 统一转为数组,兼容单个参数的调用方式
48
+ const paramNames = Array.isArray(names) ? names : [names];
49
+ if (paramNames.length === 0) return; // 无参数需删除时直接返回
50
+
47
51
  const url = new URL(window.location.href);
48
- let params, newUrl;
52
+ let newUrl;
49
53
 
50
54
  // 处理hash模式(参数在#之后)
51
55
  if (url.hash.includes('?')) {
52
56
  const [hashPath, hashQuery] = url.hash.split('?');
53
- params = new URLSearchParams(hashQuery);
57
+ const params = new URLSearchParams(hashQuery);
58
+
59
+ // 批量删除参数
60
+ paramNames.forEach(name => {
61
+ if (params.has(name)) {
62
+ params.delete(name);
63
+ }
64
+ });
54
65
 
55
- if (params.has(name)) {
56
- params.delete(name);
57
- const newHash = params.toString() ? `${hashPath}?${params.toString()}` : hashPath;
66
+ // 重构hash部分
67
+ const newHash = params.toString() ? `${hashPath}?${params.toString()}` : hashPath;
68
+ if (newHash !== url.hash) { // 只有hash变化时才更新URL
58
69
  url.hash = newHash;
59
70
  newUrl = url.toString();
60
71
  }
61
72
  }
62
73
  // 处理history模式(参数在?之后)
63
74
  else {
64
- params = new URLSearchParams(url.search);
65
- if (params.has(name)) {
66
- params.delete(name);
75
+ const params = new URLSearchParams(url.search);
76
+ let hasChanged = false;
77
+
78
+ // 批量删除参数
79
+ paramNames.forEach(name => {
80
+ if (params.has(name)) {
81
+ params.delete(name);
82
+ hasChanged = true;
83
+ }
84
+ });
85
+
86
+ // 只有参数变化时才更新URL
87
+ if (hasChanged) {
67
88
  url.search = params.toString();
68
89
  newUrl = url.toString();
69
90
  }
70
91
  }
71
-
72
- // 更新URL
92
+ // 更新URL(仅当URL有变化时)
73
93
  if (newUrl && newUrl !== window.location.href) {
74
94
  window.location.replace(newUrl);
75
95
  }
@@ -92,6 +112,7 @@ function getCurrentUrlWithParams() {
92
112
  */
93
113
  function mergeConfigs(defaults, options) {
94
114
  if (!options) return { ...defaults };
115
+
95
116
  const merged = { ...defaults };
96
117
  for (const key in options) {
97
118
  if (options.hasOwnProperty(key)) {
@@ -4036,6 +4057,66 @@ async function request(url, {
4036
4057
  }
4037
4058
  }
4038
4059
 
4060
+ // ===== Cookie操作工具函数 =====
4061
+ /**
4062
+ * 获取指定名称的Cookie值
4063
+ * @param {string} name Cookie名称
4064
+ * @returns {string|null} Cookie值
4065
+ */
4066
+ function getCookie(name) {
4067
+ if (!isBrowser()) return null;
4068
+ const match = document.cookie.match(new RegExp(`(^| )${name}=([^;]+)`));
4069
+ return match ? decodeURIComponent(match[2]) : null;
4070
+ }
4071
+
4072
+ /**
4073
+ * 设置Cookie
4074
+ * @param {string} name Cookie名称
4075
+ * @param {string} value Cookie值
4076
+ * @param {Object} options 配置(过期时间、路径等)
4077
+ */
4078
+ function setCookie(name, value, options = {}) {
4079
+ if (!isBrowser()) return;
4080
+ let cookieStr = `${name}=${encodeURIComponent(value)}`;
4081
+ cookieStr += `; path=${options.path || '/'}`; // 默认根路径
4082
+ if (options.expires) {
4083
+ const expires = typeof options.expires === 'number'
4084
+ ? new Date(Date.now() + options.expires * 86400000)
4085
+ : options.expires;
4086
+ cookieStr += `; expires=${expires.toUTCString()}`;
4087
+ }
4088
+ document.cookie = cookieStr;
4089
+ }
4090
+
4091
+ /**
4092
+ * 删除指定名称的Cookie
4093
+ * @param {string} name Cookie名称
4094
+ */
4095
+ function removeCookie(name) {
4096
+ if (!isBrowser()) return;
4097
+ setCookie(name, '', { expires: -1 });
4098
+ }
4099
+
4100
+ /**
4101
+ * 给重定向地址拼接platType参数
4102
+ * @param {string} redirectUrl 原始重定向地址
4103
+ * @param {string} platType platType值
4104
+ * @param {string} platTypeKey 参数名(默认platType)
4105
+ * @returns {string} 拼接后的重定向地址
4106
+ */
4107
+ function addPlatTypeToRedirectUrl(redirectUrl, platType, platTypeKey = 'platType') {
4108
+ if (!redirectUrl || !platType) return redirectUrl;
4109
+ try {
4110
+ const url = new URL(redirectUrl);
4111
+ url.searchParams.set(platTypeKey, platType);
4112
+ return url.toString();
4113
+ } catch (e) {
4114
+ // 兼容非标准URL的情况(比如相对路径)
4115
+ const separator = redirectUrl.includes('?') ? '&' : '?';
4116
+ return `${redirectUrl}${separator}${platTypeKey}=${platType}`;
4117
+ }
4118
+ }
4119
+
4039
4120
  // 默认配置
4040
4121
  const DEFAULT_CONFIG = {
4041
4122
  accessCodeKey: 'accessCode',
@@ -4046,13 +4127,14 @@ const DEFAULT_CONFIG = {
4046
4127
  refreshCodeApi: '',
4047
4128
  logoutApi: '',
4048
4129
  logOutUrl: '',
4049
- storage: localStorage, // 可替换为sessionStorage
4130
+ storage: localStorage,
4050
4131
  oldPwdKey: 'oldPwd',
4051
4132
  newPwdKey: 'newPwd',
4052
4133
  changePasswordApi: '',
4053
4134
  sendCaptchaCodeApi: '',
4054
4135
  typeKey: 'type',
4055
- codeKey: 'code'
4136
+ codeKey: 'code',
4137
+ platTypeKey: 'platType' // platType参数名配置
4056
4138
  };
4057
4139
 
4058
4140
  let config = null;
@@ -4075,46 +4157,35 @@ function validateConfig(options) {
4075
4157
  }
4076
4158
 
4077
4159
  /**
4078
- * 判断是否是iOS移动端(精准适配iPad Air/所有iPad机型 + 全版本iPadOS)
4160
+ * 判断是否是iOS移动端
4079
4161
  * @returns {boolean} 是否为iOS环境
4080
4162
  */
4081
4163
  function isIOS() {
4082
- // 非浏览器环境直接返回false(如需保留请取消注释)
4083
- // if (!isBrowser()) return false;
4164
+ if (!isBrowser()) return false;
4084
4165
 
4085
4166
  const userAgent = navigator.userAgent.toLowerCase();
4086
- const platform = navigator.platform.toLowerCase(); // 统一转小写,避免大小写兼容问题
4167
+ const platform = navigator.platform.toLowerCase();
4087
4168
  const maxTouchPoints = navigator.maxTouchPoints || 0;
4088
- const screenRatio = screen.width / screen.height; // 屏幕宽高比(iPad核心特征:4:3左右)
4169
+ const screenRatio = screen.width / screen.height;
4089
4170
 
4090
- // ========== 核心检测规则 ==========
4091
- // 1. 基础规则:iPhone/iPod 直接命中(无兼容问题)
4092
4171
  const isIphoneIpod = /iphone|ipod/.test(userAgent) && !window.MSStream;
4093
-
4094
- // 2. iPad 专属检测(覆盖所有iPad机型,含iPad Air)
4095
4172
  const isIpad = (
4096
- // 场景1:老版本iPadOS/原生标识(platform含ipad)
4097
4173
  platform.includes('ipad') ||
4098
- // 场景2:iPadOS 13+ 伪装Mac(UA含macintosh + 触摸+ 非Mac平台)
4099
4174
  (
4100
- userAgent.includes('macintosh') &&
4101
- maxTouchPoints > 0 && // iPad Air 触摸点≥5,Mac几乎为0
4102
- !platform.includes('mac') && // 排除真Mac
4175
+ userAgent.includes('macintosh') &&
4176
+ maxTouchPoints > 0 &&
4177
+ !platform.includes('mac') &&
4103
4178
  !window.MSStream
4104
4179
  ) ||
4105
- // 场景3:新版本iPadOS(UA直接含ipados,如iPad Air搭载的iPadOS 15+)
4106
4180
  userAgent.includes('ipados') ||
4107
- // 场景4:极端场景(第三方浏览器如Chrome for iPad Air)
4108
4181
  (
4109
- maxTouchPoints >= 5 && // iPad Air 固定支持5点触摸
4110
- !platform.includes('android') && // 排除安卓平板
4111
- (screenRatio > 0.7 && screenRatio < 1.4) // iPad宽高比≈0.75(4:3),Mac多为1.78(16:9)
4182
+ maxTouchPoints >= 5 &&
4183
+ !platform.includes('android') &&
4184
+ (screenRatio > 0.7 && screenRatio < 1.4)
4112
4185
  )
4113
4186
  );
4114
4187
 
4115
- // ========== 最终判定 ==========
4116
- const result = isIphoneIpod || isIpad;
4117
- return result;
4188
+ return isIphoneIpod || isIpad;
4118
4189
  }
4119
4190
 
4120
4191
  /**
@@ -4134,9 +4205,17 @@ function createSSO() {
4134
4205
  config = mergeConfigs(DEFAULT_CONFIG, options);
4135
4206
  validateConfig(config);
4136
4207
 
4208
+ // 初始化时检测URL中的platType并存入Cookie
4209
+ if (isBrowser()) {
4210
+ const platTypeFromUrl = getQueryParam(config.platTypeKey);
4211
+ if (platTypeFromUrl) {
4212
+ setCookie(config.platTypeKey, platTypeFromUrl);
4213
+ // 可选:移除URL中的platType(避免重复显示)
4214
+ }
4215
+ }
4216
+
4137
4217
  const accessCode = getQueryParam(config.accessCodeKey);
4138
4218
 
4139
- // 验证必要的API配置
4140
4219
  if (!config.tokenApi) {
4141
4220
  return { code: -100, msg: '缺少tokenApi配置', success: false };
4142
4221
  }
@@ -4155,14 +4234,25 @@ function createSSO() {
4155
4234
 
4156
4235
  if (result.code === 0 && result.data) {
4157
4236
  config.storage.setItem(config.tokenKey, result.data);
4158
- removeQueryParam(config.accessCodeKey);
4237
+ removeQueryParam([config.accessCodeKey,config.platTypeKey]);
4159
4238
  }
4160
4239
  return result;
4161
4240
  }
4162
4241
  // 如果没有token,跳转到登录页
4163
4242
  else if (!this.getToken()) {
4164
4243
  if (isBrowser() && config.logOutUrl) {
4165
- window.location.href = `${config.logOutUrl}?redirect_uri=${encodeURIComponent(getCurrentUrlWithParams())}`;
4244
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4245
+ const platTypeFromCookie = getCookie(config.platTypeKey);
4246
+ // 1. 获取原始重定向地址
4247
+ let redirectUri = getCurrentUrlWithParams();
4248
+ // 2. 给重定向地址加platType参数
4249
+ if (platTypeFromCookie) {
4250
+ redirectUri = addPlatTypeToRedirectUrl(redirectUri, platTypeFromCookie, config.platTypeKey);
4251
+ }
4252
+ // 3. 构建登录页URL(仅带redirect_uri参数)
4253
+ let loginUrl = new URL(config.logOutUrl);
4254
+ loginUrl.searchParams.set('redirect_uri', encodeURIComponent(redirectUri));
4255
+ window.location.href = loginUrl.toString();
4166
4256
  }
4167
4257
  }
4168
4258
 
@@ -4194,33 +4284,21 @@ function createSSO() {
4194
4284
  * @returns {Promise<Object>} 接口返回结果
4195
4285
  */
4196
4286
  async logout() {
4197
- // 1. 前置校验:初始化状态
4198
4287
  if (!config) {
4199
4288
  return { code: -101, msg: '请先调用init方法初始化', success: false };
4200
4289
  }
4201
4290
 
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配置(仅接口调用时需要,跳转登录页不受此影响)
4212
- if (!config.logOutApi) {
4213
- // 无logoutApi时仍清除token并跳转登录页,保证基础退出逻辑
4214
- this.removeToken();
4215
- const loginUrl = buildLoginUrl();
4216
- if (loginUrl) window.location.href = loginUrl;
4291
+ if (!config.logoutApi) {
4217
4292
  return { code: -102, msg: '未配置logoutApi', success: false };
4218
4293
  }
4219
4294
 
4295
+ // 获取并删除Cookie中的platType
4296
+ const platType = getCookie(config.platTypeKey);
4297
+ removeCookie(config.platTypeKey);
4298
+
4220
4299
  const token = this.getToken();
4221
4300
  if (token) {
4222
4301
  try {
4223
- // 调用退出接口
4224
4302
  const result = await request(
4225
4303
  config.logoutApi,
4226
4304
  {
@@ -4229,37 +4307,48 @@ function createSSO() {
4229
4307
  timeout: config.timeout
4230
4308
  }
4231
4309
  );
4232
- // 无论接口返回结果如何,都清除token
4233
4310
  this.removeToken();
4234
4311
 
4235
- // 跳转登录页(携带完整的当前URL)
4236
- const loginUrl = buildLoginUrl();
4237
- if (loginUrl) window.location.href = loginUrl;
4312
+ if (isBrowser() && config.logOutUrl) {
4313
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4314
+ // 1. 获取原始重定向地址
4315
+ let redirectUri = getCurrentUrlWithParams();
4316
+ // 2. 给重定向地址加platType参数
4317
+ if (platType) {
4318
+ redirectUri = addPlatTypeToRedirectUrl(redirectUri, platType, config.platTypeKey);
4319
+ }
4320
+ // 3. 构建登录页URL
4321
+ let logoutUrl = new URL(config.logOutUrl);
4322
+ logoutUrl.searchParams.set('redirect_uri', encodeURIComponent(redirectUri));
4323
+ window.location.href = logoutUrl.toString();
4324
+ }
4238
4325
  return result;
4239
4326
  } catch (error) {
4240
- // 接口调用失败,仍清除token并跳转登录页
4241
- this.removeToken();
4242
- const loginUrl = buildLoginUrl();
4243
- if (loginUrl) window.location.href = loginUrl;
4244
4327
  return { code: -103, msg: `退出失败: ${error.message}`, success: false };
4245
4328
  }
4246
4329
  } else {
4247
- // 无token时直接清除(兜底)并跳转登录页
4248
4330
  this.removeToken();
4249
- const loginUrl = buildLoginUrl();
4250
- if (loginUrl) window.location.href = loginUrl;
4331
+ if (isBrowser() && config.logOutUrl) {
4332
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4333
+ let redirectUri = getCurrentUrlWithParams();
4334
+ if (platType) {
4335
+ redirectUri = addPlatTypeToRedirectUrl(redirectUri, platType, config.platTypeKey);
4336
+ }
4337
+ let logoutUrl = new URL(config.logOutUrl);
4338
+ logoutUrl.searchParams.set('redirect_uri', encodeURIComponent(redirectUri));
4339
+ window.location.href = logoutUrl.toString();
4340
+ }
4251
4341
  return { code: 0, msg: '已成功清除token', success: true };
4252
4342
  }
4253
4343
  },
4254
4344
 
4255
4345
  /**
4256
4346
  * 用token换取新accessCode并跳转到指定URL
4257
- * @param {string} redirectUrl - 目标跳转地址(支持带query/hash参数)
4347
+ * @param {string} redirectUrl - 目标跳转地址
4258
4348
  * @param {string} target - 当前页面:_self、新页面打开:_blank,默认当前页_self
4259
4349
  * @returns {Promise<Object>} 接口返回结果
4260
4350
  */
4261
4351
  async toUrl(redirectUrl, target = '_self') {
4262
- // 1. 前置校验:初始化状态、参数合法性
4263
4352
  if (!config) {
4264
4353
  return { code: -101, msg: '请先调用init方法初始化', success: false };
4265
4354
  }
@@ -4268,45 +4357,49 @@ function createSSO() {
4268
4357
  return { code: -104, msg: '请提供跳转地址', success: false };
4269
4358
  }
4270
4359
 
4271
- // ========== 新增:获取当前页面的platType参数 ==========
4272
- const currentPlatType = isBrowser() ? getQueryParam('platType') : '';
4273
-
4274
- // ========== 保留:platType=screen强制_self逻辑 ==========
4275
- const isPlatTypeScreen = currentPlatType === 'screen';
4276
-
4277
- // 2. 处理target参数:platType=screen > iOS > 传入的target
4278
- const finalTarget = isPlatTypeScreen
4279
- ? '_self' // platType=screen时强制_self
4280
- : (isIOS() ? '_self' : target); // 否则沿用原iOS判断逻辑
4281
-
4282
- if (!['_self', '_blank'].includes(finalTarget)) {
4283
- return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
4360
+ // iOS强制_self
4361
+ if (isIOS()) {
4362
+ target = '_self';
4284
4363
  }
4285
4364
 
4286
- // 3. 工具函数:统一构建登录跳转URL(避免重复代码,确保参数完整编码)
4287
- const buildLoginUrl = (redirectUrl) => {
4288
- if (!config.logOutUrl) return '';
4289
- // 关键:encodeURIComponent 会完整编码redirectUrl的所有部分(query/hash),避免参数丢失
4290
- const encodedRedirectUri = encodeURIComponent(redirectUrl);
4291
- return `${config.logOutUrl}?redirect_uri=${encodedRedirectUri}`;
4292
- };
4365
+ // platType=screen时强制_self
4366
+ const platType = getCookie(config.platTypeKey);
4367
+ if (platType === 'screen') {
4368
+ target = '_self';
4369
+ }
4370
+
4371
+ // 验证target参数
4372
+ if (!['_self', '_blank'].includes(target)) {
4373
+ return { code: -108, msg: 'target参数必须是"_self"或"_blank"', success: false };
4374
+ }
4293
4375
 
4294
- // 4. 校验refreshCodeApi配置
4295
4376
  if (!config.refreshCodeApi) {
4296
4377
  return { code: -105, msg: '未配置refreshCodeApi', success: false };
4297
4378
  }
4298
4379
 
4299
- // 5. 获取token,无token则直接跳登录页
4300
4380
  const token = this.getToken();
4301
4381
  if (!token) {
4302
4382
  if (isBrowser() && config.logOutUrl) {
4303
- const loginUrl = buildLoginUrl(redirectUrl);
4304
- finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
4383
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4384
+ // 1. 给目标跳转地址加platType
4385
+ let newRedirectUrl = redirectUrl;
4386
+ if (platType) {
4387
+ newRedirectUrl = addPlatTypeToRedirectUrl(newRedirectUrl, platType, config.platTypeKey);
4388
+ }
4389
+ // 2. 构建登录页URL
4390
+ let loginUrl = new URL(config.logOutUrl);
4391
+ loginUrl.searchParams.set('redirect_uri', encodeURIComponent(newRedirectUrl));
4392
+ const loginUrlStr = loginUrl.toString();
4393
+
4394
+ if (target === '_blank') {
4395
+ window.open(loginUrlStr, '_blank');
4396
+ } else {
4397
+ window.location.href = loginUrlStr;
4398
+ }
4305
4399
  }
4306
4400
  return { code: -106, msg: '未找到有效token', success: false };
4307
4401
  }
4308
4402
 
4309
- // 6. 有token则尝试换取accessCode并跳转
4310
4403
  try {
4311
4404
  const result = await request(
4312
4405
  config.refreshCodeApi,
@@ -4318,31 +4411,48 @@ function createSSO() {
4318
4411
  );
4319
4412
 
4320
4413
  if (result.code === 0 && result.data && isBrowser()) {
4321
- // ========== 核心优化:拼接platType到目标URL ==========
4414
+ // toUrl跳转目标地址时,仅携带accessCode,不携带platType
4322
4415
  const url = new URL(redirectUrl);
4323
- // 1. 如果当前页面有platType,拼接到目标URL(覆盖原有platType)
4324
- if (currentPlatType) {
4325
- url.searchParams.set('platType', currentPlatType);
4326
- }
4327
- // 2. 拼接accessCode(保留原有逻辑)
4328
4416
  url.searchParams.set(config.accessCodeKey, result.data);
4329
4417
  const targetUrl = url.toString();
4330
4418
 
4331
- finalTarget === '_blank' ? window.open(targetUrl, '_blank') : window.location.href = targetUrl;
4419
+ if (target === '_blank') {
4420
+ window.open(targetUrl, '_blank');
4421
+ } else {
4422
+ window.location.href = targetUrl;
4423
+ }
4332
4424
  } else {
4333
- // 接口返回失败,跳登录页(复用统一的登录URL构建逻辑)
4334
- if (isBrowser() && config.logOutUrl) {
4335
- const loginUrl = buildLoginUrl(redirectUrl);
4336
- finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
4425
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4426
+ let newRedirectUrl = redirectUrl;
4427
+ if (platType) {
4428
+ newRedirectUrl = addPlatTypeToRedirectUrl(newRedirectUrl, platType, config.platTypeKey);
4429
+ }
4430
+ let loginUrl = new URL(config.logOutUrl);
4431
+ loginUrl.searchParams.set('redirect_uri', encodeURIComponent(newRedirectUrl));
4432
+ const loginUrlStr = loginUrl.toString();
4433
+
4434
+ if (target === '_blank') {
4435
+ window.open(loginUrlStr, '_blank');
4436
+ } else {
4437
+ window.location.href = loginUrlStr;
4337
4438
  }
4338
4439
  }
4339
4440
 
4340
4441
  return result;
4341
4442
  } catch (error) {
4342
- // 接口异常,跳登录页(复用统一的登录URL构建逻辑)
4343
- if (isBrowser() && config.logOutUrl) {
4344
- const loginUrl = buildLoginUrl(redirectUrl);
4345
- finalTarget === '_blank' ? window.open(loginUrl, '_blank') : window.location.href = loginUrl;
4443
+ // ===== 核心修正:platType拼到redirect_uri里 =====
4444
+ let newRedirectUrl = redirectUrl;
4445
+ if (platType) {
4446
+ newRedirectUrl = addPlatTypeToRedirectUrl(newRedirectUrl, platType, config.platTypeKey);
4447
+ }
4448
+ let loginUrl = new URL(config.logOutUrl);
4449
+ loginUrl.searchParams.set('redirect_uri', encodeURIComponent(newRedirectUrl));
4450
+ const loginUrlStr = loginUrl.toString();
4451
+
4452
+ if (target === '_blank') {
4453
+ window.open(loginUrlStr, '_blank');
4454
+ } else {
4455
+ window.location.href = loginUrlStr;
4346
4456
  }
4347
4457
  return { code: -107, msg: `跳转失败: ${error.message}`, success: false };
4348
4458
  }
@@ -4381,7 +4491,7 @@ function createSSO() {
4381
4491
  * @returns {Object|null} 当前配置
4382
4492
  */
4383
4493
  getConfig() {
4384
- return { ...config }; // 返回配置的副本,防止外部修改
4494
+ return { ...config };
4385
4495
  },
4386
4496
 
4387
4497
  async changePassword(fromData = {}) {
@@ -4410,7 +4520,6 @@ function createSSO() {
4410
4520
 
4411
4521
  async getPhoneCode() {
4412
4522
  const token = this.getToken();
4413
- // 修复笔误:sendCaptchaCode → sendCaptchaCodeApi
4414
4523
  return request(
4415
4524
  config.sendCaptchaCodeApi,
4416
4525
  {