|
@@ -1,32 +1,57 @@
|
1
|
1
|
import React, { useState, useEffect } from 'react';
|
2
|
|
-import { Button, Row, Col, Input, InputNumber, Modal, notification } from 'antd';
|
3
|
|
-import XForm, { FieldTypes } from '../../../components/XForm';
|
|
2
|
+import { Button, Row, Col, Input, InputNumber, Modal, notification, Select, Tooltip } from 'antd';
|
|
3
|
+import createForm from '@zjxpcyc/xrc-form2';
|
4
|
4
|
import Style from '../style.less';
|
5
|
5
|
import { fetch, apis } from '../../../utils/request';
|
6
|
6
|
|
|
7
|
+const XForm = createForm();
|
7
|
8
|
const saveMiniapp = fetch(apis.member.miniapp.edit);
|
8
|
9
|
const checkMiniapp = fetch(apis.member.miniapp.check);
|
9
|
10
|
|
|
11
|
+const getEventValue = e => {
|
|
12
|
+ return Object.prototype.hasOwnProperty.call(e, 'checked') ?
|
|
13
|
+ e.checked : (e.target ? e.target.value : e)
|
|
14
|
+}
|
|
15
|
+
|
10
|
16
|
const TplItem = React.forwardRef((props, ref) => {
|
11
|
17
|
const [val, setVal] = useState(props.value)
|
|
18
|
+ const [isSubs, setIsSubs] = useState(props.value.isSubscribe)
|
12
|
19
|
|
13
|
20
|
const handleChange = field => e => {
|
14
|
|
- const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
|
|
21
|
+ const fv = getEventValue(e);
|
|
22
|
+ const newVal = { ...val, [`${field}`]: fv }
|
15
|
23
|
setVal(newVal)
|
16
|
24
|
|
|
25
|
+ if (field === 'isSubscribe') {
|
|
26
|
+ setIsSubs(fv)
|
|
27
|
+ }
|
|
28
|
+
|
17
|
29
|
if (typeof props.onChange === 'function') {
|
18
|
|
- console.log('--change--->', newVal)
|
19
|
30
|
props.onChange(newVal)
|
20
|
31
|
}
|
21
|
32
|
}
|
22
|
33
|
|
23
|
34
|
return (
|
24
|
|
- <Input.Group compact ref={ref}>
|
25
|
|
- <Input style={{ width: '70%' }} value={val.tplId} placeholder="消息模板ID" onChange={handleChange('tplId')}></Input>
|
26
|
|
- <InputNumber style={{ width: '30%' }} value={val.fieldNum} placeholder="字段数" onChange={handleChange('fieldNum')}></InputNumber>
|
27
|
|
- </Input.Group>
|
|
35
|
+ <div ref={ref}>
|
|
36
|
+ <Input.Group compact>
|
|
37
|
+ <Tooltip title="消息类型">
|
|
38
|
+ <Select style={{ width: '15%' }} value={!!val.isSubscribe} onChange={handleChange('isSubscribe')}>
|
|
39
|
+ <Option value={true}>订阅</Option>
|
|
40
|
+ <Option value={false}>普通</Option>
|
|
41
|
+ </Select>
|
|
42
|
+ </Tooltip>
|
|
43
|
+ <Tooltip title="消息模板ID">
|
|
44
|
+ <Input style={{ width: '45%' }} value={val.tplId} placeholder="消息模板ID" onChange={handleChange('tplId')}></Input>
|
|
45
|
+ </Tooltip>
|
|
46
|
+ {
|
|
47
|
+ !isSubs ?
|
|
48
|
+ (<Tooltip title="消息字段数"><InputNumber style={{ width: '40%' }} value={val.fieldNum} placeholder="字段数" onChange={handleChange('fieldNum')}></InputNumber></Tooltip>) :
|
|
49
|
+ (<Tooltip title="消息字段, 多字段用 | 分隔"><Input style={{ width: '40%' }} value={val.tplFields} placeholder="字段内容" onChange={handleChange('tplFields')}></Input></Tooltip>)
|
|
50
|
+ }
|
|
51
|
+ </Input.Group>
|
|
52
|
+ </div>
|
28
|
53
|
);
|
29
|
|
-})
|
|
54
|
+});
|
30
|
55
|
|
31
|
56
|
const Miniapp = (props) => {
|
32
|
57
|
const [ visible, changeVisible ] = useState(false);
|
|
@@ -66,9 +91,10 @@ const Miniapp = (props) => {
|
66
|
91
|
const tplFields = (props.tplTyps || []).map((x) => {
|
67
|
92
|
return {
|
68
|
93
|
label: x.name,
|
69
|
|
- name: `tpl-${x.code}`,
|
70
|
|
- render: <TplItem />,
|
|
94
|
+ name: `tpl.${x.code}`,
|
|
95
|
+ node: TplItem,
|
71
|
96
|
value: tpls.filter(y => y.tplType === x.code)[0] || {},
|
|
97
|
+ hidden: vals => vals.isSubscribe,
|
72
|
98
|
}
|
73
|
99
|
})
|
74
|
100
|
|
|
@@ -76,14 +102,14 @@ const Miniapp = (props) => {
|
76
|
102
|
{
|
77
|
103
|
label: '名称',
|
78
|
104
|
name: 'name',
|
79
|
|
- type: FieldTypes.Text,
|
|
105
|
+ node: Input,
|
80
|
106
|
value: appdata.name,
|
81
|
107
|
rules: [{required: true, message: '请填写小程序名称'}]
|
82
|
108
|
},
|
83
|
109
|
{
|
84
|
110
|
label: 'APPID',
|
85
|
111
|
name: 'miniappId',
|
86
|
|
- type: FieldTypes.Text,
|
|
112
|
+ node: Input,
|
87
|
113
|
value: appdata.miniappId,
|
88
|
114
|
props: {
|
89
|
115
|
disabled: !!appdata.miniappId,
|
|
@@ -96,7 +122,7 @@ const Miniapp = (props) => {
|
96
|
122
|
{
|
97
|
123
|
label: 'Secret',
|
98
|
124
|
name: 'secret',
|
99
|
|
- type: FieldTypes.Text,
|
|
125
|
+ node: Input,
|
100
|
126
|
value: appdata.secret,
|
101
|
127
|
rules: [
|
102
|
128
|
{ required: true, message: '请填写 Secret' },
|
|
@@ -106,8 +132,8 @@ const Miniapp = (props) => {
|
106
|
132
|
{
|
107
|
133
|
label: 'Token',
|
108
|
134
|
name: 'token',
|
|
135
|
+ node: Input,
|
109
|
136
|
value: appdata.token,
|
110
|
|
- type: FieldTypes.Text,
|
111
|
137
|
rules: [
|
112
|
138
|
{ pattern: /^[a-zA-Z0-9]+$/, message: 'token 只能由字母与数字组成' }
|
113
|
139
|
]
|
|
@@ -115,8 +141,8 @@ const Miniapp = (props) => {
|
115
|
141
|
{
|
116
|
142
|
label: 'AES_KEY',
|
117
|
143
|
name: 'aesKey',
|
|
144
|
+ node: Input,
|
118
|
145
|
value: appdata.aesKey,
|
119
|
|
- type: FieldTypes.Text,
|
120
|
146
|
rules: [
|
121
|
147
|
{ pattern: /^[a-zA-Z0-9]+$/, message: 'AES_KEY 只能由字母与数字组成' }
|
122
|
148
|
]
|
|
@@ -154,33 +180,23 @@ const Miniapp = (props) => {
|
154
|
180
|
]
|
155
|
181
|
|
156
|
182
|
const checkTPLData = (submitData) => {
|
157
|
|
- let tplData = [...tpls]
|
158
|
183
|
let errors = []
|
159
|
184
|
|
160
|
|
- Object.keys(submitData).forEach((key) => {
|
161
|
|
- if (key.indexOf('tpl-') === 0) {
|
162
|
|
- const [, code] = key.split('-')
|
163
|
|
- const { tplId, fieldNum } = submitData[key].result || submitData[key]
|
164
|
|
- const tplType = (props.tplTyps || []).filter(x => x.code === code)[0] || {}
|
|
185
|
+ const tplData = Object.keys(submitData).map((key) => {
|
|
186
|
+ const { tplId, fieldNum, tplFields, isSubscribe, ...left } = submitData[key]
|
|
187
|
+ const tplType = (props.tplTyps || []).filter(x => x.code === key)[0] || {}
|
165
|
188
|
|
166
|
|
- if (tplId && !fieldNum) {
|
167
|
|
- errors.push(`请填写${tplType.name}模板字段数`)
|
|
189
|
+ if (isSubscribe) {
|
|
190
|
+ if (tplId && !tplFields) {
|
|
191
|
+ errors.push(`请填写${tplType.name}模板字段内容`)
|
168
|
192
|
return
|
169
|
193
|
}
|
170
|
|
-
|
171
|
|
- console.log('--->', submitData[key])
|
172
|
|
-
|
173
|
|
- if (tplId) {
|
174
|
|
- tplData = [
|
175
|
|
- ...tplData.filter(x => x.tplType !== code),
|
176
|
|
- {
|
177
|
|
- ...submitData[key],
|
178
|
|
- tplType: code,
|
179
|
|
- tplName: tplType.name,
|
180
|
|
- }
|
181
|
|
- ]
|
182
|
|
- }
|
|
194
|
+ } else if (tplId && !fieldNum) {
|
|
195
|
+ errors.push(`请填写${tplType.name}模板字段数`)
|
|
196
|
+ return
|
183
|
197
|
}
|
|
198
|
+
|
|
199
|
+ return submitData[key]
|
184
|
200
|
})
|
185
|
201
|
|
186
|
202
|
return [tplData, errors]
|
|
@@ -188,11 +204,9 @@ const Miniapp = (props) => {
|
188
|
204
|
|
189
|
205
|
const handleSubmit = val => {
|
190
|
206
|
// 校验字段
|
191
|
|
- const { mainbiz, newCustomer, notice, ...otherData} = val
|
192
|
|
-
|
193
|
|
- console.log('-----val--->', val)
|
|
207
|
+ const { tpl, ...otherData} = val
|
194
|
208
|
|
195
|
|
- const [tplData, errors] = checkTPLData(otherData)
|
|
209
|
+ const [tplData, errors] = checkTPLData(tpl)
|
196
|
210
|
|
197
|
211
|
if (errors.length > 0) {
|
198
|
212
|
notification.error({ message: errors[0] })
|