张延森 5 years ago
parent
commit
4b3c73b683

+ 58
- 14
src/pages/UserManage/Editor/Miniapp.jsx View File

1
 import React, { useState } from 'react';
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
 import XForm, { FieldTypes } from '../../../components/XForm';
3
 import XForm, { FieldTypes } from '../../../components/XForm';
4
 import Style from '../style.less';
4
 import Style from '../style.less';
5
 import { fetch, apis } from '../../../utils/request';
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
 const TplItem = React.forwardRef((props, ref) => {
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
   const handleChange = field => e => {
13
   const handleChange = field => e => {
17
     const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
14
     const newVal = { ...val, [`${field}`]: (e.target ? e.target.value : e) }
31
 })
28
 })
32
 
29
 
33
 const Miniapp = (props) => {
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
   const user = props.data || {}
35
   const user = props.data || {}
35
   const appdata = user.miniapp || {};
36
   const appdata = user.miniapp || {};
36
   const noticeTPL = (appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {}
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
   const fields = [
61
   const fields = [
51
       name: 'miniappId',
71
       name: 'miniappId',
52
       type: FieldTypes.Text,
72
       type: FieldTypes.Text,
53
       value: appdata.miniappId,
73
       value: appdata.miniappId,
74
+      props: {
75
+        disabled: !!appdata.miniappId,
76
+      },
54
       rules: [
77
       rules: [
55
         { required: true, message: '请填写 APPID' },
78
         { required: true, message: '请填写 APPID' },
56
         { pattern: /^[a-zA-Z0-9]+$/, message: 'APPID 只能由字母与数字组成' }
79
         { pattern: /^[a-zA-Z0-9]+$/, message: 'APPID 只能由字母与数字组成' }
97
     {
120
     {
98
       label: '消息通知',
121
       label: '消息通知',
99
       name: 'notice',
122
       name: 'notice',
100
-      render: () => <TplItem />,
123
+      render: <TplItem />,
101
       value: noticeTPL,
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
       action: true,
133
       action: true,
105
       render: () => {
134
       render: () => {
109
               <img src="" alt="" style={{ width: '128px' }}/>
138
               <img src="" alt="" style={{ width: '128px' }}/>
110
             </div>
139
             </div>
111
             <div className={Style['flex-auto']}>
140
             <div className={Style['flex-auto']}>
112
-              <Button type="primary" ghost onClick={checkMiniapp}>验证</Button>
141
+              <Button type="primary" ghost onClick={showModal}>验证</Button>
113
             </div>
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
           </div>
151
           </div>
115
         )
152
         )
116
       }
153
       }
138
 
175
 
139
     const tpls = [
176
     const tpls = [
140
       {
177
       {
141
-        ...notice,
142
         ...(appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {},
178
         ...(appdata.tpls || []).filter(x => x.tplType === 'notice')[0] || {},
179
+        ...notice,
143
         tplType: 'notice'
180
         tplType: 'notice'
144
-      }
181
+      },
182
+      ...(appdata.tpls || []).filter(x => x.tplType !== 'notice')
145
     ]
183
     ]
146
 
184
 
147
     const data = {
185
     const data = {
148
       ...appdata,
186
       ...appdata,
149
       ...otherData,
187
       ...otherData,
188
+      qrCode: qrCode || appdata.appdata,
150
       orgId: user.orgId,
189
       orgId: user.orgId,
151
       tpls,
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
       notification.success({ message: '保存小程序信息成功' })
199
       notification.success({ message: '保存小程序信息成功' })
156
     }).catch(x => x)
200
     }).catch(x => x)
157
   }
201
   }
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
 export default Miniapp;
212
 export default Miniapp;

+ 10
- 4
src/pages/UserManage/Editor/User.jsx View File

6
 import XForm, { FieldTypes } from '../../../components/XForm';
6
 import XForm, { FieldTypes } from '../../../components/XForm';
7
 import { fetch, apis } from '../../../utils/request';
7
 import { fetch, apis } from '../../../utils/request';
8
 
8
 
9
-const defaultPass = '123456';
9
+const defaultPass = 'abc@123';
10
 const saveUser = fetch(apis.member.save)
10
 const saveUser = fetch(apis.member.save)
11
 const updateUser = fetch(apis.member.update)
11
 const updateUser = fetch(apis.member.update)
12
 
12
 
74
   ]
74
   ]
75
 
75
 
76
   const handleSubmit = val => {
76
   const handleSubmit = val => {
77
-    const data = {
77
+    const dt = {
78
       ...val,
78
       ...val,
79
       loginName: val.loginName || val.phone,
79
       loginName: val.loginName || val.phone,
80
       loginPassword: md5(defaultPass),
80
       loginPassword: md5(defaultPass),
82
 
82
 
83
     setSubmitting(true)
83
     setSubmitting(true)
84
     if (user && user.userId) {
84
     if (user && user.userId) {
85
-      updateUser({ urlData: { id: user.userId }, data: { ...user, ...data } }).then((user) => {
85
+      const data = { ...user, ...dt }
86
+      updateUser({ urlData: { id: user.userId }, data }).then((user) => {
86
         setSubmitting(false)
87
         setSubmitting(false)
87
         notification.success({message: '编辑信息成功'})
88
         notification.success({message: '编辑信息成功'})
89
+
90
+        if (typeof props.onChange === 'function') {
91
+          props.onChange(data)
92
+        }
93
+
88
       }).catch(() => setSubmitting(false))
94
       }).catch(() => setSubmitting(false))
89
     } else {
95
     } else {
90
       saveUser({ data }).then((user) => {
96
       saveUser({ data }).then((user) => {
91
         setSubmitting(false)
97
         setSubmitting(false)
92
         notification.success({message: '新建信息成功'})
98
         notification.success({message: '新建信息成功'})
99
+        router.push(`/member/edit/${user.userId}`)
93
       }).catch(() => setSubmitting(false))
100
       }).catch(() => setSubmitting(false))
94
-      router.push(`/member/edit/${user.userId}`)
95
     }
101
     }
96
   }
102
   }
97
 
103
 

+ 10
- 2
src/pages/UserManage/Editor/index.jsx View File

27
     }
27
     }
28
   }, [props.match.params.id])
