张延森 5 gadus atpakaļ
vecāks
revīzija
4b3c73b683

+ 58
- 14
src/pages/UserManage/Editor/Miniapp.jsx Parādīt failu

@@ -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;

+ 10
- 4
src/pages/UserManage/Editor/User.jsx Parādīt failu

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

@@ -27,6 +27,14 @@ export default (props) => {
27 27
     }
28 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 38
   const handleCancel = (currentTab) => () => {
31 39
     if (currentTab === 1) {
32 40
       gotoList()
@@ -49,8 +57,8 @@ export default (props) => {
49 57
         </Radio.Group>
50 58
       </div>
51 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 62
         { tab === 3 ? <Menus data={user} {...props} onCancel={handleCancel(3)}/> : null}
55 63
       </div>
56 64
     </PageHeaderWrapper>

+ 1
- 2
src/pages/UserManage/index.jsx Parādīt failu

@@ -70,12 +70,11 @@ export default (props) => {
70 70
             (<Button type="link" onClick={handleSwitch(true)} style={{ color: colorSucces }}>开启<Icon type="check" /></Button>) :
71 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 74
         </Cell>
75 75
         <div>
76 76
           <ABCol header={'联系人'}>{cbProps.userName}</ABCol>
77 77
           <ABCol header={'手机号'}>{cbProps.phone}</ABCol>
78
-          <ABCol header={'小程序'}>{cbProps.miniappId ? cbProps.miniappName : <Warn>未设置</Warn>}</ABCol>
79 78
           <ABCol header={'服务到期时间'}>{cbProps.expData ? moment(cbProps.expData).format('YYYY-MM-DD') : <Warn>未设置</Warn>}</ABCol>
80 79
         </div>
81 80
       </>

+ 22
- 2
src/services/apis.js Parādīt failu

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

+ 3
- 1
src/utils/request.js Parādīt failu

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