@hzab/form-render-mobile 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -9,19 +9,47 @@
9
9
  ## 示例
10
10
 
11
11
  ```jsx
12
+ import { useRef } from "react";
12
13
  import FormRender from "@hzab/form-render-mobile";
13
- import Schema from './test.schema.json'
14
14
 
15
- <FormRender schema={schema} />;
15
+ import Schema from "./test.schema.json";
16
+
17
+ export default () => {
18
+ const formRef = useRef({
19
+ formRender: Object,
20
+ });
21
+
22
+ function onClick() {
23
+ console.log(JSON.stringify(formRef?.current?.formRender.values));
24
+ }
25
+
26
+ return (
27
+ <div>
28
+ <FormRender ref={formRef} schema={Schema} initialValues={ipt:'xxxxssss'} />
29
+ <button onClick={onClick}>提交</button>
30
+ </div>
31
+ );
32
+ };
16
33
  ```
17
34
 
18
35
  ## API
19
36
 
20
37
  ### InfoPanel Attributes
21
38
 
22
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
23
- | ------ | ------ | ---- | ------ | ----------------- | --- |
24
- | schema | Object | 是 | - | 数据信息的 schema | |
39
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
40
+ | ------------- | --------------------- | ---- | ------ | ----------------------------- | --- |
41
+ | schema | Object | 是 | - | 数据信息的 schema | |
42
+ | className | string | 否 | - | 元素类名 | |
43
+ | initialValues | Object | 否 | - | 表单初始值 | |
44
+ | schemaScope | Object | 否 | - | formily scope 自定义数据 | |
45
+ | components | SchemaReactComponents | 否 | - | formily 自定义组件 | |
46
+ | readOnly | boolean | 否 | - | 是否只读 | |
47
+ | disabled | boolean | 否 | - | 是否禁用 | |
48
+ | formOptions | Object | 否 | - | createForm 配置项 | |
49
+ | hasSubmit | boolean | 否 | - | 是否有提交按钮 | |
50
+ | onSubmit | Function | 否 | - | 提交事件 (values): void | |
51
+ | init | Function | 否 | - | 组件初始化 (form): void | |
52
+ | footerRender | Function | 否 | - | 底部渲染插槽 (): ReactElement | |
25
53
 
26
54
  # 组件开发流程
27
55
 
@@ -39,7 +67,8 @@ import Schema from './test.schema.json'
39
67
  ## 命令
40
68
 
41
69
  - Mac 执行该命令,设置 pre-commit 为可执行文件
42
- - npm run mac-chmod
70
+
71
+ - npm run mac-chmod
43
72
  - chmod +x .husky && chmod +x .husky/pre-commit
44
73
 
45
74
  - 生成文档:npm run docs
package/lib/index.js CHANGED
@@ -44638,7 +44638,9 @@
44638
44638
  var t = e.precision,
44639
44639
  n = e.className,
44640
44640
  r = Yg(e, Gg);
44641
- return o().createElement(_d, Wv({ className: "number-picker ".concat(n) }, r, { digits: t }));
44641
+ return r.readOnly
44642
+ ? r.value || ""
44643
+ : o().createElement(_d, Wv({ className: "number-picker ".concat(n) }, r, { digits: t }));
44642
44644
  },
