index.tsx
4.72 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
import React, { useImperativeHandle, useRef, useState } from 'react';
import { Button, Drawer, Space } from 'antd';
import { history, useLocation } from 'umi';
import { handleWindowOpen } from '@/utils';
// 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"
}
} */
type ButtonFormProps = {
cRef: any;
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 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') {
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}
/> */}
</div>
);
};
export default ButtonForm;