28
   }, [props.match.params.id])
29
 
29
 
30
+  const handleChangeUser = (newUser) => {
31
+    console.log(newUser)
32
+    setUser({
33
+      ...user,
34
+      ...newUser,
35
+    });
36
+  }
37
+
30
   const handleCancel = (currentTab) => () => {
38
   const handleCancel = (currentTab) => () => {
31
     if (currentTab === 1) {
39
     if (currentTab === 1) {
32
       gotoList()
40
       gotoList()
49
         </Radio.Group>
57
         </Radio.Group>
50
       </div>
58
       </div>
51
       <div style={{ width: '680px', margin: '0 auto' }}>
59
       <div style={{ width: '680px', margin: '0 auto' }}>
52
-        { tab === 1 ? <User data={user} {...props} onCancel={handleCancel(1)}/> : null}
53
-        { tab === 2 ? <MiniApp data={user} {...props} onCancel={handleCancel(2)}/> : null}
60
+        { tab === 1 ? <User data={user} {...props} onChange={handleChangeUser} onCancel={handleCancel(1)}/> : null}
61
+        { tab === 2 ? <MiniApp data={user} {...props} onChange={handleChangeUser} onCancel={handleCancel(2)}/> : null}
54
         { tab === 3 ? <Menus data={user} {...props} onCancel={handleCancel(3)}/> : null}
62
         { tab === 3 ? <Menus data={user} {...props} onCancel={handleCancel(3)}/> : null}
55
       </div>
63
       </div>
56
     </PageHeaderWrapper>
64
     </PageHeaderWrapper>

+ 1
- 2
src/pages/UserManage/index.jsx View File

70
             (<Button type="link" onClick={handleSwitch(true)} style={{ color: colorSucces }}>开启<Icon type="check" /></Button>) :
70
             (<Button type="link" onClick={handleSwitch(true)} style={{ color: colorSucces }}>开启<Icon type="check" /></Button>) :
71
             (<Button type="link" onClick={handleSwitch(false)} style={{ color: colorDanger }}>关闭<Icon type="delete" /></Button>)
71
             (<Button type="link" onClick={handleSwitch(false)} style={{ color: colorDanger }}>关闭<Icon type="delete" /></Button>)
72
           }>
72
           }>
73
-          <h3>南京楼市</h3>
73
+          <h3>{cbProps.miniappId ? cbProps.miniappName : <Warn>(小程序)未设置</Warn>}</h3>
74
         </Cell>
74
         </Cell>
75
         <div>
75
         <div>
76
           <ABCol header={'联系人'}>{cbProps.userName}</ABCol>
76
           <ABCol header={'联系人'}>{cbProps.userName}</ABCol>
77
           <ABCol header={'手机号'}>{cbProps.phone}</ABCol>
77
           <ABCol header={'手机号'}>{cbProps.phone}</ABCol>
78
-          <ABCol header={'小程序'}>{cbProps.miniappId ? cbProps.miniappName : <Warn>未设置</Warn>}</ABCol>
79
           <ABCol header={'服务到期时间'}>{cbProps.expData ? moment(cbProps.expData).format('YYYY-MM-DD') : <Warn>未设置</Warn>}</ABCol>
78
           <ABCol header={'服务到期时间'}>{cbProps.expData ? moment(cbProps.expData).format('YYYY-MM-DD') : <Warn>未设置</Warn>}</ABCol>
80
         </div>
79
         </div>
81
       </>
80
       </>

+ 22
- 2
src/services/apis.js View File

5
     current: {
5
     current: {
6
       url: `${prefix}/current`,
6
       url: `${prefix}/current`,
7
       method: 'GET',
7
       method: 'GET',
8
+      action: 'center',
8
     },
9
     },
9
     login: {
10
     login: {
10
       url: `${prefix}/signin`,
11
       url: `${prefix}/signin`,
11
       method: 'POST',
12
       method: 'POST',
13
+      action: 'center',
12
       login: true
14
       login: true
13
     },
15
     },
14
     logoff: {
16
     logoff: {
15
       url: `${prefix}/signout`,
17
       url: `${prefix}/signout`,
16
       method: 'POST',
18
       method: 'POST',
19
+      action: 'center',
17
       logout: true
20
       logout: true
18
     },
21
     },
19
   },
22
   },
