index.tsx
6.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import React, { useImperativeHandle, useRef, useState, useEffect } from 'react';
import { Button, Drawer, Space, Modal } from 'antd';
import { history, useLocation } from 'umi';
import { handleWindowOpen } from '@/utils';
import Draggable from 'react-draggable';
// TODO: 公共依赖
import { doBtnJump } from '@/pages/app-view/list/util';
import { RuntimeFormDrawer } from '@/pages/app-view/form';
import QxFormRender from '@/packages/qx-form-generator/src/form-render';
import { useForm } from '@qx/form-render';
const FORM_SCHEMA = {};
/* {
"actionJson": {
"link": {
"funId": "SwJ7iKDN1eYLTjUmljx",
"viewCode": "all",
"methodCode": "LIST",
"openType": "SELF" || "BLANK",
"title": "数值小数"
},
"type": "FORM_PAGE"
}
} */
/*表单页--弹框的形式*/
interface UrlDialogProp {
visible: boolean;
title: string;
url: string;
onVisibleChange: (visible: boolean) => void;
}
export const UrlDialog: React.FC<UrlDialogProp> = (props) => {
const [visible, setVisible] = useState(false);
useEffect(() => {
setVisible(props?.visible);
}, [props?.visible]);
useEffect(() => {
props.onVisibleChange(visible);
}, [visible]);
return (
<>
<Modal
title={props.title}
width={'1200px'}
visible={visible}
bodyStyle={{ padding: '0' }} // 不能加 对其详情有影响
onCancel={() => setVisible(false)}
footer={false}
destroyOnClose={true}
modalRender={(node) => (
<Draggable handle=".ant-modal-header">
<div>{node}</div>
</Draggable>
)}
>
<iframe src={props.url} style={{ width: '100%', height: '500px' }} frameBorder="0" />
</Modal>
</>
);
};
type ButtonFormProps = {
cRef: any;
title?: string;
successCallback?: (result: any) => void;
};
const ButtonForm: React.FC<ButtonFormProps> = (props) => {
const form = useForm();
// const [isEdit, setEdit] = useState(false);
const [visible, setVisible] = useState(false);
const { pathname } = useLocation();
const [query, setQuery] = useState<any>({});
const [url, setUrl] = useState<string>('');
const [urlDialogVisible, setUrlDialogVisible] = useState<boolean>(false);
const drawerRef = useRef({
open: () => {},
close: () => {},
});
const method = {
LIST(link: any, params: any) {
const origin = location.href.split('#').shift(); //截取地址栏#前地址
let URL = `/app-view/${link.appCode}/${link.formCode}/list?appId=${
link.appId
}&pageNum=1&pageSize=10&viewCode=${link.viewCode}&${params.join('&')}`;
// sys下appId与_code不需要 ----晴晴 2022.7.13
if (pathname.includes('/sys')) {
URL = `/sys/${link.appCode}/${link.formCode}/${
link.viewCode
}/list?pageNum=1&pageSize=10&${params.join('&')}`;
}
if (link.openType === 'SELF') {
history.push(URL);
}
if (link.openType === 'BLANK') {
console.log(history, location);
handleWindowOpen(`${origin}#${URL}`);
}
},
ADD(link: object, params: any) {
console.log(params);
// @ts-ignore
if (link?.appCode && link.formCode && link?.viewCode) {
drawerRef.current.open();
}
},
VIEW(link: object, params: any) {
console.log(link, params);
},
};
const getParaVal = (val: any = {}, record: any = {}) => {
if (val.type === 'CUSTOM') {
return val.value === 'LOCATION_PATH' ? pathname : val.value;
}
if (val.type === 'FIELD') {
const dataValue = record[val.value];
return Array.isArray(dataValue) ? dataValue.join(',') : dataValue;
}
return val.value;
};
useImperativeHandle(props.cRef, () => ({
// 暴露给父组件
open: (schemaItem: any, record: any) => {
setQuery(schemaItem.link);
const btnSchema = schemaItem;
const params = (btnSchema.link.params || []).map((item: any) => {
return `${item.name}=${getParaVal(item.value, record)}`;
});
if (btnSchema.type === 'URL') {
//TODO,开发者模式下才有,不完善。 for 易才项目 from 史婷婷
if (btnSchema?.link?.openType === 'DIALOG') {
const _url = btnSchema?.link?.url;
if (_url) {
try {
const _urlArr = _url.split('?');
_urlArr[1] = params.join('&') + (_urlArr[1] ? '&' : '') + _urlArr[1];
setUrl(_urlArr.join('?'));
setUrlDialogVisible(true);
} catch (e) {
console.log(e);
}
}
} else {
doBtnJump(btnSchema, record, params);
}
return;
}
if (btnSchema.type === 'FORM_PAGE' && btnSchema.link) {
// console.log('FORM_PAGE!!!!!!!!!!');
const mcode = btnSchema.link.methodCode;
if (mcode) method[mcode].call(null, btnSchema.link, params);
}
//setVisible(true)
},
}));
const successCallback = (val: any) => {
if (props.successCallback) {
props.successCallback(val);
}
};
const onFinish = async (data: any, error: any) => {
console.log(data, error);
};
const onMount = () => {};
return (
<div>
{false ? (
<Drawer
title="填写记录"
placement="right"
onClose={() => setVisible(false)}
visible={visible}
width={'500px'}
keyboard={false}
maskClosable={false}
footer={
<Space>
<Button onClick={() => setVisible(false)}>关闭</Button>
<Button type="primary" onClick={() => form.submit()}>
保存
</Button>
</Space>
}
>
<QxFormRender
form={form}
schema={FORM_SCHEMA}
onMount={onMount}
onFinish={onFinish}
widgets={{}}
/>
</Drawer>
) : null}
<RuntimeFormDrawer
appCode={query.appCode}
viewCode={query.viewCode}
funCode={query.formCode}
dRef={drawerRef}
type={'add'}
dataId={''}
successCallback={successCallback}
// onCustomBtnClick={handleOpt}
/>
{/* <RuntimeFormDialog
// from={'rel'}
title={'新增'}
appCode={query.appCode}
funCode={query.funCode}
viewCode={query.viewCode}
dRef={drawerRef}
type={'add'}
// onAfterSave={props.onAfterSave}
/> */}
<UrlDialog
visible={urlDialogVisible}
onVisibleChange={(visible: boolean) => {
setUrlDialogVisible(visible);
}}
title={props?.title || ''}
url={url}
/>
</div>
);
};
export default ButtonForm;