vap1 0.1.4 → 0.1.6

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.
Files changed (130) hide show
  1. package/components/SearchBar/ByField.js +7 -1
  2. package/components/SearchBar/ByKeyword.js +52 -10
  3. package/components/Tables/STable.d.ts +9 -1
  4. package/components/Tables/STable.js +20 -5
  5. package/components/Tables/VTable.js +18 -10
  6. package/components/Trees/ActionTree.js +0 -1
  7. package/components/Trees/COTree/COSelect.d.ts +45 -0
  8. package/components/Trees/COTree/COSelect.js +107 -0
  9. package/components/Trees/COTree/COTree.d.ts +74 -0
  10. package/components/Trees/COTree/COTree.js +207 -0
  11. package/components/Trees/COTree/COTreeUtil.d.ts +17 -0
  12. package/components/Trees/COTree/COTreeUtil.js +187 -0
  13. package/components/UForm/UForm.js +0 -1
  14. package/components/UForm/UFormModal.js +1 -1
  15. package/components/UForm/_FieldType.d.ts +1 -1
  16. package/components/UForm/_FieldType.js +10 -2
  17. package/components/UForm/index.d.ts +10 -0
  18. package/components/_adapt/Drawer.js +1 -1
  19. package/components/_adapt/Dropdown.d.ts +12 -3
  20. package/components/_adapt/Dropdown.js +10 -2
  21. package/components/_adapt/Modal.js +1 -1
  22. package/components/_adapt/Radio.js +6 -6
  23. package/components/_common/Upagination.js +4 -4
  24. package/components/_setup/UForm/UFormCOTree.d.ts +1 -0
  25. package/components/_setup/UForm/UFormCOTree.js +23 -0
  26. package/components/_setup/UForm/UFormDate.js +99 -24
  27. package/components/_setup/UForm/UFormJSONTable.d.ts +1 -0
  28. package/components/_setup/UForm/UFormJSONTable.js +157 -0
  29. package/components/_setup/UForm/UFormSelect.js +19 -0
  30. package/components/_setup/index.d.ts +1 -0
  31. package/components/_setup/index.js +1 -0
  32. package/hooks/_list.js +2 -1
  33. package/hooks/useArray.d.ts +2 -3
  34. package/hooks/useArray.js +34 -67
  35. package/index.d.ts +1 -1
  36. package/package.json +1 -1
  37. package/uform/FormEditor.d.ts +21 -0
  38. package/uform/FormEditor.js +101 -0
  39. package/uform/FormViewer.d.ts +12 -0
  40. package/uform/FormViewer.js +71 -0
  41. package/uform/hooks/useEditor.d.ts +28 -0
  42. package/uform/hooks/useEditor.js +144 -0
  43. package/uform/hooks/useForm.d.ts +4 -0
  44. package/uform/hooks/useForm.js +7 -0
  45. package/uform/index.d.ts +5 -0
  46. package/uform/index.js +35 -0
  47. package/uform/inputs/_advance.d.ts +2 -0
  48. package/uform/inputs/_advance.js +57 -0
  49. package/uform/inputs/_date.d.ts +2 -0
  50. package/uform/inputs/_date.js +178 -0
  51. package/uform/inputs/_input.d.ts +6 -0
  52. package/uform/inputs/_input.js +139 -0
  53. package/uform/inputs/_select.d.ts +2 -0
  54. package/uform/inputs/_select.js +241 -0
  55. package/uform/inputs/_specific.d.ts +2 -0
  56. package/uform/inputs/_specific.js +107 -0
  57. package/uform/inputs/index.d.ts +6 -0
  58. package/uform/inputs/index.js +18 -0
  59. package/uform/inputs/register.d.ts +25 -0
  60. package/uform/inputs/register.js +47 -0
  61. package/uform/panel/Editor/GroupEditor.d.ts +7 -0
  62. package/uform/panel/Editor/GroupEditor.js +126 -0
  63. package/uform/panel/Editor/ListEditor.d.ts +4 -0
  64. package/uform/panel/Editor/ListEditor.js +77 -0
  65. package/uform/panel/Editor/_FieldItems.d.ts +5 -0
  66. package/uform/panel/Editor/_FieldItems.js +45 -0
  67. package/uform/panel/Editor/_GroupCollapse.d.ts +3 -0
  68. package/uform/panel/Editor/_GroupCollapse.js +24 -0
  69. package/uform/panel/Editor/_GroupDefault.d.ts +3 -0
  70. package/uform/panel/Editor/_GroupDefault.js +24 -0
  71. package/uform/panel/Editor/_GroupStep.d.ts +3 -0
  72. package/uform/panel/Editor/_GroupStep.js +49 -0
  73. package/uform/panel/Editor/_GroupTab.d.ts +3 -0
  74. package/uform/panel/Editor/_GroupTab.js +41 -0
  75. package/uform/panel/Editor/index.d.ts +3 -0
  76. package/uform/panel/Editor/index.js +83 -0
  77. package/uform/panel/Items/index.d.ts +3 -0
  78. package/uform/panel/Items/index.js +23 -0
  79. package/uform/panel/Propreties/CanvasProperties.d.ts +3 -0
  80. package/uform/panel/Propreties/CanvasProperties.js +42 -0
  81. package/uform/panel/Propreties/Component/FieldPlugin.d.ts +12 -0
  82. package/uform/panel/Propreties/Component/FieldPlugin.js +39 -0
  83. package/uform/panel/Propreties/Component/LinkAsyncFunction.d.ts +8 -0
  84. package/uform/panel/Propreties/Component/LinkAsyncFunction.js +171 -0
  85. package/uform/panel/Propreties/Component/LinkSyncFunction.d.ts +8 -0
  86. package/uform/panel/Propreties/Component/LinkSyncFunction.js +149 -0
  87. package/uform/panel/Propreties/Component/Links.d.ts +3 -0
  88. package/uform/panel/Propreties/Component/Links.js +114 -0
  89. package/uform/panel/Propreties/Component/OptionTable.d.ts +3 -0
  90. package/uform/panel/Propreties/Component/OptionTable.js +144 -0
  91. package/uform/panel/Propreties/Component/RegexpModal.d.ts +5 -0
  92. package/uform/panel/Propreties/Component/RegexpModal.js +74 -0
  93. package/uform/panel/Propreties/Component/Validate.d.ts +3 -0
  94. package/uform/panel/Propreties/Component/Validate.js +93 -0
  95. package/uform/panel/Propreties/Component/ValidateAsyncFunction.d.ts +3 -0
  96. package/uform/panel/Propreties/Component/ValidateAsyncFunction.js +83 -0
  97. package/uform/panel/Propreties/Component/ValidateSyncFunction.d.ts +3 -0
  98. package/uform/panel/Propreties/Component/ValidateSyncFunction.js +77 -0
  99. package/uform/panel/Propreties/FieldOptions.d.ts +6 -0
  100. package/uform/panel/Propreties/FieldOptions.js +131 -0
  101. package/uform/panel/Propreties/FieldProperties.d.ts +3 -0
  102. package/uform/panel/Propreties/FieldProperties.js +60 -0
  103. package/uform/panel/Propreties/GroupProperties.d.ts +3 -0
  104. package/uform/panel/Propreties/GroupProperties.js +17 -0
  105. package/uform/panel/Propreties/_ItemAdvance.d.ts +4 -0
  106. package/uform/panel/Propreties/_ItemAdvance.js +140 -0
  107. package/uform/panel/Propreties/_ItemBase.d.ts +4 -0
  108. package/uform/panel/Propreties/_ItemBase.js +34 -0
  109. package/uform/panel/Propreties/_ItemLink.d.ts +4 -0
  110. package/uform/panel/Propreties/_ItemLink.js +15 -0
  111. package/uform/panel/Propreties/_ItemValidate.d.ts +4 -0
  112. package/uform/panel/Propreties/_ItemValidate.js +67 -0
  113. package/uform/panel/Propreties/_util.d.ts +9 -0
  114. package/uform/panel/Propreties/_util.js +2 -0
  115. package/uform/plugins/index.d.ts +15 -0
  116. package/uform/plugins/index.js +47 -0
  117. package/uform/schema.d.ts +155 -0
  118. package/uform/schema.js +2 -0
  119. package/uform/utils/Const.d.ts +20 -0
  120. package/uform/utils/Const.js +24 -0
  121. package/uform/utils/Convert.d.ts +3 -0
  122. package/uform/utils/Convert.js +274 -0
  123. package/uform/utils/SchemaConvert.d.ts +6 -0
  124. package/uform/utils/SchemaConvert.js +169 -0
  125. package/uform/utils/arr.d.ts +12 -0
  126. package/uform/utils/arr.js +175 -0
  127. package/utils/ArrayUtil.js +8 -1
  128. package/utils/Global.d.ts +0 -1
  129. package/utils/index.d.ts +32 -1
  130. package/widget/index.d.ts +0 -4
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const lodash_1 = __importDefault(require("lodash"));
31
+ const utils_1 = require("../../../utils");
32
+ const index_1 = require("../../../index");
33
+ const components_1 = require("../../../components");
34
+ const hooks_1 = require("../../../hooks");
35
+ const renderColumn = (txt, column) => {
36
+ if (column.options) {
37
+ let find = lodash_1.default.find(column.options, { value: txt });
38
+ if (find) {
39
+ return find.name;
40
+ }
41
+ }
42
+ return txt;
43
+ };
44
+ // json-table 不支持被联动,可联动其它
45
+ // 基础组件 JSON 数组, json-array 升级版本,适用于复杂的表格
46
+ (0, components_1.registerFormField)('json-table', props => {
47
+ const { field, disabled, value, } = props;
48
+ const config = field.config;
49
+ const rowKey = lodash_1.default.has(config, 'rowKey') ? config.rowKey : 'id';
50
+ const { modalState: { modalProps }, showAdd, showEdit, showInfo, hide } = (0, hooks_1.useModals)();
51
+ const onChange = (arr) => {
52
+ if (field.dataType == 'array') {
53
+ props.onChange(arr);
54
+ }
55
+ else {
56
+ props.onChange(JSON.stringify(arr));
57
+ }
58
+ };
59
+ const arr = (0, react_1.useMemo)(() => {
60
+ let arr = [];
61
+ if (lodash_1.default.isArray(value)) {
62
+ arr = [...props.value];
63
+ }
64
+ else if (lodash_1.default.isString(value)) {
65
+ try {
66
+ arr = JSON.parse(value);
67
+ if (!lodash_1.default.isArray(arr))
68
+ arr = [];
69
+ }
70
+ catch (_a) { }
71
+ }
72
+ arr.map(item => {
73
+ if (!lodash_1.default.has(item, rowKey)) {
74
+ lodash_1.default.set(item, rowKey, utils_1.StringUtil.genKey());
75
+ }
76
+ });
77
+ return arr;
78
+ }, [value]);
79
+ const formFields = (0, react_1.useMemo)(() => {
80
+ if (lodash_1.default.has(config, 'formFields'))
81
+ return config.formFields;
82
+ let fields = [];
83
+ config.columns.map((col) => {
84
+ let field = { field: col.dataIndex, title: col.title, };
85
+ if (col.type)
86
+ field.type = col.type;
87
+ if (col.required)
88
+ field.required = true;
89
+ if (lodash_1.default.isArray(col.options))
90
+ field.options = col.options;
91
+ fields.push(field);
92
+ });
93
+ return fields;
94
+ }, []);
95
+ const tableColumns = (0, react_1.useMemo)(() => {
96
+ let columns = [];
97
+ config.columns.map((item) => {
98
+ let col = lodash_1.default.omit(item, ['type', 'options', 'required']);
99
+ if (!col.render && lodash_1.default.isArray(item.options)) {
100
+ col.render = utils_1.Renders.ListRender(item.options);
101
+ }
102
+ columns.push(col);
103
+ });
104
+ return columns;
105
+ }, []);
106
+ const add = (0, react_1.useCallback)((data) => onChange(utils_1.ArrayUtil.add(arr, Object.assign(Object.assign({}, data), { [rowKey]: utils_1.StringUtil.genKey() }))), [arr]);
107
+ const update = (0, react_1.useCallback)((data) => onChange(utils_1.ArrayUtil.update(arr, data, rowKey)), [arr]);
108
+ const del = (0, react_1.useCallback)((data) => onChange(utils_1.ArrayUtil.del(arr, data, rowKey)), [arr]);
109
+ return react_1.default.createElement(react_1.default.Fragment, null,
110
+ react_1.default.createElement(index_1.STable, { list: arr, locale: {
111
+ emptyText: react_1.default.createElement(index_1.Empty, { description: react_1.default.createElement(index_1.Button, { type: "primary", icon: "plus", onClick: showAdd },
112
+ "\u6DFB\u52A0",
113
+ field.title) })
114
+ }, columns: [
115
+ ...tableColumns,
116
+ index_1.VTable.COL_OPERACTION((record) => [
117
+ react_1.default.createElement(index_1.VTable.INFO, { onClick: () => showInfo(record) }),
118
+ react_1.default.createElement(index_1.VTable.EDIT, { onClick: () => showEdit(record) }),
119
+ react_1.default.createElement(index_1.VTable.DELETE, { onClick: () => del(record) }),
120
+ ])
121
+ ], pagination: false, footer: () => {
122
+ if (arr.length == 0 || disabled) {
123
+ return null;
124
+ }
125
+ return react_1.default.createElement(index_1.Button, { type: "primary", icon: "plus", onClick: showAdd },
126
+ "\u6DFB\u52A0",
127
+ field.title);
128
+ } }),
129
+ react_1.default.createElement(index_1.UModal, Object.assign({}, modalProps, { autoTitle: field.title, fields: formFields, default: config.formDefault || {}, onOk: (data) => {
130
+ hide();
131
+ if (modalProps.isEdit) {
132
+ update(data);
133
+ }
134
+ else {
135
+ add(data);
136
+ }
137
+ } })));
138
+ }, {
139
+ breakCol: true,
140
+ breakTitle: true,
141
+ render: (value, data, field) => {
142
+ let list = [];
143
+ try {
144
+ list = JSON.parse(value);
145
+ }
146
+ catch (e) {
147
+ console.error(e);
148
+ }
149
+ return react_1.default.createElement(index_1.STable
150
+ // className="c-table json-array-table"
151
+ // size="small"
152
+ , {
153
+ // className="c-table json-array-table"
154
+ // size="small"
155
+ locale: { emptyText: react_1.default.createElement(index_1.Empty, { description: "\u6682\u65E0\u6570\u636E" }) }, list: list, columns: field.config.columns.map(item => (Object.assign(Object.assign({}, item), { render: (txt) => renderColumn(txt, item) }))), pagination: false });
156
+ }
157
+ });
@@ -82,6 +82,25 @@ const Const_1 = require("../Const");
82
82
  onChange(isCheck ? field.options[CHECKED].value : field.options[UNCHECKED].value);
