af-mobile-client-vue3 1.6.14 → 1.6.15

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "af-mobile-client-vue3",
3
3
  "type": "module",
4
- "version": "1.6.14",
4
+ "version": "1.6.15",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -126,9 +126,6 @@ export const useUserStore = defineStore('app-user', () => {
126
126
  const getToken = () => {
127
127
  return userState.value.token || Storage.get(ACCESS_TOKEN, '') as string
128
128
  }
129
- const getSessionKey = () => {
130
- return Storage.get('v4-session-key', '') as string || localStorage.getItem('v4-session-key')
131
- }
132
129
  const getLastUpdateTime = () => {
133
130
  return userState.value.lastUpdateTime
134
131
  }
@@ -157,20 +154,6 @@ export const useUserStore = defineStore('app-user', () => {
157
154
  setToken(token)
158
155
  }
159
156
  }
160
- const setSessionKey = (key: string | undefined, expiresInMinutes: number | null = null) => {
161
- if (expiresInMinutes === 0) {
162
- Storage.set('v4-session-key', key, 0)
163
- }
164
- else if (expiresInMinutes && expiresInMinutes > 0) {
165
- const expiresInSeconds = expiresInMinutes * 60
166
- const BUFFER_SECONDS = 30
167
- const safeExpire = Math.max(expiresInSeconds - BUFFER_SECONDS, 0)
168
- Storage.set('v4-session-key', key, safeExpire)
169
- }
170
- else {
171
- localStorage.setItem('v4-session-key', key)
172
- }
173
- }
174
157
  const setUserInfo = (info: any | null) => {
175
158
  userState.value.userInfo = info
176
159
  userState.value.lastUpdateTime = new Date().getTime()
@@ -326,7 +309,7 @@ export const useUserStore = defineStore('app-user', () => {
326
309
  Storage.set('LoginTicket', LoginTicket)
327
310
  if (data.session && useSettingStore().getSetting().requestEncrypt) {
328
311
  const k = encryptUtil.RSADecrypt(data.session as string)
329
- setSessionKey(k, data.expires_in)
312
+ localStorage.setItem('v4-session-key', k)
330
313
  secureStorageWrite('v4-session-key', k)
331
314
  }
332
315
  return Promise.resolve(data)
@@ -344,7 +327,7 @@ export const useUserStore = defineStore('app-user', () => {
344
327
  const LoginTicket = crypto.AESEncrypt(JSON.stringify(data), '3KMKqvgwR8ULbR8Z')
345
328
  if (data.session && useSettingStore().getSetting().requestEncrypt) {
346
329
  const k = encryptUtil.RSADecrypt(data.session as string)
347
- setSessionKey(k, data.expires_in)
330
+ localStorage.setItem('v4-session-key', k)
348
331
  secureStorageWrite('v4-session-key', k)
349
332
  }
350
333
  Storage.set('LoginTicket', LoginTicket)
@@ -380,7 +363,6 @@ export const useUserStore = defineStore('app-user', () => {
380
363
  Storage.remove(PLATFORM_TYPE)
381
364
  Storage.remove(EXTERNAL_USER_INFO)
382
365
  Storage.remove('LoginTicket')
383
- Storage.remove('v4-session-key')
384
366
  // 清除本地加密秘钥
385
367
  localStorage.removeItem('v4-session-key')
386
368
  secureStorageWrite('v4-session-key', '')
@@ -427,7 +409,6 @@ export const useUserStore = defineStore('app-user', () => {
427
409
  loginExternal,
428
410
  loginExternalMini,
429
411
  getToken,
430
- getSessionKey,
431
412
  getLastUpdateTime,
432
413
  logout,
433
414
  registerClean,
@@ -33,16 +33,19 @@ class Http {
33
33
  // 如果 token 存在
34
34
  if (savedToken)
35
35
  config.headers[ACCESS_TOKEN] = savedToken
36
- const v4SessionKey = useUserStore().getSessionKey()
37
- if (['post'].includes(config.method.toLowerCase()) && v4SessionKey) {
38
- if (config.data && !(config.data instanceof FormData)) {
39
- config.data = {
40
- encrypted: encryptUtil.AESEncryptCBC(config.data, v4SessionKey),
36
+ const v4SessionKey = localStorage.getItem('v4-session-key')
37
+ if (['post'].includes(config.method.toLowerCase()) &&
38
+ !config.url.includes('/logic/openapi/') &&
39
+ !config.url.includes('auth/login')
40
+ && v4SessionKey) {
41
+ if (config.data && !(config.data instanceof FormData)) {
42
+ config.data = {
43
+ encrypted: encryptUtil.AESEncryptCBC(config.data, v4SessionKey),
44
+ }
45
+ config.headers['X-Sec'] = '1'
46
+ config.headers['X-Rand'] = Math.random().toString(36).substr(2, 5)
47
+ config.headers['X-Ts'] = Date.now()
41
48
  }
42
- config.headers['X-Sec'] = '1'
43
- config.headers['X-Rand'] = Math.random().toString(36).substr(2, 5)
44
- config.headers['X-Ts'] = Date.now()
45
- }
46
49
  }
47
50
  return config
48
51
  },
@@ -62,7 +65,7 @@ class Http {
62
65
  async (response: AxiosResponse) => {
63
66
  // 判断是否需要解密
64
67
  if (response.headers && response.headers['x-encrypted'] === '1') {
65
- const v4SessionKey = useUserStore().getSessionKey()
68
+ const v4SessionKey = localStorage.getItem('v4-session-key')
66
69
  if (v4SessionKey && response.data) {
67
70
  const decryptedData = encryptUtil.decryptResponse(response?.data, v4SessionKey)
68
71
  // 如果解密成功且不等于原数据,说明解密有效