@brushes/component-core 2.0.2 → 2.0.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@brushes/component-core",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "main": "src/index.ts",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  "@brushes/context": "*",
23
23
  "@babel/standalone": "^7.23.7",
24
24
  "@brushes/form": "^3.0.4",
25
+ "@brushes/request": "^2.0.2",
25
26
  "@craftjs/core": "^0.2.12",
26
27
  "antd": "^5.24.5",
27
28
  "lodash": "^4.17.21",
@@ -201,7 +201,7 @@ export const OutContainer = (props: any) => {
201
201
  </ModuleProvider>
202
202
  );
203
203
  };
204
- export const ContainerWrap = ({ width, background, children, backgroundImage, height, $$_style = '', $_style = '', ...props }: any) => {
204
+ export const ContainerWrap = ({ width, reduceSize=110, background, children, backgroundImage, height, $$_style = '', $_style = '', ...props }: any) => {
205
205
  const {
206
206
  connectors: { connect, drag }
207
207
  } = useNode();
@@ -217,7 +217,7 @@ export const ContainerWrap = ({ width, background, children, backgroundImage, he
217
217
  width,
218
218
  paddingBottom: 5,
219
219
  background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
220
- minHeight: `calc(${height}vh - 110px)`
220
+ minHeight: `calc(${height}vh - ${reduceSize}px)`
221
221
  }}
222
222
  >
223
223
  <Inner root={true} enabled={enabled}>
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
2
2
  import { Form, Spin } from 'antd';
3
3
  import { dynamicFormFields } from '@brushes/form';
4
4
  import { createStyles } from 'antd-style';
5
+ import { get, toImageDataUrl } from '@brushes/request';
5
6
  import { encryptBySM2 } from '../tool';
6
7
 
7
8
  const useStyle = createStyles(({ token, css }, { height }: { height: number }) => {
@@ -13,6 +14,7 @@ const useStyle = createStyles(({ token, css }, { height }: { height: number }) =
13
14
  `
14
15
  };
15
16
  });
17
+
16
18
  export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', codeKey, height = 40, encryption = true }: { api?: string; codeKey?: string; height?: number; encryption?: boolean }) => {
17
19
  const { styles } = useStyle({ height });
18
20
  const form = Form.useFormInstance();
@@ -27,7 +29,6 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
27
29
  }, [isDisabled]);
28
30
 
29
31
  const fetchCode = async () => {
30
- setLoading(true);
31
32
  const { getFieldsValue } = form;
32
33
  const { loginName, userPhone, userinfoConPhone, ...rest } = getFieldsValue();
33
34
 
@@ -35,25 +36,21 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
35
36
  if (codeKey) {
36
37
  params = rest[codeKey];
37
38
  }
39
+ if (!params) return;
38
40
 
39
- let userPhoneParam = params;
40
- if (encryption) {
41
- userPhoneParam = encodeURIComponent(await encryptBySM2(params));
41
+ setLoading(true);
42
+ try {
43
+ // 加密后的手机号原样交给 request 编码;这里不能再 encodeURIComponent,否则会二次编码
44
+ const userPhoneParam = encryption ? await encryptBySM2(params) : params;
45
+ // 按 @brushes/request 文档:get(url, params),二进制用第三个参数 responseType
46
+ const res = await get(api, { userPhone: userPhoneParam, t: Date.now() }, { responseType: 'arraybuffer' });
47
+ setVerImg(toImageDataUrl(res));
48
+ } catch (error) {
49
+ // 图形验证码拿不到时保留占位,不弹全局错误,不打断用户填表
50
+ setVerImg('');
51
+ } finally {
52
+ setLoading(false);
42
53
  }
43
-
44
- fetch(`${api}?userPhone=${userPhoneParam}`)
45
- .then((code) => {
46
- return code;
47
- })
48
- .then((res) => res.arrayBuffer())
49
- .then((res) => {
50
- const imgUrl = 'data:image/png;base64,' + window.btoa(String.fromCharCode(...new Uint8Array(res)));
51
- setVerImg(imgUrl);
52
- })
53
- .catch((error: any) => {})
54
- .finally(() => {
55
- setLoading(false);
56
- });
57
54
  };
58
55
  return (
59
56
  <div className={styles.wrap}>
@@ -69,7 +66,7 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
69
66
  autoComplete: 'off',
70
67
  placeholder: '请输入',
71
68
  addonAfter: (
72
- <Spin spinning={loading}>{verImg ? <img src={verImg} onClick={fetchCode} style={{ width: 90, height: height - 2 }} /> : <div style={{ width: 90, height: height - 2 }}></div>}</Spin>
69
+ <Spin spinning={loading}>{verImg ? <img src={verImg} onClick={fetchCode} style={{ width: 90, height: height - 2, cursor: 'pointer' }} /> : <div style={{ width: 90, height: height - 2 }}></div>}</Spin>
73
70
  ),
74
71
  style: {
75
72
  height