83
83
  } }));
84
84
  });
85
+ // 用法与 switch 相同
86
+ (0, _register_1.registerFormField)('switch-checkbox', (props) => {
87
+ const { field, disabled, value, onChange, options } = props;
88
+ if (options.length <= 1) {
89
+ console.warn('Type Switch Must have 2 Options');
90
+ return utils_1.Const.NONE;
91
+ }
92
+ let CHECKED = utils_1.GLOBAL.CONFIG.FORM.SWITCH_DEFAULT_CHECKED;
93
+ if (lodash_1.default.has(field.config, 'reverse') && field.config.reverse)
94
+ CHECKED = 1 - CHECKED;
95
+ let UNCHECKED = 1 - CHECKED;
96
+ const isCheck = value == field.options[CHECKED].value;
97
+ return react_1.default.createElement(antd_1.Checkbox, Object.assign({}, field.config, { disabled: disabled, checked: isCheck, onChange: evt => {
98
+ utils_1.PageUtil.stopEvent(evt.nativeEvent);
99
+ const checked = evt.target.checked;
100
+ onChange(checked ? field.options[CHECKED].value : field.options[UNCHECKED].value);
101
+ } }),
102
+ react_1.default.createElement("span", { style: { userSelect: 'none' } }, isCheck ? field.options[CHECKED].label : field.options[UNCHECKED].label));
103
+ });
85
104
  // 单选
