Bläddra i källkod

change tpl message select

张延森 5 år sedan
förälder
incheckning
97614bd873
2 ändrade filer med 1 tillägg och 230 borttagningar
  1. 0
    229
      src/pages/UserManage/Editor/Miniapp.bak.jsx
  2. 1
    1
      src/pages/UserManage/Editor/Miniapp.jsx

+ 0
- 229
src/pages/UserManage/Editor/Miniapp.bak.jsx Visa fil

@@ -1,229 +0,0 @@
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';
4
-import Style from '../style.less';
5
-import { fetch, apis } from '../../../utils/request';
6
-
7
-const saveMiniapp = fetch(apis.member.miniapp.edit);
8
-const checkMiniapp = fetch(apis.member.miniapp.check);
9
-
10
-const TplItem = React.forwardRef((props, ref) => {
11
-  const [val, setVal] = useState(props.value)
12
-
13
-  const handleChange = field => e => {
14
-    const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
15
-    setVal(newVal)
16
-
17
-    if (typeof props.onChange === 'function') {
18
-      console.log('--change--->', newVal)
19
-      props.onChange(newVal)
20
-    }
21
-  }
22
-
23
-  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>
28
-  );
29
-})
30
-
31
-const Miniapp = (props) => {
32
-  const [ visible, changeVisible ] = useState(false);
33
-  const [ path, changePath ] = useState('/pages/project/index');
34
-  const [ qrCode, setQrCode ] = useState();
35
-
36
-  const user = props.data || {}
37
-  const appdata = user.miniapp || {};
38
-  const tpls = appdata.tpls || [];
39
-
40
-  useEffect(() => {
41
-    setQrCode(appdata.qrCode)
42
-  }, [])
43
-
44
-  const showModal = () => {
45
-    changeVisible(true);
46
-  }
47
-
48
-  let form = undefined;
49
-  const handleForm = f => {
50
-    if (f) {
51
-      form = f.props.form
52
-    }
53
-  }
54
-
55
-  const handleModalOk = () => {
56
-    const values = form.getFieldsValue()
57
-    const data = { ...values, path }
58
-
59
-    checkMiniapp({ data }).then(dt => {
60
-      setQrCode(dt.qrCode)
61
-      changeVisible(false)
62
-      notification.success({ message: '校验成功' });
63
-    }).catch();
64
-  }
65
-
66
-  const tplFields = (props.tplTyps || []).map((x) => {
67
-    return {
68
-      label: x.name,
69
-      name: `tpl-${x.code}`,
70
-      render: <TplItem />,
71
-      value: tpls.filter(y => y.tplType === x.code)[0] || {},
72
-    }
73
-  })
74
-
75
-  const fields = [
76
-    {
77
-      label: '名称',
78
-      name: 'name',
79
-      type: FieldTypes.Text,
80
-      value: appdata.name,
81
-      rules: [{required: true, message: '请填写小程序名称'}]
82
-    },
83
-    {
84
-      label: 'APPID',
85
-      name: 'miniappId',
86
-      type: FieldTypes.Text,
87
-      value: appdata.miniappId,
88
-      props: {
89
-        disabled: !!appdata.miniappId,
90
-      },
91
-      rules: [
92
-        { required: true, message: '请填写 APPID' },
93
-        { pattern: /^[a-zA-Z0-9]+$/, message: 'APPID 只能由字母与数字组成' }
94
-      ]
95
-    },
96
-    {
97
-      label: 'Secret',
98
-      name: 'secret',
99
-      type: FieldTypes.Text,
100
-      value: appdata.secret,
101
-      rules: [
102
-        { required: true, message: '请填写 Secret' },
103
-        { pattern: /^[a-zA-Z0-9]+$/, message: 'APPID 只能由字母与数字组成' }
104
-      ]
105
-    },
106
-    {
107
-      label: 'Token',
108
-      name: 'token',
109
-      value: appdata.token,
110
-      type: FieldTypes.Text,
111
-      rules: [
112
-        { pattern: /^[a-zA-Z0-9]+$/, message: 'token 只能由字母与数字组成' }
113
-      ]
114
-    },
115
-    {
116
-      label: 'AES_KEY',
117
-      name: 'aesKey',
118
-      value: appdata.aesKey,
119
-      type: FieldTypes.Text,
120
-      rules: [
121
-        { pattern: /^[a-zA-Z0-9]+$/, message: 'AES_KEY 只能由字母与数字组成' }
122
-      ]
123
-    },
124
-    ...tplFields,
125
-    {
126
-      label: '小程序码',
127
-      name: 'qrCode',
128
-      render: () => <img src={qrCode} style={{ width: '240px' }} alt=""/>,
129
-      value: qrCode,
130
-    },
131
-    {
132
-      action: true,
133
-      render: () => {
134
-        return (
135
-          <div className={Style['flex-box']}>
136
-            <div className={Style['flex-item']}>
137
-              <img src="" alt="" style={{ width: '128px' }}/>
138
-            </div>
139
-            <div className={Style['flex-auto']}>
140
-              <Button type="primary" ghost onClick={showModal}>验证</Button>
141
-            </div>
142
-            <Modal
143
-              title="填写首页地址"
144
-              visible={visible}
145
-              onOk={handleModalOk}
146
-              onCancel={() => changeVisible(false)}
147
-            >
148
-              <Input value={path} onChange={e => changePath(e.target.value)}></Input>
149
-            </Modal>
150
-          </div>
151
-        )
152
-      }
153
-    },
154
-  ]
155
-
156
-  const checkTPLData = (submitData) => {
157
-    let tplData = [...tpls]
158
-    let errors = []
159
-
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] || {}
165
-
166
-        if (tplId && !fieldNum) {
167
-          errors.push(`请填写${tplType.name}模板字段数`)
168
-          return
169
-        }
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
-        }
183
-      }
184
-    })
185
-
186
-    return [tplData, errors]
187
-  }
188
-
189
-  const handleSubmit = val => {
190
-    // 校验字段
191
-    const { mainbiz, newCustomer, notice, ...otherData} = val
192
-
193
-    console.log('-----val--->', val)
194
-
195
-    const [tplData, errors] = checkTPLData(otherData)
196
-
197
-    if (errors.length > 0) {
198
-      notification.error({ message: errors[0] })
199
-      return
200
-    }
201
-
202
-    const data = {
203
-      ...appdata,
204
-      ...otherData,
205
-      qrCode: qrCode || appdata.appdata,
206
-      orgId: user.orgId,
207
-      tpls: tplData,
208
-    }
209
-
210
-    saveMiniapp({ data }).then((miniapp) => {
211
-      
212
-      if (typeof props.onChange === 'function') {
213
-        props.onChange({ ...user, miniapp })
214
-      }
215
-
216
-      notification.success({ message: '保存小程序信息成功' })
217
-    }).catch(x => x)
218
-  }
219
-
220
-  const handleCancel = () => {
221
-    if (typeof props.onCancel === 'function') {
222
-      props.onCancel()
223
-    }
224
-  }
225
-
226
-  return (<XForm wrappedComponentRef={handleForm} onSubmit={handleSubmit} onCancel={handleCancel} fields={fields}></XForm>)
227
-}
228
-
229
-export default Miniapp;

+ 1
- 1
src/pages/UserManage/Editor/Miniapp.jsx Visa fil

@@ -37,7 +37,7 @@ const TplItem = React.forwardRef((props, ref) => {
37 37
         <Tooltip title="消息类型">
38 38
           <Select style={{ width: '15%' }} value={!!val.isSubscribe} onChange={handleChange('isSubscribe')}>
39 39
             <Option value={true}>订阅</Option>
40
-            <Option value={false}>普通</Option>
40
+            <Option value={false}>服务</Option>
41 41
           </Select>
42 42
         </Tooltip>
43 43
         <Tooltip title="消息模板ID">