21
     list: {
24
     list: {
22
       url: `${prefix}/taUser`,
25
       url: `${prefix}/taUser`,
23
       method: 'GET',
26
       method: 'GET',
27
+      action: 'center',
24
     },
28
     },
25
     get: {
29
     get: {
26
       url: `${prefix}/taUser/:id`,
30
       url: `${prefix}/taUser/:id`,
27
       method: 'GET',
31
       method: 'GET',
32
+      action: 'center',
28
     },
33
     },
29
     save: {
34
     save: {
30
       url: `${prefix}/taUser`,
35
       url: `${prefix}/taUser`,
31
       method: 'POST',
36
       method: 'POST',
37
+      action: 'center',
32
     },
38
     },
33
     update: {
39
     update: {
34
       url: `${prefix}/taUser/:id`,
40
       url: `${prefix}/taUser/:id`,
35
       method: 'PUT',
41
       method: 'PUT',
42
+      action: 'center',
36
     },
43
     },
37
     miniapp: {
44
     miniapp: {
38
-      url: `${prefix}/taMiniapp`,
39
-      method: 'POST',
45
+      edit: {
46
+        url: `${prefix}/taMiniapp`,
47
+        method: 'POST',
48
+        action: 'center',
49
+      },
50
+      check: {
51
+        url: `${prefix}/check/taMiniapp`,
52
+        method: 'POST',
53
+        action: 'center',
54
+      }
40
     },
55
     },
41
     menus: {
56
     menus: {
42
       url: `${prefix}/sysmodules`,
57
       url: `${prefix}/sysmodules`,
43
       method: 'GET',
58
       method: 'GET',
59
+      action: 'center',
44
     },
60
     },
45
     authorize: {
61
     authorize: {
46
       url: `${prefix}/sysmodules`,
62
       url: `${prefix}/sysmodules`,
47
       method: 'POST',
63
       method: 'POST',
64
+      action: 'center',
48
     },
65
     },
49
     turn: {
66
     turn: {
50
       url: `${prefix}/turn/taUser/:id/:type`,
67
       url: `${prefix}/turn/taUser/:id/:type`,
51
       method: 'PUT',
68
       method: 'PUT',
69
+      action: 'center',
52
     },
70
     },
53
     resetPass: {
71
     resetPass: {
54
       url: `${prefix}/password/taUser/:id`,
72
       url: `${prefix}/password/taUser/:id`,
55
       method: 'PUT',
73
       method: 'PUT',
74
+      action: 'center',
56
     },
75
     },
57
   },
76
   },
58
   image: {
77
   image: {
59
     upload: {
78
     upload: {
60
       url: `${prefix}/antd/image`,
79
       url: `${prefix}/antd/image`,
61
       method: 'POST',
80
       method: 'POST',
81
+      action: 'center',
62
     }
82
     }
63
   },
83
   },
64
 }
84
 }

+ 3
- 1
src/utils/request.js View File

33
 }
33
 }
34
 
34
 
35
 request.interceptors.request.use((url, options) => {
35
 request.interceptors.request.use((url, options) => {
36
-  const { urlData, headers = {}, logout = false, login = false, data, ...opts } = options
36
+  const { urlData, headers = {}, logout = false, login = false, action, data, ...opts } = options
37
   const apiURL = urlData ? replaceURLParams(url, urlData) : url
37
   const apiURL = urlData ? replaceURLParams(url, urlData) : url
38
   const token = mixStr(window.localStorage.getItem('test-foobar'))
38
   const token = mixStr(window.localStorage.getItem('test-foobar'))
39
 
39
 
42
   }
42
   }
43
 
43
 
44
   const authHeader = !login ? { Authorization: `Bearer ${token}` } : {}
44
   const authHeader = !login ? { Authorization: `Bearer ${token}` } : {}
45
+  const actionHeader = action ? { 'X-ACTION': action  }: {}
45
 
46
 
46
   return (
47
   return (
47
     {
48
     {
50
         ...opts,
51
         ...opts,
51
         headers: {
52
         headers: {
52
           ...authHeader,
53
           ...authHeader,
54
+          ...actionHeader,
53
           ...headers,
55
           ...headers,
54
         },
56
         },
55
         data,
57
         data,