@indfnd/utils 0.1.18 → 0.1.21

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/global.d.ts CHANGED
@@ -3,6 +3,7 @@ interface Window {
3
3
  apiErrorHandler: (msg: string) => void
4
4
  NodeRSA: any
5
5
  Base64: any
6
+ native: any
6
7
  }
7
8
 
8
9
  interface Date {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indfnd/utils",
3
- "version": "0.1.18",
3
+ "version": "0.1.21",
4
4
  "author": "huxuetong",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -0,0 +1,122 @@
1
+ let Base64 = {
2
+ Base64Chars: 'abcdefghijklmnopqrstuv' + 'wxyzABCDEFGHIJKLMNOP' + 'QRSTUVWXYZ0123456789@*-',
3
+ /**
4
+ * Encode a string to a Base64 string follow Bse64 regular.
5
+ * @param s, a normal string
6
+ * @return a Base64 string
7
+ */
8
+ encode: function (s) {
9
+ if (!s || s.length == 0) return s
10
+
11
+ var d = ''
12
+ var b = this.ucs2_utf8(s)
13
+ var b0, b1, b2, b3
14
+ var len = b.length
15
+ var i = 0
16
+ while (i < len) {
17
+ var tmp = b[i++]
18
+ b0 = (tmp & 0xfc) >> 2
19
+ b1 = (tmp & 0x03) << 4
20
+ if (i < len) {
21
+ tmp = b[i++]
22
+ b1 |= (tmp & 0xf0) >> 4
23
+ b2 = (tmp & 0x0f) << 2
24
+ if (i < len) {
25
+ tmp = b[i++]
26
+ b2 |= (tmp & 0xc0) >> 6
27
+ b3 = tmp & 0x3f
28
+ } else {
29
+ b3 = 64 // 1 byte "-" is supplement
30
+ }
31
+ } else {
32
+ b2 = b3 = 64 // 2 bytes "-" are supplement
33
+ }
34
+
35
+ d += this.Base64Chars.charAt(b0)
36
+ d += this.Base64Chars.charAt(b1)
37
+ d += this.Base64Chars.charAt(b2)
38
+ d += this.Base64Chars.charAt(b3)
39
+ }
40
+
41
+ return d
42
+ },
43
+
44
+ /**
45
+ * Encodes a ucs2 string to a utf8 integer array.
46
+ * @param s, a string
47
+ * @return an integer array
48
+ */
49
+ ucs2_utf8: function (s) {
50
+ if (!s) return null
51
+ var d = new Array()
52
+ if (s == '') return d
53
+
54
+ var c = 0,
55
+ i = 0,
56
+ j = 0
57
+ var len = s.length
58
+ while (i < len) {
59
+ c = s.charCodeAt(i++)
60
+ if (c <= 0x7f) {
61
+ // 1 byte
62
+
63
+ d[j++] = c
64
+ } else if (c >= 0x80 && c <= 0x7ff) {
65
+ // 2 bytes
66
+
67
+ d[j++] = ((c >> 6) & 0x1f) | 0xc0
68
+ d[j++] = (c & 0x3f) | 0x80
69
+ } else {
70
+ // 3 bytes
71
+
72
+ d[j++] = (c >> 12) | 0xe0
73
+ d[j++] = ((c >> 6) & 0x3f) | 0x80
74
+ d[j++] = (c & 0x3f) | 0x80
75
+ }
76
+ }
77
+
78
+ return d
79
+ },
80
+ /**
81
+ * Encodes a utf8 integer array to a ucs2 string.
82
+ * @param s, an integer array
83
+ * @return a string
84
+ */
85
+ utf8_ucs2: function (s) {
86
+ if (!s) return null
87
+ var len = s.length
88
+ if (len == 0) return ''
89
+
90
+ var d = ''
91
+ var c = 0,
92
+ i = 0,
93
+ tmp = 0
94
+ while (i < len) {
95
+ c = s[i++]
96
+ if ((c & 0xe0) == 0xe0) {
97
+ // 3 bytes
98
+
99
+ tmp = (c & 0x0f) << 12
100
+ c = s[i++]
101
+ tmp |= (c & 0x3f) << 6
102
+ c = s[i++]
103
+ tmp |= c & 0x3f
104
+ } else if ((c & 0xc0) == 0xc0) {
105
+ // 2 bytes
106
+
107
+ tmp = (c & 0x1f) << 6
108
+ c = s[i++]
109
+ tmp |= c & 0x3f
110
+ } else {
111
+ // 1 byte
112
+
113
+ tmp = c
114
+ }
115
+
116
+ d += String.fromCharCode(tmp)
117
+ }
118
+
119
+ return d
120
+ },
121
+ }
122
+ export { Base64 }
@@ -1,5 +1,6 @@
1
1
  import { axios } from '@/utils'
2
2
  import { config } from '@/config'
3
+ import { Base64 } from './base64'
3
4
 
4
5
  const CONTEXT = config.authServerContext
5
6
 
@@ -7,7 +8,7 @@ export function loginApi({ userName, password, validCodeId, validCodeInput }) {
7
8
  let publicKey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDD2iolFHi+6bUh+V6JPr2gFJQsC0QNsq2EwI0MAPlI5AaizBHRVMjX1H73ptuDSiT3QZh4kk74w+eDLyYj4JXo1SvvDw5w378SLhUIDzH0zrlt3oleT3kiPQxC17yM3Os/wrtHO7IC+KGo9qrg+LJFyR/fYYHcyH9i+JAejBEnJQIDAQAB`
8
9
  let nodeRSA = new window.NodeRSA(publicKey, 'pkcs8-public')
9
10
  let rsaPaswword = nodeRSA.encrypt(password, 'base64')
10
- let upw = window.Base64.encode(rsaPaswword)
11
+ let upw = Base64.encode(rsaPaswword)
11
12
 
12
13
  const data = { usn: userName, upw, validCodeId, validCodeInput }
13
14
  return axios.formPost(CONTEXT + '/sso/auth/login', data)
@@ -78,6 +78,11 @@ export function responseInterceptors(response) {
78
78
  const code = data.code
79
79
  switch (code) {
80
80
  case SUCCESS_CODE: {
81
+ if (sessionStorage.getItem('isFromIM') == '1' && data?.extInfo?.handleTask) {
82
+ if (typeof window.native != 'undefined') {
83
+ window.native.goHome()
84
+ }
85
+ }
81
86
  return data
82
87
  }
83
88
  case NO_SESSION_CODE: {
@@ -1,4 +1,4 @@
1
- import { getLocalStorage, getSessionStorage, setLocalStorage } from './storage'
1
+ import { getLocalStorage, getSessionStorage, setLocalStorage, setSessionStorage } from './storage'
2
2
 
3
3
  const TOKEN_KEY = 'v8-token'
4
4
 
@@ -7,6 +7,7 @@ const TOKEN_KEY_IBP = 'lambo-token'
7
7
  // 要从门户跳转过来,sessionStorage不能带token过来,改成localStorage
8
8
  export function setToken(token: string) {
9
9
  setLocalStorage(TOKEN_KEY, token)
10
+ setSessionStorage(TOKEN_KEY_IBP, token)
10
11
  Cookie.set('TOKEN_KEY', token, 1)
11
12
  }
12
13
 
@@ -0,0 +1,7 @@
1
+ export namespace Base64 {
2
+ let Base64Chars: string
3
+ function encode(s: any): any
4
+ function ucs2_utf8(s: any): any[]
5
+ function utf8_ucs2(s: any): string
6
+ }
7
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../../src/api/platform/base64.js"],"names":[],"mappings":";;IAOU,6BAkCP;IAOU,kCA8BV;IAMU,mCAmCV"}
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/platform/user.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE;;;;;CAAA,+CAQ3E;AAED,wBAAgB,cAAc,gDAE7B;AAED,wBAAgB,kBAAkB,gDAEjC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,+CAErC;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,UAEhD;AAED,wBAAgB,SAAS,gDAExB"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../src/api/platform/user.ts"],"names":[],"mappings":"AAMA,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE;;;;;CAAA,+CAQ3E;AAED,wBAAgB,cAAc,gDAE7B;AAED,wBAAgB,kBAAkB,gDAEjC;AAED,wBAAgB,iBAAiB,CAAC,IAAI,KAAA,+CAErC;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,UAEhD;AAED,wBAAgB,SAAS,gDAExB"}
@@ -1 +1 @@
1
- {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../../src/utils/request/interceptors.ts"],"names":[],"mappings":"AAuBA,wBAAgB,mBAAmB,CAAC,MAAM,KAAA,OAwCzC;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,OA6B5C;AAED,wBAAgB,cAAc,CAAC,KAAK,KAAA,kBAQnC"}
1
+ {"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../../src/utils/request/interceptors.ts"],"names":[],"mappings":"AAuBA,wBAAgB,mBAAmB,CAAC,MAAM,KAAA,OAwCzC;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,KAAA,OAkC5C;AAED,wBAAgB,cAAc,CAAC,KAAK,KAAA,kBAQnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAGrC;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,OAAO,CAY3C"}
1
+ {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAOA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,QAIrC;AAED,wBAAgB,QAAQ,IAAI,MAAM,GAAG,OAAO,CAY3C"}