wui-components-v2 1.2.52 → 1.2.54
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/api/login.ts +7 -5
- package/components/login-form/login-form.vue +1 -0
- package/package.json +1 -1
- package/utils/rsaEncrypt.ts +59 -0
package/api/login.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// 导入核心alova实例
|
|
2
2
|
import dayjs from 'dayjs/esm/index'
|
|
3
|
-
import timezone from 'dayjs/esm/plugin/timezone'
|
|
4
|
-
import utc from 'dayjs/esm/plugin/utc'
|
|
5
3
|
import rsaEncrypt from '../utils/rsaEncrypt'
|
|
6
4
|
import req from './core/index'
|
|
7
5
|
// 获取公钥
|
|
@@ -18,17 +16,21 @@ export async function login(
|
|
|
18
16
|
kaptchaToken: string = '',
|
|
19
17
|
kaptchaText: string = ''
|
|
20
18
|
): Promise<any> {
|
|
21
|
-
dayjs.
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// 注意:不能依赖 dayjs timezone/utc 插件,它们在 App 端会使用 Intl.DateTimeFormat,
|
|
20
|
+
// 而部分 App 环境(如 Android webview)未提供全局 Intl,会抛 ReferenceError: Intl is not defined。
|
|
21
|
+
// 这里用基础格式化取本地时间即可(不依赖 Intl)。
|
|
22
|
+
const datetime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
|
|
24
23
|
const json = {
|
|
25
24
|
username,
|
|
26
25
|
password,
|
|
27
26
|
datetime,
|
|
28
27
|
}
|
|
28
|
+
// 1. 获取公钥
|
|
29
29
|
const res = await pubKey()
|
|
30
30
|
const pubkeystr = res.rasPubkey
|
|
31
|
+
// 2. 用公钥加密账号密码
|
|
31
32
|
const userInfo = rsaEncrypt(JSON.stringify(json), pubkeystr)
|
|
33
|
+
// 3. 请求登录接口
|
|
32
34
|
return req({
|
|
33
35
|
url: `/v3/auth/hctoken`,
|
|
34
36
|
data: {
|
package/package.json
CHANGED
package/utils/rsaEncrypt.ts
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RSA 加密(登录账号密码加密)
|
|
3
|
+
* jsencrypt 依赖 window/self/navigator/crypto.getRandomValues 等浏览器全局对象,
|
|
4
|
+
* 在 uni-app App 端(部分 webview 或 nvue 环境)可能缺失导致加密抛错。
|
|
5
|
+
* 这里在 import 之后、实例化之前补齐所需的全局对象,保证多端可用。
|
|
6
|
+
*/
|
|
1
7
|
import { JSEncrypt } from 'jsencrypt'
|
|
2
8
|
|
|
9
|
+
// 补齐 jsencrypt 依赖的全局对象(App 端缺失时)
|
|
10
|
+
function ensureBrowserEnv() {
|
|
11
|
+
const root: any =
|
|
12
|
+
typeof globalThis !== 'undefined'
|
|
13
|
+
? globalThis
|
|
14
|
+
: typeof global !== 'undefined'
|
|
15
|
+
? global
|
|
16
|
+
: typeof window !== 'undefined'
|
|
17
|
+
? window
|
|
18
|
+
: undefined
|
|
19
|
+
|
|
20
|
+
if (!root) return
|
|
21
|
+
|
|
22
|
+
if (typeof (root as any).self === 'undefined') {
|
|
23
|
+
try {
|
|
24
|
+
root.self = root
|
|
25
|
+
} catch (e) {
|
|
26
|
+
/* ignore */
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (typeof (root as any).window === 'undefined') {
|
|
30
|
+
try {
|
|
31
|
+
root.window = root
|
|
32
|
+
} catch (e) {
|
|
33
|
+
/* ignore */
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (typeof (root as any).navigator === 'undefined') {
|
|
37
|
+
try {
|
|
38
|
+
root.navigator = { userAgent: '', platform: 'app' }
|
|
39
|
+
} catch (e) {
|
|
40
|
+
/* ignore */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!root.crypto) {
|
|
44
|
+
try {
|
|
45
|
+
root.crypto = {}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
/* ignore */
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (root.crypto && typeof root.crypto.getRandomValues !== 'function') {
|
|
51
|
+
root.crypto.getRandomValues = function (array: any) {
|
|
52
|
+
for (let i = 0; i < array.length; i++) {
|
|
53
|
+
const bits = array.BYTES_PER_ELEMENT ? array.BYTES_PER_ELEMENT * 8 : 32
|
|
54
|
+
array[i] = Math.floor(Math.random() * Math.pow(2, bits))
|
|
55
|
+
}
|
|
56
|
+
return array
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
3
61
|
// 加密
|
|
4
62
|
function rsaEncrypt(word: string, keyStr: string) {
|
|
63
|
+
ensureBrowserEnv()
|
|
5
64
|
const encrypt = new JSEncrypt()
|
|
6
65
|
encrypt.setPublicKey(keyStr)
|
|
7
66
|
return encrypt.encrypt(word)
|