aldehyde 0.0.1
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/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/163.js +2 -0
- package/dist/163.js.LICENSE.txt +43 -0
- package/dist/41.js +1 -0
- package/dist/aldehyde.js +2 -0
- package/dist/aldehyde.js.LICENSE.txt +122 -0
- package/dist/chemstruc-graph.js +1 -0
- package/dist/css/163-24392163d3c7b54ea806.css +11 -0
- package/dist/css/290-5e8e152675ab7d201c00.css +886 -0
- package/dist/css/chemstruc-graph-87868f791bf92fb80db9.css +29 -0
- package/dist/css/main-2e6725ec1b56da516cee.css +256 -0
- package/dist/html-editor-draft.js +2 -0
- package/dist/html-editor-draft.js.LICENSE.txt +5 -0
- package/dist/images/logo-06f6a5d8.png +0 -0
- package/dist/index.html +4 -0
- package/dist/signature.js +2 -0
- package/dist/signature.js.LICENSE.txt +17 -0
- package/package.json +180 -0
- package/src/components/chart/antd/Chart.js +32 -0
- package/src/components/chart/antd/Chart10000.js +90 -0
- package/src/components/chart/antd/Max2DimLineChart.js +128 -0
- package/src/components/chart/antd/PieChart1.js +54 -0
- package/src/components/chart/antd/PieChart2.js +56 -0
- package/src/components/chart/antd/chart-utils.tsx +50 -0
- package/src/components/chart/antd/column-chart-sub.tsx +67 -0
- package/src/components/chart/antd/line-chart-sub.tsx +65 -0
- package/src/components/chart/antd/pie-chart-sub.tsx +54 -0
- package/src/components/chart/antd/statview-d2-chart.tsx +125 -0
- package/src/components/chart/statview-l2-chart.tsx +69 -0
- package/src/components/controls/action/index.css +9 -0
- package/src/components/controls/action/index.tsx +228 -0
- package/src/components/controls/action/utils.tsx +122 -0
- package/src/components/controls/auto-complete/index.tsx +80 -0
- package/src/components/controls/cascader/index.js +97 -0
- package/src/components/controls/chemstruc/graph.tsx +150 -0
- package/src/components/controls/chemstruc/index.css +28 -0
- package/src/components/controls/collapse-card/index.css +9 -0
- package/src/components/controls/collapse-card/index.tsx +59 -0
- package/src/components/controls/color-picker/index.css +27 -0
- package/src/components/controls/color-picker/index.tsx +88 -0
- package/src/components/controls/cquery/cquick-button.tsx +117 -0
- package/src/components/controls/date-picker/index.tsx +141 -0
- package/src/components/controls/entity-select/entity-select.tsx +277 -0
- package/src/components/controls/entity-select/index.css +6 -0
- package/src/components/controls/entity-select/popover-entity-select.tsx +112 -0
- package/src/components/controls/entry-control.tsx +240 -0
- package/src/components/controls/enum-badge/index.tsx +28 -0
- package/src/components/controls/enum-tag/index.tsx +30 -0
- package/src/components/controls/file-view/drawer-file-view.tsx +69 -0
- package/src/components/controls/file-view/index.tsx +145 -0
- package/src/components/controls/html-editor/draft.tsx +161 -0
- package/src/components/controls/html-editor/tinymce.js +55 -0
- package/src/components/controls/input-number/index.tsx +101 -0
- package/src/components/controls/input-range/index.tsx +48 -0
- package/src/components/controls/password-setter/index.css +3 -0
- package/src/components/controls/password-setter/index.js +70 -0
- package/src/components/controls/progress/index.tsx +61 -0
- package/src/components/controls/relation-existion/index.css +4 -0
- package/src/components/controls/relation-existion/index.tsx +108 -0
- package/src/components/controls/rfield/index.css +4 -0
- package/src/components/controls/rfield/index.tsx +161 -0
- package/src/components/controls/signature/index.tsx +162 -0
- package/src/components/controls/steps/index.tsx +58 -0
- package/src/components/controls/text/ellipsis-text.tsx +70 -0
- package/src/components/controls/upload/index.tsx +122 -0
- package/src/components/controls/view-control.tsx +177 -0
- package/src/components/detail/button/cquery-button-bar.tsx +112 -0
- package/src/components/detail/button/index.css +43 -0
- package/src/components/detail/button/submit-button-bar.tsx +151 -0
- package/src/components/detail/dtmpl.css +53 -0
- package/src/components/detail/edit/dtmpl-edit.tsx +218 -0
- package/src/components/detail/edit/fields-edit-card.tsx +103 -0
- package/src/components/detail/edit/modal-dtmpl-edit.tsx +198 -0
- package/src/components/detail/edit/modal-row-edit.tsx +72 -0
- package/src/components/detail/edit/post-result/index.tsx +52 -0
- package/src/components/detail/edit/row-edit-card.tsx +125 -0
- package/src/components/detail/edit/row-editor.tsx +71 -0
- package/src/components/detail/rightbar/index.css +35 -0
- package/src/components/detail/rightbar/index.tsx +76 -0
- package/src/components/detail/view/act-dtmpl-view.tsx +155 -0
- package/src/components/detail/view/dtmpl-view.tsx +143 -0
- package/src/components/detail/view/field-view-group.tsx +73 -0
- package/src/components/detail/view/modal-dtmpl-view.tsx +56 -0
- package/src/components/detail/view/snapshot-timeline.tsx +130 -0
- package/src/components/exportor/export-frame.css +3 -0
- package/src/components/exportor/export-frame.tsx +194 -0
- package/src/components/exportor/index.tsx +60 -0
- package/src/components/form/criteria-form.tsx +241 -0
- package/src/components/form/dtmpl-form.css +4 -0
- package/src/components/form/dtmpl-form.tsx +272 -0
- package/src/components/form/field-group-form.tsx +75 -0
- package/src/components/form/fields-form.tsx +51 -0
- package/src/components/form/form-Item-group.tsx +99 -0
- package/src/components/form/index.css +13 -0
- package/src/components/import/excel-import.tsx +316 -0
- package/src/components/import/index.css +54 -0
- package/src/components/import/template-builder.js +474 -0
- package/src/components/import/template.css +51 -0
- package/src/components/layout/MainPage.tsx +230 -0
- package/src/components/layout/footer/index.css +6 -0
- package/src/components/layout/footer/index.js +17 -0
- package/src/components/layout/header/index.css +86 -0
- package/src/components/layout/header/index.tsx +58 -0
- package/src/components/layout/menu/block.tsx +88 -0
- package/src/components/layout/menu/l2menu-message-bar.tsx +118 -0
- package/src/components/layout/menu/l2menu-quick-bar.tsx +132 -0
- package/src/components/layout/menu/menu-2layers.tsx +92 -0
- package/src/components/layout/menu/menu-render.tsx +49 -0
- package/src/components/layout/menu/reset-password.tsx +185 -0
- package/src/components/layout/menu/user-bar.tsx +97 -0
- package/src/components/layout/menu/userinfo-bar.tsx +70 -0
- package/src/components/layout/sidebar/index.css +26 -0
- package/src/components/layout/sidebar/index.tsx +38 -0
- package/src/components/login.js +137 -0
- package/src/components/module/criteria-page.tsx +175 -0
- package/src/components/module/dtmpl-page.tsx +70 -0
- package/src/components/module/ltmpl-page.tsx +181 -0
- package/src/components/routable/dtmpl-route.tsx +96 -0
- package/src/components/routable/import-route.tsx +28 -0
- package/src/components/routable/ltmpl-route.tsx +158 -0
- package/src/components/table/act-table.tsx +635 -0
- package/src/components/table/column/column-selector.tsx +79 -0
- package/src/components/table/column/index.css +14 -0
- package/src/components/table/index.css +45 -0
- package/src/components/table/l2-act-table.tsx +85 -0
- package/src/components/table/modal-select-table.tsx +248 -0
- package/src/components/table/pagination.css +15 -0
- package/src/components/table/pagination.tsx +72 -0
- package/src/components/table/query-table.tsx +331 -0
- package/src/components/table/relation-table.tsx +600 -0
- package/src/components/table/select-table.tsx +247 -0
- package/src/components/table/selected-rows-card.tsx +62 -0
- package/src/components/table/stat/restat.tsx +79 -0
- package/src/components/table/table-util.tsx +33 -0
- package/src/components/tmpl/control-type-supportor.tsx +97 -0
- package/src/components/tmpl/hc-data-source.tsx +230 -0
- package/src/components/tmpl/hcservice-v3.tsx +624 -0
- package/src/components/tmpl/interface.tsx +308 -0
- package/src/components/tmpl/superagent.js +93 -0
- package/src/components/tmpl/tmpl-config-analysis.tsx +111 -0
- package/src/components/units/EncryptUtils.js +38 -0
- package/src/components/units/image.d.ts +8 -0
- package/src/components/units/index.tsx +536 -0
- package/src/components/units/logo.png +0 -0
- package/src/components/units/storage.js +3 -0
- package/src/components/welcome/HCWelcome.js +232 -0
- package/src/components/welcome/index.css +13 -0
- package/src/components/welcome/logo.png +0 -0
- package/src/components/welcome/quick-entrance.tsx +77 -0
- package/src/components/welcome/workbench.tsx +76 -0
- package/src/index.js +4 -0
- package/src/style/common.css +79 -0
- package/src/style/coverstyle.css +49 -0
- package/src/style/transstyle.css +24 -0
- package/tsconfig.json +106 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import React, {RefObject} from 'react'
|
|
2
|
+
import {Button, Card, Form as AntdForm, message, Modal, Switch} from 'antd'
|
|
3
|
+
import {DtmplBaseProps, DtmplConfig, DtmplData, FieldGroupConfig} from "../tmpl/interface";
|
|
4
|
+
import HcserviceV3 from "../tmpl/hcservice-v3";
|
|
5
|
+
import FormItemGroup from "./form-Item-group";
|
|
6
|
+
import {FormInstance} from "antd/lib/form/hooks/useForm";
|
|
7
|
+
import {ReloadOutlined} from '@ant-design/icons';
|
|
8
|
+
import FieldViewGroup from "../detail/view/field-view-group";
|
|
9
|
+
import RelationTable from "./../table/relation-table";
|
|
10
|
+
import './dtmpl-form.css';
|
|
11
|
+
import CollapseCard from "../controls/collapse-card";
|
|
12
|
+
|
|
13
|
+
export interface DtmplFormProps extends DtmplBaseProps {
|
|
14
|
+
parentId:string,
|
|
15
|
+
dtmplConfig: DtmplConfig,
|
|
16
|
+
dtmplData?:DtmplData,
|
|
17
|
+
formRef: RefObject<FormInstance>,
|
|
18
|
+
showConfirm: boolean,
|
|
19
|
+
onFinish: (code:string) => void,
|
|
20
|
+
onValuesChange?:()=>void,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface DtmplFormStat {
|
|
24
|
+
loading: boolean,
|
|
25
|
+
dtmplData: DtmplData,
|
|
26
|
+
// changedGroupData:Map<number,DtmplData[]>
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const confirm = Modal.confirm;
|
|
30
|
+
|
|
31
|
+
export default class Form extends React.PureComponent<DtmplFormProps, DtmplFormStat> {
|
|
32
|
+
fuseMode: boolean = false;
|
|
33
|
+
premisestitle: string = "默认字段";
|
|
34
|
+
|
|
35
|
+
state = {
|
|
36
|
+
loading: true,
|
|
37
|
+
dtmplData: undefined,
|
|
38
|
+
// changedGroupData:new Map<number,DtmplData[]>()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async componentDidMount() {
|
|
42
|
+
await this.loadData();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async componentDidUpdate(preProps) {
|
|
46
|
+
// const { code,formRef} = this.props;
|
|
47
|
+
const { code:preCode} = preProps;
|
|
48
|
+
if(preProps!=this.props){
|
|
49
|
+
await this.loadData();
|
|
50
|
+
}
|
|
51
|
+
// this.props.onValuesChange();
|
|
52
|
+
// if(code!=preCode || (!code && preCode)){
|
|
53
|
+
// await this.loadData();
|
|
54
|
+
// }else{
|
|
55
|
+
// formRef.current.resetFields();
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
loadData = async () => {
|
|
61
|
+
const { sourceId, code, formRef,dtmplData} = this.props;
|
|
62
|
+
if (code) {
|
|
63
|
+
this.setState({
|
|
64
|
+
loading: true,
|
|
65
|
+
})
|
|
66
|
+
const dtmplData_ = await HcserviceV3.requestDtmplData( sourceId, code, null);
|
|
67
|
+
this.setState({
|
|
68
|
+
dtmplData:dtmplData_,
|
|
69
|
+
// changedGroupData:new Map<number,DtmplData[]>(),
|
|
70
|
+
loading: false,
|
|
71
|
+
})
|
|
72
|
+
}else if(dtmplData){
|
|
73
|
+
this.setState({
|
|
74
|
+
dtmplData,
|
|
75
|
+
// changedGroupData:new Map<number,DtmplData[]>(),
|
|
76
|
+
loading: false,
|
|
77
|
+
})
|
|
78
|
+
}else{
|
|
79
|
+
this.setState({
|
|
80
|
+
dtmplData:{code:undefined,title:undefined,fieldMap:{},arrayMap:{}},
|
|
81
|
+
loading: false,
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
//debounce(formRef.current.resetFields();, 500);
|
|
85
|
+
setTimeout(()=>formRef.current.resetFields(),200)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
doRefresh = async () => {
|
|
89
|
+
await this.loadData();
|
|
90
|
+
message.info("已刷新!")
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onGroupChange = (fieldGroupConfig: FieldGroupConfig, selectdDatas: DtmplData[]) => {
|
|
94
|
+
const {dtmplData} = this.state;
|
|
95
|
+
dtmplData['arrayMap'][fieldGroupConfig.id] = selectdDatas;
|
|
96
|
+
let dtmplData_1 = {...dtmplData};
|
|
97
|
+
|
|
98
|
+
this.setState({
|
|
99
|
+
dtmplData: dtmplData_1,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
changeFuseMode = (checked) => {
|
|
106
|
+
this.fuseMode = !checked;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
postForm = async (result) => {
|
|
110
|
+
this.setState({
|
|
111
|
+
loading:true,
|
|
112
|
+
})
|
|
113
|
+
const {sourceId, code,dtmplData} = this.props;
|
|
114
|
+
if (code) { //有code是修改,没有是新增实体模板
|
|
115
|
+
result['唯一编码'] = code;
|
|
116
|
+
}else if(dtmplData && dtmplData.code){
|
|
117
|
+
result['唯一编码'] = dtmplData.code;
|
|
118
|
+
}
|
|
119
|
+
let res = await HcserviceV3.postDtmplData(sourceId, result, message);
|
|
120
|
+
this.setState({
|
|
121
|
+
loading:false,
|
|
122
|
+
})
|
|
123
|
+
if(res.status === "success"){
|
|
124
|
+
this.props.onFinish(res.code);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
onSubmit = async (values: any) => {
|
|
129
|
+
const {showConfirm, code, dtmplConfig} = this.props;
|
|
130
|
+
const {dtmplData} = this.state;
|
|
131
|
+
console.log("from value:",values);
|
|
132
|
+
let resultCode = undefined;
|
|
133
|
+
const result = values;
|
|
134
|
+
for (let group of dtmplConfig.groups) {
|
|
135
|
+
if (group.type == 'relation') {
|
|
136
|
+
//添加关系标识
|
|
137
|
+
values[`${group.id}.$$flag$$`] = true;
|
|
138
|
+
//添加关系内容
|
|
139
|
+
let ds: DtmplData[] = dtmplData.arrayMap[group.id];
|
|
140
|
+
if (ds) {
|
|
141
|
+
ds.forEach((d, index) => {
|
|
142
|
+
values[`${group.id}[${index}].$$relation$$`] = d.relationLabel;
|
|
143
|
+
if (d.editStatus || d.editStatus=='new') {
|
|
144
|
+
for (let field of group.fields) {
|
|
145
|
+
values[`${group.id}[${index}].${field.id}`] = d.fieldMap[field.id];
|
|
146
|
+
}
|
|
147
|
+
} else if(d.editStatus || d.editStatus=='changed'){
|
|
148
|
+
values[`${group.id}[${index}].唯一编码`] = d.code;
|
|
149
|
+
for (let field of group.fields) {
|
|
150
|
+
values[`${group.id}[${index}].${field.id}`] = d.fieldMap[field.id];
|
|
151
|
+
}
|
|
152
|
+
}else{
|
|
153
|
+
values[`${group.id}[${index}].唯一编码`] = d.code;
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
resultCode = await this.postForm(result);
|
|
160
|
+
// if (showConfirm) {
|
|
161
|
+
// confirm({
|
|
162
|
+
// title: '确定要保存修改吗',
|
|
163
|
+
// okText: '确定',
|
|
164
|
+
// okType: 'danger',
|
|
165
|
+
// cancelText: '取消',
|
|
166
|
+
// onOk: async () =>
|
|
167
|
+
// await this.postForm(result)
|
|
168
|
+
// ,
|
|
169
|
+
// });
|
|
170
|
+
// } else {
|
|
171
|
+
// resultCode = await this.postForm(result);
|
|
172
|
+
// }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
fieldGroupList = () => {
|
|
177
|
+
|
|
178
|
+
const {dtmplConfig,parentId} = this.props;
|
|
179
|
+
const {dtmplData, loading} = this.state;
|
|
180
|
+
|
|
181
|
+
let groups: FieldGroupConfig[];
|
|
182
|
+
if (dtmplConfig) {
|
|
183
|
+
groups = dtmplConfig.groups;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return groups.map((item) => {
|
|
187
|
+
if (item.type == 'relation') {//关系
|
|
188
|
+
if (item.fields) {
|
|
189
|
+
let data: DtmplData[] = undefined;
|
|
190
|
+
if (dtmplData) {
|
|
191
|
+
data = dtmplData.arrayMap[item.id];
|
|
192
|
+
}
|
|
193
|
+
return <RelationTable loading={loading} parentId={parentId} key={item.id} fieldGroupConfig={item} value={data}
|
|
194
|
+
viewOrEdit={"edit"} onChange={this.onGroupChange}/>
|
|
195
|
+
}
|
|
196
|
+
} else {//字段组
|
|
197
|
+
return <CollapseCard
|
|
198
|
+
title={item.title}
|
|
199
|
+
key={item.id}
|
|
200
|
+
id={parentId+item.id}
|
|
201
|
+
className="hoverable"
|
|
202
|
+
headStyle={{background: "#f2f4f5"}}
|
|
203
|
+
loading={loading}
|
|
204
|
+
>
|
|
205
|
+
<FormItemGroup fields={item?item.fields:undefined} valueMap={dtmplData ? dtmplData.fieldMap : undefined}
|
|
206
|
+
></FormItemGroup>
|
|
207
|
+
</CollapseCard>
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
render() {
|
|
214
|
+
const {formRef, dtmplConfig, sourceId, code,parentId,onValuesChange,dtmplData} = this.props;
|
|
215
|
+
if(!dtmplConfig){
|
|
216
|
+
return <Card>
|
|
217
|
+
{/*loading={loading}*/}
|
|
218
|
+
</Card>
|
|
219
|
+
}
|
|
220
|
+
const {buttons, premises} = dtmplConfig;
|
|
221
|
+
return (
|
|
222
|
+
<>
|
|
223
|
+
<Card bordered={false}
|
|
224
|
+
key={"detailTitle"}
|
|
225
|
+
className="hoverable pageHeader"
|
|
226
|
+
// loading={loading}
|
|
227
|
+
>
|
|
228
|
+
<h3>
|
|
229
|
+
{code || (dtmplData && dtmplData.code)? "[编辑]":"[新增]"}
|
|
230
|
+
<div className="fr">
|
|
231
|
+
{buttons && buttons.includes('fusionMode') ?
|
|
232
|
+
<Switch
|
|
233
|
+
checkedChildren="开"
|
|
234
|
+
unCheckedChildren="关"
|
|
235
|
+
style={{marginRight: 10}}
|
|
236
|
+
title="融合模式"
|
|
237
|
+
onChange={this.changeFuseMode}/>
|
|
238
|
+
: ""}
|
|
239
|
+
<Button
|
|
240
|
+
className="hoverbig"
|
|
241
|
+
title="刷新"
|
|
242
|
+
onClick={this.doRefresh}
|
|
243
|
+
><ReloadOutlined/></Button>
|
|
244
|
+
</div>
|
|
245
|
+
</h3>
|
|
246
|
+
</Card>
|
|
247
|
+
<AntdForm scrollToFirstError={true} labelWrap={true} ref={formRef} name="control-hooks" onValuesChange={onValuesChange} onFinish={this.onSubmit}>
|
|
248
|
+
<AntdForm.Item hidden={true} name={'actionId'} ></AntdForm.Item>
|
|
249
|
+
<AntdForm.Item hidden={true} name={'mainCode'} ></AntdForm.Item>
|
|
250
|
+
{this.fieldGroupList()}
|
|
251
|
+
</AntdForm>
|
|
252
|
+
{premises && premises.length > 0 ?
|
|
253
|
+
<CollapseCard
|
|
254
|
+
title={this.premisestitle}
|
|
255
|
+
key={this.premisestitle}
|
|
256
|
+
id={parentId+premises[0].id}
|
|
257
|
+
className="hoverable"
|
|
258
|
+
headStyle={{background: "#f2f4f5"}}
|
|
259
|
+
// loading={loading}
|
|
260
|
+
>
|
|
261
|
+
<FieldViewGroup
|
|
262
|
+
fields={premises}/>
|
|
263
|
+
</CollapseCard>
|
|
264
|
+
: ""
|
|
265
|
+
}
|
|
266
|
+
</>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, {RefObject} from 'react'
|
|
2
|
+
import {Form as AntdForm, message,Radio} from 'antd'
|
|
3
|
+
import {DtmplData, FieldGroupConfig} from "../tmpl/interface";
|
|
4
|
+
import HcserviceV3 from "../tmpl/hcservice-v3";
|
|
5
|
+
import {FormInstance} from "antd/lib/form/hooks/useForm";
|
|
6
|
+
import './dtmpl-form.css';
|
|
7
|
+
import FormItemGroup, {FieldGroupProps} from './form-Item-group';
|
|
8
|
+
import Units from '../units'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export interface FieldGroupFormProps {
|
|
12
|
+
fieldGroupConfig: FieldGroupConfig,
|
|
13
|
+
formRef?: RefObject<FormInstance>,
|
|
14
|
+
dtmplData?:DtmplData,
|
|
15
|
+
onFinish: (value: DtmplData) => void,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface FieldGroupFormStat {
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default class Form extends React.PureComponent<FieldGroupFormProps, FieldGroupFormStat> {
|
|
23
|
+
state = {}
|
|
24
|
+
|
|
25
|
+
async componentDidMount() {
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onSubmit = (values: any) => {
|
|
30
|
+
const {dtmplData,fieldGroupConfig}=this.props;
|
|
31
|
+
let data:DtmplData={
|
|
32
|
+
code: dtmplData?dtmplData.code :'new'+Units.getRandomNum(6),
|
|
33
|
+
editStatus:dtmplData && dtmplData.code && !dtmplData.code.startsWith('new')?'changed':"new",
|
|
34
|
+
relationLabel: values['relationLabel']?values['relationLabel']:fieldGroupConfig.relationNames[0],
|
|
35
|
+
fieldMap: values,
|
|
36
|
+
};
|
|
37
|
+
this.props.onFinish(data);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
selectRelation=()=>{
|
|
41
|
+
const {fieldGroupConfig, dtmplData} = this.props;
|
|
42
|
+
if(fieldGroupConfig.relationNames.length>1){
|
|
43
|
+
return <AntdForm.Item name="relationLabel" initialValue={dtmplData?dtmplData.relationLabel:undefined}
|
|
44
|
+
rules={[{
|
|
45
|
+
required: true, message: `请选择关系`,
|
|
46
|
+
}] }
|
|
47
|
+
label="关系">
|
|
48
|
+
<Radio.Group>
|
|
49
|
+
{
|
|
50
|
+
fieldGroupConfig.relationNames.map((item)=>{
|
|
51
|
+
return <Radio value="item">{item}</Radio>
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
</Radio.Group>
|
|
55
|
+
</AntdForm.Item>
|
|
56
|
+
}else{
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
render() {
|
|
62
|
+
const {formRef, fieldGroupConfig, dtmplData} = this.props;
|
|
63
|
+
return (
|
|
64
|
+
<>
|
|
65
|
+
<AntdForm labelWrap={true} ref={formRef} name="control-hooks" onFinish={this.onSubmit}>
|
|
66
|
+
{this.selectRelation()}
|
|
67
|
+
<FormItemGroup nameAttr={'id'} fields={fieldGroupConfig?fieldGroupConfig.fields:undefined} valueMap={dtmplData?dtmplData.fieldMap:{}}></FormItemGroup>
|
|
68
|
+
</AntdForm>
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, {RefObject} from 'react'
|
|
2
|
+
import {Form as AntdForm} from 'antd'
|
|
3
|
+
import {DtmplData, FieldConfig} from "../tmpl/interface";
|
|
4
|
+
import {FormInstance} from "antd/lib/form/hooks/useForm";
|
|
5
|
+
import './dtmpl-form.css';
|
|
6
|
+
import FormItemGroup from './form-Item-group';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export interface FieldsFormProps {
|
|
10
|
+
fields: FieldConfig[],
|
|
11
|
+
formRef?: RefObject<FormInstance>,
|
|
12
|
+
value?: object,
|
|
13
|
+
onFinish: (value: object) => void,
|
|
14
|
+
onValuesChange:(value: object) => void,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
interface FieldsFormStat {
|
|
18
|
+
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default class FieldsForm extends React.PureComponent<FieldsFormProps, FieldsFormStat> {
|
|
22
|
+
state = {}
|
|
23
|
+
|
|
24
|
+
async componentDidMount() {
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// onSubmit = (values: any) => {
|
|
29
|
+
// const {dtmplData, fields} = this.props;
|
|
30
|
+
// let data: DtmplData = {
|
|
31
|
+
// fieldMap: values,
|
|
32
|
+
// };
|
|
33
|
+
// this.props.onFinish(data);
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
const {formRef, fields, value,onFinish,onValuesChange} = this.props;
|
|
39
|
+
return (
|
|
40
|
+
<>
|
|
41
|
+
<AntdForm onValuesChange={onValuesChange} labelWrap={true} ref={formRef} name="control-hooks" onFinish={onFinish}>
|
|
42
|
+
<FormItemGroup nameAttr={'id'} fields={fields}
|
|
43
|
+
valueMap={value}></FormItemGroup>
|
|
44
|
+
</AntdForm>
|
|
45
|
+
</>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {Col, Form, Row} from 'antd'
|
|
3
|
+
import 'moment/locale/zh-cn';
|
|
4
|
+
import {FieldConfig, FieldGroupConfig} from "../tmpl/interface";
|
|
5
|
+
import EntryControl from "../controls/entry-control";
|
|
6
|
+
import Units from './../units'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const FormItem = Form.Item
|
|
11
|
+
|
|
12
|
+
export interface FieldGroupProps {
|
|
13
|
+
fields: FieldConfig[],
|
|
14
|
+
nameAttr?:string,
|
|
15
|
+
valueMap: object,
|
|
16
|
+
width?: number,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface FieldGroupState {
|
|
20
|
+
fileList: any,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default class FormItemGroup extends React.PureComponent<FieldGroupProps, FieldGroupState> {
|
|
24
|
+
|
|
25
|
+
static defaultProps={
|
|
26
|
+
nameAttr:'id',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(props) {
|
|
30
|
+
super(props);
|
|
31
|
+
this.state = {
|
|
32
|
+
fileList: [],
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
initFormList = () => {
|
|
37
|
+
const {fields, valueMap,nameAttr} = this.props
|
|
38
|
+
const formItemList = [];
|
|
39
|
+
|
|
40
|
+
if ( fields && fields.length > 0) {
|
|
41
|
+
fields.forEach((item, index) => {
|
|
42
|
+
const title = item.title;
|
|
43
|
+
let fieldValue = valueMap ? valueMap[item.id] : undefined;
|
|
44
|
+
//fieldValue 没有值时不能为null 要为 undefined。antd input所限制
|
|
45
|
+
fieldValue = (fieldValue || fieldValue==0 ) ? fieldValue : item.defaultValue ? Units.configParamTrans(item.defaultValue): undefined;
|
|
46
|
+
|
|
47
|
+
console.log("表单值:",valueMap[item.id],fieldValue);
|
|
48
|
+
|
|
49
|
+
const fieldKey = item.id + Math.random() * 100;
|
|
50
|
+
let formItem=null;
|
|
51
|
+
if(item.extControlType=='hidden'){
|
|
52
|
+
formItem= <FormItem hidden={true}
|
|
53
|
+
initialValue={fieldValue}
|
|
54
|
+
name={item[nameAttr]} key={item.id}>
|
|
55
|
+
<EntryControl value={fieldValue} fieldConfig={item} />
|
|
56
|
+
</FormItem>
|
|
57
|
+
}else{
|
|
58
|
+
formItem = <FormItem label={item.title} name={item[nameAttr]} key={item.id}
|
|
59
|
+
labelCol={item.colNum == 1 ? {span: 6} : {span: 3}}
|
|
60
|
+
wrapperCol={item.colNum == 1 ? {span: 15} : {span: 19}}
|
|
61
|
+
tooltip={item.tip}
|
|
62
|
+
initialValue={fieldValue}
|
|
63
|
+
style={{ margin: 4}}
|
|
64
|
+
rules={item.required ? [{
|
|
65
|
+
required: true, message: `请选择${title}`,
|
|
66
|
+
}] : undefined}>
|
|
67
|
+
<EntryControl value={fieldValue} fieldConfig={item} />
|
|
68
|
+
</FormItem>
|
|
69
|
+
}
|
|
70
|
+
formItemList.push(formItem);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const colList = [];
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < formItemList.length; i = i + 1) {
|
|
77
|
+
let colNum = fields[i].colNum;
|
|
78
|
+
if(fields[i].extControlType=='hidden'){
|
|
79
|
+
colNum=0;
|
|
80
|
+
}
|
|
81
|
+
let col = <Col key={i} span={12 * colNum}>
|
|
82
|
+
{formItemList[i]}
|
|
83
|
+
</Col>
|
|
84
|
+
colList.push(col);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const row =
|
|
88
|
+
<Row gutter={[16, 8]} key={1}>
|
|
89
|
+
{colList}
|
|
90
|
+
</Row>
|
|
91
|
+
return row;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
render() {
|
|
95
|
+
return (
|
|
96
|
+
this.initFormList()
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
}
|