44643
44645
  (0, sh.mapProps)(function (e, t) {
44644
44646
  return qg(qg({}, e), {}, { form: t.form, field: t });
@@ -46464,6 +46466,21 @@
46464
46466
  sh.FormProvider,
46465
46467
  { form: a },
46466
46468
  o().createElement(r, { schema: s }),
46469
+ !1 !== t.hasSubmit
46470
+ ? o().createElement(
46471
+ Sp,
46472
+ null,
46473
+ o().createElement(
46474
+ Cv,
46475
+ {
46476
+ onSubmit: function (e) {
46477
+ t.onSubmit && t.onSubmit(e);
46478
+ },
46479
+ },
46480
+ "提交",
46481
+ ),
46482
+ )
46483
+ : null,
46467
46484
  o().createElement("div", { className: "form-render-footer" }, t.footerRender && t.footerRender()),
46468
46485
  ),
46469
46486
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render-mobile",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "formily-form-render-mobile",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -21,10 +21,12 @@
21
21
  "author": "CaiYansong",
22
22
  "license": "ISC",
23
23
  "devDependencies": {
24
+ "@ant-design/icons": "^4.8.1",
24
25
  "@hzab/permissions": "0.0.4",
25
26
  "@hzab/webpack-config": "0.0.12",
26
27
  "@types/react": "^17.0.62",
27
28
  "@types/react-dom": "^17.0.20",
29
+ "antd": "^4.24.13",
28
30
  "axios": "^1.4.0",
29
31
  "babel-plugin-import": "^1.13.8",
30
32
  "eslint": "^8.30.0",
@@ -38,11 +40,9 @@
38
40
  "typescript": "^4.9.4"
39
41
  },
40
42
  "dependencies": {
41
- "@ant-design/icons": "^4.8.1",
42
43
  "@formily/antd-mobile": "^1.0.0-beta.3",
43
44
  "@formily/core": "^2.2.29",
44
45
  "@formily/react": "^2.2.29",
45
- "antd": "^4.24.13",
46
46
  "antd-mobile": "^5.32.0",
47
47
  "antd-mobile-icons": "^0.2.2",
48
48
  "leaflet": "^1.9.4",
@@ -5,6 +5,9 @@ import { Stepper } from "antd-mobile";
5
5
  import "./index.less";
6
6
 
7
7
  function NumberPicker({ precision, className, ...props }) {
8
+ if (props.readOnly) {
9
+ return props.value || "";
10
+ }
8
11
  return <Stepper className={`number-picker ${className}`} {...props} digits={precision} />;
9
12
  }
10
13
 
package/src/index.tsx CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  Submit,
18
18
  Reset,
19
19
  } from "@formily/antd-mobile";
20
- import { Dialog, Slider } from "antd-mobile";
20
+ import { Slider } from "antd-mobile";
21
21
  import { createForm } from "@formily/core";
22
22
  import { FormProvider, createSchemaField, Schema } from "@formily/react";
23
23
 
@@ -83,15 +83,17 @@ const FormRender = forwardRef((props: formPropsI, parentRef) => {
83
83
  <FormProvider form={formRender}>
84
84
  {/* @ts-ignore */}
85
85
  <SchemaField schema={schema} />
86
- {/* <FormButtonGroup>
87
- <Submit
88
- onSubmit={(e) => {
89
- console.log(e);
90
- }}
91
- >
92
- 提交
93
- </Submit>
94
- </FormButtonGroup> */}
86
+ {props.hasSubmit !== false ? (
87
+ <FormButtonGroup>
88
+ <Submit
89
+ onSubmit={(values) => {
90
+ props.onSubmit && props.onSubmit(values);
91
+ }}
92
+ >
93
+ 提交
94
+ </Submit>
95
+ </FormButtonGroup>
96
+ ) : null}
95
97
  <div className="form-render-footer">{props.footerRender && props.footerRender()}</div>
96
98
  </FormProvider>
97
99
  </div>
package/src/type.d.ts CHANGED
@@ -1,15 +1,34 @@
1
- import { SchemaReactComponents, Schema } from "@formily/react";
2
1
  import { ReactElement } from "react";
2
+ import { SchemaReactComponents, Schema } from "@formily/react";
3
+ import { Form } from "@formily/core";
3
4
 
4
5
  export interface formPropsI {
6
+ /** 元素类名 */
5
7
  className?: string;
8
+ /** 表单初始值 */
6
9
  initialValues?: Object;
10
+ /** 表单 schema */
7
11
  schema: { schema: Object } | Object;
12
+ /** formily scope 自定义数据 */
8
13
  schemaScope?: Object;
14
+ /** formily 自定义组件 */
9
15
  components?: SchemaReactComponents;
16
+ /** 是否只读 */
10
17
  readOnly?: boolean;
18
+ /** 是否禁用 */
11
19
  disabled?: boolean;
20
+ /** createForm 配置项 */
12
21
  formOptions?: Object;
22
+ /** 是否有提交按钮 */
23
+ hasSubmit?: boolean;
24
+ /** 提交事件 */
25
+ onSubmit?(values): void;
26
+ /** 组件初始化 */
13
27
  init?(form): void;
28
+ /** 底部渲染插槽 */
14
29
  footerRender?(): ReactElement;
15
30
  }
31
+
32
+ export interface formRefI {
33
+ formRender: Form;
34
+ }