|
@@ -1,17 +1,14 @@
|
1
|
1
|
import React, { useState } from 'react';
|
2
|
|
-import { Button, Row, Col, Input, InputNumber, notification } from 'antd';
|
|
2
|
+import { Button, Row, Col, Input, InputNumber, Modal, notification } from 'antd';
|
3
|
3
|
import XForm, { FieldTypes } from '../../../components/XForm';
|
4
|
4
|
import Style from '../style.less';
|
5
|
5
|
import { fetch, apis } from '../../../utils/request';
|
6
|
6
|
|
7
|
|
-const saveMiniapp = fetch(apis.member.miniapp);
|
|
7
|
+const saveMiniapp = fetch(apis.member.miniapp.edit);
|
|
8
|
+const checkMiniapp = fetch(apis.member.miniapp.check);
|
8
|
9
|
|
9
|
10
|
const TplItem = React.forwardRef((props, ref) => {
|
10
|
|
- const [val, setVal] = useState({
|
11
|
|
- tplId: undefined,
|
12
|
|
- fieldNum: undefined,
|
13
|
|
- ...props.value || {}
|
14
|
|
- })
|
|
11
|
+ const [val, setVal] = useState(props.value)
|
15
|
12
|
|
16
|
13
|
const handleChange = field => e => {
|
17
|
14
|
const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
|
|
@@ -31,11 +28,34 @@ const TplItem = React.forwardRef((props, ref) => {
|
31
|
28
|
})
|
32
|
29
|
|
33
|
30
|
const Miniapp = (props) => {
|
|
31
|
+ const [ visible, changeVisible ] = useState(false);
|
|
32
|
+ const [ path, changePath ] = useState('/pages/project/index');
|
|
33
|
+ const [ qrCode, setQrCode ] = useState();
|
|
34
|
+
|
34
|
35
|
const user = props.data || {}
|
35
|
36
|
const appdata = user.miniapp || {};
|
36
|
37
|
const noticeTPL = (appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {}
|
37
|
38
|
|
38
|
|
- const checkMiniapp = () => {
|
|
39
|
+ const showModal = () => {
|
|
40
|
+ changeVisible(true);
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ let form = undefined;
|
|
44
|
+ const handleForm = f => {
|
|
45
|
+ if (f) {
|
|
46
|
+ form = f.props.form
|
|
47
|
+ }
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ const handleModalOk = () => {
|
|
51
|
+ const values = form.getFieldsValue()
|
|
52
|
+ const data = { ...values, path }
|
|
53
|
+
|
|
54
|
+ checkMiniapp({ data }).then(dt => {
|
|
55
|
+ setQrCode(dt.qrCode)
|
|
56
|
+ changeVisible(false)
|
|
57
|
+ notification.success({ message: '校验成功' });
|
|
58
|
+ }).catch();
|
39
|
59
|
}
|
40
|
60
|
|
41
|
61
|
const fields = [
|
|
@@ -51,6 +71,9 @@ const Miniapp = (props) => {
|
51
|
71
|
name: 'miniappId',
|
52
|
72
|
type: FieldTypes.Text,
|
53
|
73
|
value: appdata.miniappId,
|
|
74
|
+ props: {
|
|
75
|
+ disabled: !!appdata.miniappId,
|
|
76
|
+ },
|
54
|
77
|
rules: [
|
55
|
78
|
{ required: true, message: '请填写 APPID' },
|
56
|
79
|
{ pattern: /^[a-zA-Z0-9]+$/, message: 'APPID 只能由字母与数字组成' }
|
|
@@ -97,9 +120,15 @@ const Miniapp = (props) => {
|
97
|
120
|
{
|
98
|
121
|
label: '消息通知',
|
99
|
122
|
name: 'notice',
|
100
|
|
- render: () => <TplItem />,
|
|
123
|
+ render: <TplItem />,
|
101
|
124
|
value: noticeTPL,
|
102
|
125
|
},
|
|
126
|
+ {
|
|
127
|
+ label: '小程序码',
|
|
128
|
+ name: 'qrCode',
|
|
129
|
+ render: () => <img src={qrCode} style={{ width: '240px' }} alt=""/>,
|
|
130
|
+ value: qrCode || appdata.qrCode,
|
|
131
|
+ },
|
103
|
132
|
{
|
104
|
133
|
action: true,
|
105
|
134
|
render: () => {
|
|
@@ -109,8 +138,16 @@ const Miniapp = (props) => {
|
109
|
138
|
<img src="" alt="" style={{ width: '128px' }}/>
|
110
|
139
|
</div>
|
111
|
140
|
<div className={Style['flex-auto']}>
|
112
|
|
- <Button type="primary" ghost onClick={checkMiniapp}>验证</Button>
|
|
141
|
+ <Button type="primary" ghost onClick={showModal}>验证</Button>
|
113
|
142
|
</div>
|
|
143
|
+ <Modal
|
|
144
|
+ title="填写首页地址"
|
|
145
|
+ visible={visible}
|
|
146
|
+ onOk={handleModalOk}
|
|
147
|
+ onCancel={() => changeVisible(false)}
|
|
148
|
+ >
|
|
149
|
+ <Input value={path} onChange={e => changePath(e.target.value)}></Input>
|
|
150
|
+ </Modal>
|
114
|
151
|
</div>
|
115
|
152
|
)
|
116
|
153
|
}
|
|
@@ -138,20 +175,27 @@ const Miniapp = (props) => {
|
138
|
175
|
|
139
|
176
|
const tpls = [
|
140
|
177
|
{
|
141
|
|
- ...notice,
|
142
|
178
|
...(appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {},
|
|
179
|
+ ...notice,
|
143
|
180
|
tplType: 'notice'
|
144
|
|
- }
|
|
181
|
+ },
|
|
182
|
+ ...(appdata.tpls || []).filter(x => x.tplType !== 'notice')
|
145
|
183
|
]
|
146
|
184
|
|
147
|
185
|
const data = {
|
148
|
186
|
...appdata,
|
149
|
187
|
...otherData,
|
|
188
|
+ qrCode: qrCode || appdata.appdata,
|
150
|
189
|
orgId: user.orgId,
|
151
|
190
|
tpls,
|
152
|
191
|
}
|
153
|
192
|
|
154
|
|
- saveMiniapp({ data }).then(() => {
|
|
193
|
+ saveMiniapp({ data }).then((miniapp) => {
|
|
194
|
+
|
|
195
|
+ if (typeof props.onChange === 'function') {
|
|
196
|
+ props.onChange({ ...user, miniapp })
|
|
197
|
+ }
|
|
198
|
+
|
155
|
199
|
notification.success({ message: '保存小程序信息成功' })
|
156
|
200
|
}).catch(x => x)
|
157
|
201
|
}
|
|
@@ -162,7 +206,7 @@ const Miniapp = (props) => {
|
162
|
206
|
}
|
163
|
207
|
}
|
164
|
208
|
|
165
|
|
- return (<XForm onSubmit={handleSubmit} onCancel={handleCancel} fields={fields}></XForm>)
|
|
209
|
+ return (<XForm wrappedComponentRef={handleForm} onSubmit={handleSubmit} onCancel={handleCancel} fields={fields}></XForm>)
|
166
|
210
|
}
|
167
|
211
|
|
168
|
212
|
export default Miniapp;
|