wui-components-v2 1.2.52 → 1.2.53

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 CHANGED
@@ -26,9 +26,12 @@ export async function login(
26
26
  password,
27
27
  datetime,
28
28
  }
29
+ // 1. 获取公钥
29
30
  const res = await pubKey()
30
31
  const pubkeystr = res.rasPubkey
32
+ // 2. 用公钥加密账号密码
31
33
  const userInfo = rsaEncrypt(JSON.stringify(json), pubkeystr)
34
+ // 3. 请求登录接口
32
35
  return req({
33
36
  url: `/v3/auth/hctoken`,
34
37
  data: {
@@ -126,6 +126,7 @@ function handleSubmit() {
126
126
  } catch (error: any) {
127
127
  // 登录接口返回 status: 'error' 时,core/index.ts 会 reject 整个 res
128
128
  // 该函数内部已通过 uni.showToast 提示错误,这里仅触发验证码显示
129
+ console.error('[login-form] 登录调用异常:', error)
129
130
  handleGetCaptcha()
130
131
  }
131
132
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.2.52",
3
+ "version": "1.2.53",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",
@@ -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)