86
105
  (0, _register_1.registerFormField)('radio', (props) => {
87
106
  const { field, disabled, value, onChange, options } = props;
@@ -16,6 +16,7 @@ import './UForm/UFormRole';
16
16
  import './UForm/UFormOrg';
17
17
  import './UForm/UFormSearch';
18
18
  import './UForm/UFormJSON';
19
+ import './UForm/UFormJSONTable';
19
20
  import './UForm/UFormCrontab';
20
21
  import './UForm/UFormAdvanceInput';
21
22
  import './UForm/UFormAdvanceSelect';
@@ -20,6 +20,7 @@ require("./UForm/UFormRole"); // 高阶类型:角色
20
20
  require("./UForm/UFormOrg"); // 高阶类型:机构
21
21
  require("./UForm/UFormSearch"); // 高阶类型:自动填充/自动搜索(API接口获取数据)
22
22
  require("./UForm/UFormJSON"); // 高阶类型:JSON Array, JSON Object
23
+ require("./UForm/UFormJSONTable"); // 高阶类型:JSON Array 升级版本
23
24
  require("./UForm/UFormCrontab"); // 高阶类型:Crontab
24
25
  require("./UForm/UFormAdvanceInput"); // 高阶类型:高级输入
25
26
  require("./UForm/UFormAdvanceSelect"); // 高阶类型:高级选择
package/hooks/_list.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_STATE = void 0;
4
+ const Global_1 = require("../utils/Global");
4
5
  exports.DEFAULT_STATE = {
5
6
  rowKey: 'id',
6
7
  list: [],
7
8
  isQuerying: false,
8
9
  pageNo: 1,
9
- pageSize: 15,
10
+ pageSize: Global_1.CONFIG.PAGINATION.SIZE_DEFAULT,
10
11
  total: 0,
11
12
  totalAcc: 0,
12
13
  param: {},
@@ -1,5 +1,5 @@
1
1
  import type { StaticListState, ListInit } from './_list';
2
- type ArrayOption = ListInit & {
2
+ export type UseArrayOption = ListInit & {
3
3
  /**
4
4
  * 页面大小,默认为 VLIST 大小
5
5
  * 默认为 0 :为0时,不分页,非0时分页
@@ -17,5 +17,4 @@ type ArrayOption = ListInit & {
17
17
  * 静态数组 Table,支持 CRUD(不调接口)
18
18
  * 同样适用于 VTable 等组件
19
19
  */
20
- export declare const useArray: (options: ArrayOption) => StaticListState;
21
- export {};
20
+ export declare const useArray: (options: UseArrayOption) => StaticListState;
package/hooks/useArray.js CHANGED
@@ -46,21 +46,43 @@ const getList = (result) => {
46
46
  * 同样适用于 VTable 等组件
47
47
  */
48
48
  const useArray = (options) => {
49
- const AllRef = (0, react_1.useRef)(null);
50
- const BASE = Object.assign(Object.assign({}, _list_1.DEFAULT_STATE), { pageSize: 0 });
49
+ const [ALL, setList] = (0, react_1.useState)(options.list || []);
50
+ const BASE = Object.assign(Object.assign({}, _list_1.DEFAULT_STATE), { pageSize: 0, list: [] });
51
51
  if (options.rowKey)
52
52
  BASE.rowKey = options.rowKey;
53
- let lastQueryRef = (0, react_1.useRef)(options.param || {});
54
- let pageToRef = (0, react_1.useRef)(null);
55
- let orderByRef = (0, react_1.useRef)(null);
56
53
  if (options.pageSize && options.pageSize > 0)
57
54
  BASE.pageSize = options.pageSize;
55
+ let lastQueryRef = (0, react_1.useRef)(options.param || {});
56
+ let pageToRef = (0, react_1.useRef)({ pageNo: 1, pageSize: BASE.pageSize > 0 ? BASE.pageSize : 99999 });
57
+ let orderByRef = (0, react_1.useRef)(null);
58
58
  const [state, setState] = (0, useSetState_1.useSetState)(BASE);
59
+ (0, useEffectFunction_1.useEffectFunction)(() => __awaiter(void 0, void 0, void 0, function* () {
60
+ if (ALL.length > 0 || options.api == null)
61
+ return;
62
+ setState({ isQuerying: true });
63
+ const param = options.param || {};
64
+ let response;
65
+ if (options.param) {
66
+ response = utils_1.Ajax.POST(options.api, options.param);
67
+ }
68
+ else {
69
+ response = utils_1.Ajax.GET(options.api);
70
+ ;
71
+ }
72
+ const resp = yield response;
73
+ const list = getList(resp);
74
+ setList(list);
75
+ setState({ isQuerying: false, param });
76
+ }));
77
+ (0, react_1.useLayoutEffect)(() => {
78
+ setState({ total: ALL.length, totalAcc: ALL.length });
79
+ queryRef();
80
+ }, [ALL]);
59
81
  const queryRef = () => {
60
82
  const param = lastQueryRef.current;
61
83
  const pageTo = pageToRef.current;
62
84
  const orderBy = orderByRef.current;
63
- let list = AllRef.current.slice(0);
85
+ let list = ALL.slice(0);
64
86
  lodash_1.default.keys(param).map(field => {
65
87
  if (lodash_1.default.endsWith('_'))
66
88
  return;
@@ -76,28 +98,13 @@ const useArray = (options) => {
76
98
  list = lodash_1.default.orderBy(list, orderBy.order, orderBy.by);
77
99
  }
78
100
  if (pageTo == null) {
79
- setState({ isQuerying: false, list, total: list.length, totalAcc: list.length, param, pageNo: 1, });
101
+ setState({ isQuerying: false, list, param, pageNo: 1, total: list.length, totalAcc: list.length });
80
102
  return;
81
103
  }
82
104
  let start = pageTo.pageSize * (pageTo.pageNo - 1);
83
105
  let count = pageTo.pageSize;
84
- setState({ isQuerying: false, list: list.slice(start, count), total: list.length, totalAcc: list.length, param, pageNo: 1, });
106
+ setState({ isQuerying: false, list: list.slice(start, start + count), param, pageNo: pageTo.pageNo, pageSize: pageTo.pageSize, total: list.length, totalAcc: list.length });
85
107
  };
86
- const queryApi = () => __awaiter(void 0, void 0, void 0, function* () {
87
- const param = lastQueryRef.current;
88
- setState({ isQuerying: true });
89
- const resp = yield utils_1.Ajax.POST(options.api, param);
90
- const list = getList(resp);
91
- AllRef.current = list;
92
- const pageTo = pageToRef.current;
93
- if (pageTo == null) {
94
- setState({ isQuerying: false, list, total: list.length, totalAcc: list.length, param, pageNo: 1, });
95
- return;
96
- }
97
- let start = pageTo.pageSize * (pageTo.pageNo - 1);
98
- let count = pageTo.pageSize;
99
- setState({ isQuerying: false, list: list.slice(start, count), total: list.length, totalAcc: list.length, param, pageNo: 1, });
100
- });
101
108
  const query = (param, clean) => {
102
109
  if (clean) {
103
110
  lastQueryRef.current = param || {};
@@ -113,42 +120,20 @@ const useArray = (options) => {
113
120
  }
114
121
  if (options.pageSize && options.pageSize > 0) {
115
122
  pageToRef.current = { pageNo: 1, pageSize: options.pageSize };
123
+ setState({ pageNo: 1, pageSize: options.pageSize });
116
124
  }
117
125
  else {
118
126
  pageToRef.current = null;
119
127
  }
120
- if (options.api) {
121
- queryApi();
122
- }
123
- else if (AllRef.current != null && lodash_1.default.isArray(AllRef.current)) {
124
- queryRef();
125
- }
126
- else {
127
- console.error('list 与 api 到少需要指定一项');
128
- }
128
+ queryRef();
129
129
  };
130
- (0, useEffectFunction_1.useEffectFunction)(() => {
131
- if (lodash_1.default.isArray(options.list))
132
- AllRef.current = options.list;
133
- if (options.autoLoad !== false)
134
- query(options.param || {}, true);
135
- });
136
130
  const pageTo = (pageNo, pageSize) => {
137
- if (options.pageSize && options.pageSize > 0) {
138
- // pageToRef.current = { pageNo: 1, pageSize: options.pageSize }
131
+ if (options.pageSize == null || options.pageSize == 0) {
139
132
  console.error('静态Array默认不翻页,如果需要翻页,需要指定pageSize');
140
133
  return;
141
134
  }
142
135
  pageToRef.current = { pageNo, pageSize };
143
- if (AllRef.current != null && lodash_1.default.isArray(AllRef.current)) {
144
- queryRef();
145
- }
146
- else if (options.api) {
147
- queryApi();
148
- }
149
- else {
150
- console.error('list 与 api 到少需要指定一项');
151
- }
136
+ queryRef();
152
137
  };
153
138
  const orderBy = (order, by) => {
154
139
  if (order == null || by == null) {
@@ -157,24 +142,6 @@ const useArray = (options) => {
157
142
  else {
158
143
  orderByRef.current = { order, by };
159
144
  }
160
- if (AllRef.current != null && lodash_1.default.isArray(AllRef.current)) {
161
- queryRef();
162
- }
163
- else if (options.api) {
164
- queryApi();
165
- }
166
- else {
167
- console.error('list 与 api 到少需要指定一项');
168
- }
169
- };
170
- const setList = (list) => {
171
- AllRef.current = list.slice();
172
- if (options.pageSize && options.pageSize > 0) {
173
- pageToRef.current = { pageNo: 1, pageSize: options.pageSize };
174
- }
175
- else {
176
- pageToRef.current = null;
177
- }
178
145
  queryRef();
179
146
  };
180
147
  return Object.assign(Object.assign({}, state), { mode: 'static', query, pageTo, orderBy, setList });
package/index.d.ts CHANGED
@@ -132,7 +132,7 @@ export { VTable, ApiTable, ApiTableModal, STable, TopTable, TopTableModal } from
132
132
  export { STree, DTree, FTree } from './components/Trees';
133
133
  export { UploadFile, UploadImage, UploadModal } from './components/Upload';
134
134
  export { SList } from './components/Lists/SList';
135
- export type { UFromProps, UModalProps, UFormField, UFormFieldGroup, LinkResult, UDescriptionsProps, UFormRef } from './components/UForm';
135
+ export type { UFromProps, UModalProps, UFormField, UFormFieldGroup, LinkResult, UDescriptionsProps, UFormRef, Link, LinkValue } from './components/UForm';
136
136
  export type { TableColumn } from './components/Tables/index';
137
137
  export type { VTableProps, VTableRef } from './components/Tables/VTable';
138
138
  export type { ApiTableProps } from './components/Tables/ApiTable';
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"vap1","version":"0.1.4","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
1
+ {"name":"vap1","version":"0.1.6","description":"vap1, Both support MicroService and SAP FrameWork, Support IE>9","main":"index.js","author":"Xiang da","license":"ISC"}
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import type { FormSchema } from './schema';
3
+ /**
4
+ * TODO
5
+ * 1. input-with-select
6
+ * select 宽度
7
+ * select 位置
8
+ * 2. fieldCount>2 默认值
9
+ * 3. 默认显示/disable
10
+ * 4. tree-select
11
+ * 5. dtree-select
12
+ * 6. 所有日期:日期格式设置
13
+ * */
14
+ type FormEditorProps = {
15
+ data?: string | FormSchema;
16
+ name?: string;
17
+ onSave: (schema: string, isCtrlS?: boolean) => void;
18
+ onBack?: () => void;
19
+ };
20
+ export declare const FormEditor: React.FC<FormEditorProps>;
21
+ export {};
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.FormEditor = void 0;
30
+ const react_1 = __importStar(require("react"));
31
+ const lodash_1 = __importDefault(require("lodash"));
32
+ const index_1 = require("../index");
33
+ const index_2 = __importDefault(require("./panel/Items/index"));
34
+ const index_3 = __importDefault(require("./panel/Editor/index"));
35
+ const useForm_1 = require("./hooks/useForm");
36
+ const FormViewer_1 = require("./FormViewer");
37
+ const CanvasProperties_1 = __importDefault(require("./panel/Propreties/CanvasProperties"));
38
+ const FieldProperties_1 = __importDefault(require("./panel/Propreties/FieldProperties"));
39
+ const GroupProperties_1 = __importDefault(require("./panel/Propreties/GroupProperties"));
40
+ const useEditor_1 = require("./hooks/useEditor");
41
+ const FormViewer_2 = require("./FormViewer");
42
+ const FormEditor = (props) => {
43
+ const schema = (0, react_1.useMemo)(() => (0, FormViewer_2.initSchama)(props.data), [props.data]);
44
+ const editor = (0, useEditor_1.useFormEditor)(schema);
45
+ const [open, setOpen] = (0, react_1.useState)(false);
46
+ const save = (isCtrlS = false) => {
47
+ props.onSave(JSON.stringify(editor.getForm()), isCtrlS);
48
+ };
49
+ (0, react_1.useLayoutEffect)(() => {
50
+ const onKeyDown = (evt) => {
51
+ if (evt.ctrlKey && (evt.key == 's' || evt.key == 'S')) {
52
+ evt.preventDefault();
53
+ evt.stopPropagation();
54
+ save(true);
55
+ }
56
+ };
57
+ document.addEventListener('keydown', onKeyDown, false);
58
+ return () => document.removeEventListener('keydown', onKeyDown);
59
+ }, []);
60
+ return react_1.default.createElement(useForm_1.UFORM.Provider, { value: editor.form },
61
+ react_1.default.createElement(useEditor_1.FORM_EDITOR.Provider, { value: editor },
62
+ react_1.default.createElement(index_1.Row, { className: 'uform-editor' },
63
+ react_1.default.createElement(index_1.Col, { style: { width: 210, flexShrink: 0 } },
64
+ react_1.default.createElement(index_2.default, null)),
65
+ react_1.default.createElement(index_1.Col, { style: { flexGrow: 1 } },
66
+ react_1.default.createElement("div", { className: 'panel-title' },
67
+ "\u8868\u5355 ",
68
+ props.name && react_1.default.createElement("small", null,
69
+ react_1.default.createElement("b", null, props.name)),
70
+ react_1.default.createElement(index_1.Button.Group, { style: { float: 'right', marginRight: 6, display: 'block' } },
71
+ editor.form.isGroup && react_1.default.createElement(index_1.Button, { icon: "plus", onClick: () => editor.addGroup() }, "\u6DFB\u52A0\u5206\u7EC4"),
72
+ react_1.default.createElement(index_1.Button, { icon: 'eye', type: "primary", onClick: () => {
73
+ if (schema.fields && schema.fields.length > 1) {
74
+ setOpen(true);
75
+ }
76
+ else {
77
+ index_1.message.error('至少添加一个字段');
78
+ }
79
+ } }, "\u9884\u89C8"))),
80
+ react_1.default.createElement(index_3.default, null)),
81
+ react_1.default.createElement(index_1.Col, { style: { width: 320, flexShrink: 0 }, className: "uform-prperties" },
82
+ react_1.default.createElement("div", { className: 'panel-title' },
83
+ "\u5C5E\u6027",
84
+ react_1.default.createElement(index_1.Button.Group, { style: { float: 'right', marginRight: 6, display: 'block' } },
85
+ lodash_1.default.isFunction(props.onBack) && react_1.default.createElement(index_1.Button, { icon: 'rollback', onClick: () => props.onBack() }, "\u8FD4\u56DE"),
86
+ react_1.default.createElement(index_1.Button, { onClick: () => save(), icon: 'save', type: 'primary' }, "\u4FDD\u5B58"))),
87
+ react_1.default.createElement(index_1.Form, { className: 'panel-content', labelCol: { sm: 6 }, wrapperCol: { sm: 17 } }, editor.selected == null ? react_1.default.createElement(CanvasProperties_1.default, null) : (editor.selected.field ? react_1.default.createElement(FieldProperties_1.default, null) : react_1.default.createElement(GroupProperties_1.default, null))))),
88
+ react_1.default.createElement(FormViewer_1.FormModal, { title: editor.form.title || '表单预览', schema: editor.form, open: open, onOk: (data) => {
89
+ setOpen(false);
90
+ index_1.notification.info({
91
+ role: 'alert',
92
+ style: { padding: 0 },
93
+ icon: react_1.default.createElement(react_1.default.Fragment, null),
94
+ placement: 'top',
95
+ message: react_1.default.createElement(react_1.default.Fragment, null,
96
+ react_1.default.createElement("h4", null, "JSON \u9884\u89C8"),
97
+ react_1.default.createElement("pre", null, JSON.stringify(data, null, 1)))
98
+ });
99
+ }, onCancel: () => setOpen(false) })));
100
+ };
101
+ exports.FormEditor = FormEditor;
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import type { FormSchema } from './schema';
3
+ import type { UModalProps, PlainObject } from '../index';
4
+ type ModalProps = Pick<UModalProps, 'open' | 'onOk' | 'onCancel' | 'title' | 'data'>;
5
+ type FormViewProps = {
6
+ schema: FormSchema | string;
7
+ data?: PlainObject;
8
+ };
9
+ export declare const initSchama: (data: string | FormSchema) => FormSchema;
10
+ export declare const FormViewer: React.FC<FormViewProps>;
11
+ export declare const FormModal: React.FC<FormViewProps & ModalProps>;
12
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.FormModal = exports.FormViewer = exports.initSchama = void 0;
30
+ const lodash_1 = __importDefault(require("lodash"));
31
+ const react_1 = __importStar(require("react"));
32
+ const index_1 = require("../index");
33
+ const Convert_1 = require("./utils/Convert");
34
+ const DEFAULT = { fields: [] };
35
+ const initSchama = (data) => {
36
+ if (lodash_1.default.isString(data)) {
37
+ try {
38
+ const schema = JSON.parse(data);
39
+ if (lodash_1.default.isPlainObject(schema) && lodash_1.default.isArray(schema.fields)) {
40
+ return schema;
41
+ }
42
+ }
43
+ catch (_a) {
44
+ }
45
+ }
46
+ else if (lodash_1.default.isPlainObject(data) && lodash_1.default.isArray(data.fields)) {
47
+ return data;
48
+ }
49
+ return DEFAULT;
50
+ };
51
+ exports.initSchama = initSchama;
52
+ const _FormRender = props => {
53
+ const uformProps = (0, react_1.useMemo)(() => (0, Convert_1.schemaToForm)(props.schema), [props]);
54
+ return react_1.default.createElement(index_1.UForm, Object.assign({}, uformProps, { data: props.data }));
55
+ };
56
+ const _ModalRender = props => {
57
+ const uformProps = (0, react_1.useMemo)(() => (0, Convert_1.schemaToForm)(props.schema), [props]);
58
+ let modalProps = {};
59
+ modalProps.title = props.title || props.schema.title || '';
60
+ return react_1.default.createElement(index_1.UFormModal, Object.assign({}, uformProps, modalProps, { data: props.data, open: props.open, onOk: props.onOk, onCancel: props.onCancel }));
61
+ };
62
+ const FormViewer = props => {
63
+ const schema = (0, react_1.useMemo)(() => (0, exports.initSchama)(props.schema), [props.schema]);
64
+ return react_1.default.createElement(_FormRender, { schema: schema, data: props.data });
65
+ };
66
+ exports.FormViewer = FormViewer;
67
+ const FormModal = props => {
68
+ const schema = (0, react_1.useMemo)(() => (0, exports.initSchama)(props.schema), [props.schema]);
69
+ return react_1.default.createElement(_ModalRender, Object.assign({}, props, { schema: schema }));
70
+ };
71
+ exports.FormModal = FormModal;
@@ -0,0 +1,28 @@
1
+ /// <reference types="react" />
2
+ import type { FormGroup, FormItem, FormSchema, Cursor } from '../schema';
3
+ type CurrentSelected = {
4
+ group?: string;
5
+ field?: string;
6
+ };
7
+ type FormEditorContext = {
8
+ form: FormSchema;
9
+ selected: CurrentSelected;
10
+ baseSpan: number;
11
+ getForm: () => FormSchema;
12
+ setSelected: (selected: {
13
+ field?: string;
14
+ group?: string;
15
+ }) => void;
16
+ deleteField: (groupId?: string) => void;
17
+ addGroup: () => void;
18
+ deleteGroup: (groupId: string) => void;
19
+ getSelect: () => FormItem | FormGroup;
20
+ sortField: (itemId: string, targetPos: any, groupId?: string) => void;
21
+ addField: (type: string, pointer?: Cursor, groupId?: string) => void;
22
+ setFormProperties: (param: Partial<FormSchema>) => void;
23
+ setFieldProperties: (properties: string, value: any) => void;
24
+ };
25
+ export declare const FORM_EDITOR: import("react").Context<FormEditorContext>;
26
+ export declare const useEditor: () => FormEditorContext;
27
+ export declare const useFormEditor: (dataJson: FormSchema) => FormEditorContext;
28
+ export {};