zlisen 4 年之前
父節點
當前提交
fb4d34ea97
共有 6 個文件被更改,包括 95 次插入56 次删除
  1. 3
    3
      config/dev.js
  2. 9
    2
      src/app.js
  3. 26
    12
      src/compents/tab/index.jsx
  4. 21
    27
      src/pages/house/addnewhouse/index.jsx
  5. 1
    1
      src/pages/house/index.jsx
  6. 35
    11
      src/util/request.js

+ 3
- 3
config/dev.js 查看文件

@@ -4,10 +4,10 @@ module.exports = {
4 4
     NODE_ENV: '"development"'
5 5
   },
6 6
   defineConstants: {
7
-    HOST: '"http://localhost:7080"',
7
+    // HOST: '"http://localhost:7080"',
8 8
     // HOST: '"https://sgl.ycjcjy.com"',
9
-    // HOST: '"http://192.168.31.68:7080"',
10
-    // HOST: '"http://192.168.211.181:7080"',
9
+    HOST: '"http://192.168.31.211:7080"',
10
+    // HOST: '"http://192.168.211.105:7080"',
11 11
  
12 12
     // OSS_PATH: "https://njcj.oss-cn-shanghai.aliyuncs.com/",
13 13
     // OSS_FAST_PATH: "https://njcj.oss-accelerate.aliyuncs.com/",

+ 9
- 2
src/app.js 查看文件

@@ -19,19 +19,28 @@ class App extends Component {
19 19
   componentDidMount() {}
20 20
 
21 21
   onLaunch () {
22
+  
23
+  }
24
+
25
+  componentDidShow() {
22 26
     wx.login({
23 27
       success (res) {
24 28
         if (res.code) {
25 29
           //发起网络请求
26 30
 
27 31
           request({url:`/login?code=${res.code}`,method:"post"}).then((res)=>{
32
+            console.log(res,'22222222222')
28 33
             try {
29 34
               Taro.setStorageSync('token', res.data.data.token)
30 35
               store.dispatch({type:'LOGIN',user:res.data.data})
31 36
             } catch (e) { }
32 37
             
33 38
             
39
+          }).catch(err=>{
40
+            console.log(err,'3333333333')
34 41
           })
42
+
43
+          
35 44
         } else {
36 45
           console.log('登录失败!' + res.errMsg)
37 46
         }
@@ -39,8 +48,6 @@ class App extends Component {
39 48
     })
40 49
   }
41 50
 
42
-  componentDidShow() {}
43
-
44 51
   componentDidHide() {}
45 52
 
46 53
   componentDidCatchError() {}

+ 26
- 12
src/compents/tab/index.jsx 查看文件

@@ -21,7 +21,7 @@ const tab = (props) => {
21 21
 
22 22
     const user = useSelector(state => state.user)
23 23
 
24
-    const { value, openType, pageState, formType, color, ...prop } = props
24
+    const { value, openType, pageState, formType, color, styleType='', ...prop } = props
25 25
 
26 26
     const [state, setState] = useState(1)
27 27
     console.log(props, openType, 'formType')
@@ -33,20 +33,34 @@ const tab = (props) => {
33 33
     //     color: #fed12f;
34 34
     // }${props.className}
35 35
     return <View className='tab'>
36
-        {value.length == 1 && 
36
+        {
37
+        value.length == 1 && 
37 38
         <>
38
-        {openType &&  <button openType="share" className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</button>}
39
-        {!openType && <View className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</View>}
39
+            {openType &&  <button openType="share" className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</button>}
40
+            {!openType && <View className={`tab,tab1,${props.className}`} style={{ backgroundColor: getColor(user.role), color }} onClick={() => props.onClick('2')}>{value[0]}</View>}
40 41
         </>
41 42
         }
42
-        {value.length == 2 && <View className={`tab,tab2,${props.className}`} style={{ display: 'flex', }}>
43
-            <View style={{ width: '50%' }} style={pageState == '2' ? { color: getColor(user.role), width: '50%' } : { width: '50%' }} onClick={props.onClick[0]}>{value[0]}</View>
44
-            {formType && <Button className='tab-btn' formType="submit" plain={true} style={pageState == '3' ? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}>{value[1]}</Button>}
45
-            {openType && <button className='tab-btn' openType="share" plain={true} style={pageState == '3' ? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}>{value[1]}</button>}
46
-            {!formType&&!openType &&
47
-                <View style={{ width: '50%' }} style={pageState == '3' ? { color: getColor(user.role), width: '50%' } : { width: '50%' }} onClick={props.onClick[1]}>{value[1]}</View>
48
-            }
49
-        </View>}
43
+        {
44
+            value.length == 2 && <View className={`tab,tab2,${props.className}`} style={{ display: 'flex', }}>
45
+            <View style={{ width: '50%' }} style={pageState == '2'&&styleType!='tab' ? { color: getColor(user.role), width: '50%' } : { color:pageState != '2'&&styleType=='tab'?getColor(user.role):undefined, width: '50%' }} onClick={props.onClick[0]}>{value[0]}</View>
46
+                {formType && 
47
+                <Button className='tab-btn' 
48
+                    formType="submit" 
49
+                    plain={true} 
50
+                    style={pageState == '3' &&styleType!='tab'? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}
51
+                >{value[1]}
52
+                </Button>}
53
+                {openType && 
54
+                <button className='tab-btn' 
55
+                    openType="share" plain={true} style={pageState == '3'&&styleType!='tab' ? { color: getColor(user.role), width: '50%', border: 'none' } : { width: '50%', border: 'none' }}>{value[1]}</button>}
56
+                {!formType&&!openType &&
57
+                    <View style={{ width: '50%' }} 
58
+                    style={pageState == '3'&&styleType!='tab' ? { color: getColor(user.role), width: '50%' } : { color:pageState != '3'&&styleType=='tab'?getColor(user.role):undefined, width: '50%' }} 
59
+                    onClick={props.onClick[1]}
60
+                >{value[1]}</View>
61
+                }
62
+            </View>
63
+        }
50 64
 
51 65
     </View>
52 66
 };

+ 21
- 27
src/pages/house/addnewhouse/index.jsx 查看文件

@@ -69,42 +69,36 @@ const index = (props) => {
69 69
             desc:imgUrl,
70 70
         }
71 71
         console.log(data,e.detail.value,'formSubmit')
72
-        request({ url: '/taHouse', method: 'post', data }).then((res) => {
72
+        request({ url: '/taHouse', method: 'post', data:{...data} }).then((res) => {
73 73
             if (res.data.code == 1000)
74 74
                 Taro.navigateBack({
75 75
                     delta: 1
76 76
                 })
77 77
         })
78 78
 
79
-        // {shopId,
80
-
81
-        //     "address": "string",
82
-
83
-        //     "lngLat": "string",
84
-        //     "parkLngLat": "string",
85
-        //     "parking": "string",
86
-
87
-        //     "surroundList": [
88
-        //       {
89
-        //         "createDate": "2020-12-29T15:38:53.177Z",
90
-        //         "houseId": "string",
91
-        //         "image": "string",
92
-        //         "imageId": "string",
93
-        //         "sortNo": 0,
94
-        //         "status": 0,
95
-        //         "surroundId": "string"
96
-        //       }
97
-        //     ],
98
-        //     "title": "string",
99
-        //     "wifiName": "string",
100
-        //     "wifiPassword": "string"
101
-        //   }
102 79
     }
103 80
 
104 81
     const formReset = () => {
105 82
         console.log('formReset')
106 83
     }
107 84
 
85
+    const onAdderssChange = (e) => {
86
+        console.log(e,'formReset')
87
+        setAddress({
88
+            ...address,
89
+            address:e.detail.value
90
+        })
91
+    }
92
+
93
+    const onParkingAdderssChange = (e) => {
94
+        console.log(e,'formReset')
95
+        setParking({
96
+            ...address,
97
+            parking:e.detail.value
98
+        })
99
+    }
100
+    
101
+
108 102
     return <View className='addnewhouse'>
109 103
 
110 104
         <Form onSubmit={formSubmit} onReset={formReset}>
@@ -144,7 +138,7 @@ const index = (props) => {
144 138
                 <View className='inputstyle-view'>
145 139
                     <Text className='title'>具体地址</Text>
146 140
                     <Container className='inputstyle-view-card ' style={{ borderRadius: '20rpx', padding: '0 40rpx' }} >
147
-                        <Input name='address' value={address.address} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
141
+                        <Input name='address' value={address.address} onInput={onAdderssChange} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
148 142
                     </Container>
149 143
                 </View>
150 144
                 <View className='inputstyle-view'>
@@ -155,7 +149,7 @@ const index = (props) => {
155 149
 
156 150
                         </Container>
157 151
                         <Container className='map-view-icon' onClick={() => onChooseLocation('parking')}>
158
-                            <Image className='icon' mode='widthFix' style={{ width: '100%' }} style={{ width: '40rpx' }} src={locationicon} />
152
+                            <Image className='icon' mode='widthFix'  style={{ width: '100%' }} style={{ width: '40rpx' }} src={locationicon} />
159 153
 
160 154
                         </Container>
161 155
                     </View>
@@ -163,7 +157,7 @@ const index = (props) => {
163 157
                 <View className='inputstyle-view'>
164 158
                     <Text className='title'>具体地址</Text>
165 159
                     <Container className='inputstyle-view-card ' style={{ borderRadius: '20rpx', padding: '0 40rpx' }} >
166
-                        <Input name='parking' value={parking.address} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
160
+                        <Input name='parking' value={parking.address} onInput={onParkingAdderssChange} placeholderClass='placeholderinput' className='input' type='text' placeholder='' />
167 161
                     </Container>
168 162
                 </View>
169 163
                 <View className='inputstyle-view'>

+ 1
- 1
src/pages/house/index.jsx 查看文件

@@ -79,7 +79,7 @@ const house = (props) => {
79 79
                 {pageState == '2' && <Guide houseId={houseId} dataSource={dataSource}></Guide>}
80 80
                 {pageState == '3' && <Recommend houseId={houseId} dataSource={imgSource}></Recommend>}
81 81
             </Layout>
82
-            {pageState != '1' && <Tab value={['入住指引', '房东推荐']} pageState={pageState} onClick={[(e) => setPageState('2'), (e) => setPageState('3')]}></Tab>}
82
+            {pageState != '1' && <Tab styleType='tab' value={['入住指引', '房东推荐']} pageState={pageState} onClick={[(e) => setPageState('2'), (e) => setPageState('3')]}></Tab>}
83 83
 
84 84
         </View>
85 85
 

+ 35
- 11
src/util/request.js 查看文件

@@ -1,5 +1,7 @@
1 1
 import Taro from '@tarojs/taro'
2
-import { useSelector } from 'react-redux'
2
+import {
3
+  useSelector
4
+} from 'react-redux'
3 5
 import user from '../reducers/user'
4 6
 
5 7
 const baseURL = HOST
@@ -9,12 +11,34 @@ export default async (options) => {
9 11
 
10 12
   return Taro.request(opts[0])
11 13
     .then((res) => {
12
-      // console.log('3322');
13
-      return res
14
+      const {
15
+        data,
16
+        code,
17
+        message
18
+      } = typeof res.data === 'string' ? JSON.parse(res.data) : res.data
19
+      if (code == '1000') {
20
+        return res
21
+      } else if (code === 1005) {
22
+        Taro.showToast({
23
+          title: message,
24
+          icon: 'none'
25
+        })
26
+        throw res
27
+      } else {
28
+        throw res
29
+      }
14 30
     })
15 31
     .catch((err) => {
16
-      // console.log('333221');
17
-      return err
32
+      console.log(err, '111111111111');
33
+      if (err.errMsg === "request:fail ") {
34
+        Taro.showToast({
35
+          title: "请检查网络",
36
+          icon: 'none'
37
+        })
38
+        throw err
39
+      }
40
+
41
+      throw err
18 42
     })
19 43
 }
20 44
 
@@ -38,7 +62,7 @@ export function optionBuilder(options) {
38 62
     api = `${api}?${paramsToString(params)}`
39 63
   }
40 64
   // user.user?.token||
41
-  const token = Taro.getStorageSync('token')||''
65
+  const token = Taro.getStorageSync('token') || ''
42 66
   // console.log(token,'token')
43 67
   return [{
44 68
       url: `${baseURL}${api}`,
@@ -46,7 +70,7 @@ export function optionBuilder(options) {
46 70
       data,
47 71
       header: {
48 72
         'content-type': 'application/json',
49
-      'X-Authorization-JWT': `${token}`,
73
+        'X-Authorization-JWT': `${token}`,
50 74
         // 'appId': appId,
51 75
         // 'x-action': 'miniapp',
52 76
         // 'x-version': Version,
@@ -63,13 +87,13 @@ export function optionBuilder(options) {
63 87
 }
64 88
 
65 89
 
66
-export const uploadFiles = async (files,url) => {
90
+export const uploadFiles = async (files, url) => {
67 91
   const uploads = []
68
-  const token = Taro.getStorageSync('token')||''
92
+  const token = Taro.getStorageSync('token') || ''
69 93
   for (var i = 0; i < files.length; i++) {
70 94
     uploads[i] = new Promise((resolve, reject) => {
71 95
       Taro.uploadFile({
72
-        url:  url||`${baseURL}/api/ma/image`,
96
+        url: url || `${baseURL}/api/ma/image`,
73 97
         filePath: files[i],
74 98
         header: {
75 99
           'authorization': `X-Authorization-JWT ${token}`,
@@ -110,4 +134,4 @@ function paramsToString(params) {
110 134
 function composeKeyValue(k, v, encode) {
111 135
 
112 136
   return encode === false ? `${k}=${v}` : `${encodeURIComponent(k)}=${encodeURIComponent(v)}`
113
-}
137
+}