zlisen 4 年之前
父節點
當前提交
435fda31ad

+ 2
- 1
config/dev.js 查看文件

5
   },
5
   },
6
   defineConstants: {
6
   defineConstants: {
7
     HOST: '"http://localhost:7080"',
7
     HOST: '"http://localhost:7080"',
8
-    WSS_HOST: '"ws://localhost:7080"',
8
+    // HOST: '"https://sgl.ycjcjy.com"',
9
+    
9
     // OSS_PATH: "https://njcj.oss-cn-shanghai.aliyuncs.com/",
10
     // OSS_PATH: "https://njcj.oss-cn-shanghai.aliyuncs.com/",
10
     // OSS_FAST_PATH: "https://njcj.oss-accelerate.aliyuncs.com/",
11
     // OSS_FAST_PATH: "https://njcj.oss-accelerate.aliyuncs.com/",
11
   },
12
   },

+ 10
- 0
config/index.js 查看文件

1
+const path = require('path')
2
+
1
 const config = {
3
 const config = {
2
   projectName: 'shigongliApp',
4
   projectName: 'shigongliApp',
3
   date: '2020-12-12',
5
   date: '2020-12-12',
65
         }
67
         }
66
       }
68
       }
67
     }
69
     }
70
+  },
71
+  alias: {
72
+    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
73
+    '@/compents': path.resolve(__dirname, '..', 'src/compents'),
74
+    '@/layout': path.resolve(__dirname, '..', 'src/layout'),
75
+    '@/store': path.resolve(__dirname, '..', 'src/store'),
76
+    '@/reducers': path.resolve(__dirname, '..', 'src/reducers'),
77
+    '@/util': path.resolve(__dirname, '..', 'src/util'),
68
   }
78
   }
69
 }
79
 }
70
 
80
 

+ 9
- 13
src/actions/user.js 查看文件

1
 import {
1
 import {
2
-  ADD,
3
-  MINUS
2
+  LOGIN,
4
 } from '../constants/user'
3
 } from '../constants/user'
5
 
4
 
6
-export const add = () => {
5
+export const login = () => {
6
+  console.log('login')
7
   return {
7
   return {
8
-    type: ADD
9
-  }
10
-}
11
-export const minus = () => {
12
-  return {
13
-    type: MINUS
8
+    type: LOGIN
14
   }
9
   }
15
 }
10
 }
16
 
11
 
17
 // 异步的action
12
 // 异步的action
18
-export function asyncAdd () {
13
+export function asyncLogin () {
14
+  console.log('asyncLogin')
19
   return dispatch => {
15
   return dispatch => {
20
-    setTimeout(() => {
21
-      dispatch(add())
22
-    }, 2000)
16
+    console.log('asyncLogin')
17
+      dispatch(login())
18
+    
23
   }
19
   }
24
 }
20
 }

+ 45
- 13
src/app.js 查看文件

1
-
2
 import 'taro-ui/dist/style/index.scss'
1
 import 'taro-ui/dist/style/index.scss'
3
-import React, { Component } from 'react'
4
-import { Provider } from 'react-redux'
2
+import React, {
3
+  Component
4
+} from 'react'
5
+import Taro from '@tarojs/taro'
6
+import {
7
+  Provider,connect
8
+} from 'react-redux'
5
 
9
 
6
 import configStore from './store'
10
 import configStore from './store'
11
+import {asyncLogin} from './reducers/user'
7
 
12
 
8
 import './app.scss'
13
 import './app.scss'
14
+import request from './util/request'
9
 
15
 
10
 const store = configStore()
16
 const store = configStore()
11
 
17
 
12
 class App extends Component {
18
 class App extends Component {
13
-  componentDidMount () {}
19
+  componentDidMount() {
20
+console.log(this.props,'this.props')
21
+   
22
+  }
23
+
24
+  onLaunch () {
25
+    wx.login({
26
+      success (res) {
27
+        if (res.code) {
28
+          //发起网络请求
29
+          // console.log(res.code,store.getState(),'code')
30
+          // asyncLogin().dispatch()
31
+          // store.dispatch(asyncLogin())
32
+          // asyncLogin()
33
+          request({url:`/login?code=${res.code}`,method:"post"}).then((res)=>{
34
+            console.log(res.data.data.token,'res.data.data.token')
35
+            store.dispatch({type:'LOGIN',user:res.data.data})
36
+            Taro.setStorage({
37
+              key:"token",
38
+              data:res.data.data.token
39
+            })
40
+          })
41
+        } else {
42
+          console.log('登录失败!' + res.errMsg)
43
+        }
44
+      }
45
+    })
46
+  }
47
+
48
+  componentDidShow() {}
14
 
49
 
15
-  componentDidShow () {}
50
+  componentDidHide() {}
16
 
51
 
17
-  componentDidHide () {}
52
+  componentDidCatchError() {}
18
 
53
 
19
-  componentDidCatchError () {}
20
 
54
 
21
   // 在 App 类中的 render() 函数没有实际作用
55
   // 在 App 类中的 render() 函数没有实际作用
22
   // 请勿修改此函数
56
   // 请勿修改此函数
23
-  render () {
24
-    return (
25
-      <Provider store={store}>
26
-        {this.props.children}
27
-      </Provider>
57
+  render() {
58
+    return ( <Provider store = {store} > 
59
+        {this.props.children} 
60
+    </Provider>
28
     )
61
     )
29
   }
62
   }
30
 }
63
 }
31
 
64
 
32
 export default App
65
 export default App
33
-

+ 1
- 1
src/constants/user.js 查看文件

1
-export const ADD = 'ADD'
1
+export const LOGIN = 'LOGIN'
2
 export const MINUS = 'MINUS'
2
 export const MINUS = 'MINUS'

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

13
 import request from '../../util/request'
13
 import request from '../../util/request'
14
 const index = (props) => {
14
 const index = (props) => {
15
 
15
 
16
-  const page = useSelector(state => state.page)
17
 
16
 
18
   const user = useSelector(state => state.user)
17
   const user = useSelector(state => state.user)
19
 
18
 
21
   const [pageState, SetPageState] = useState('1')
20
   const [pageState, SetPageState] = useState('1')
22
   const [list, setList] = useState([])
21
   const [list, setList] = useState([])
23
   useEffect(() => {
22
   useEffect(() => {
24
-
25
-    console.log(page,'page')
26
     setList([
23
     setList([
27
       {
24
       {
28
         name: 'zhou',
25
         name: 'zhou',
40
 
37
 
41
     // fetch({ url: API_CARDS_LIST, payload })
38
     // fetch({ url: API_CARDS_LIST, payload })
42
 
39
 
43
-    request({
44
-      url:'/api/taHouseSurround',
45
-      method: 'get',
46
-      // params:{
47
-      //   id:3,
48
-
49
-      //   b:3
50
-      // }
51
-    })
40
+  
52
 
41
 
53
 
42
 
54
   }, [])
43
   }, [])
74
 
63
 
75
       {user.role==roleList.customer&&<Customer></Customer>  }
64
       {user.role==roleList.customer&&<Customer></Customer>  }
76
       {user.role==roleList.landlord&&<Landlord></Landlord>  }
65
       {user.role==roleList.landlord&&<Landlord></Landlord>  }
77
-      {user.role==roleList.adminuser&&<AdminUser></AdminUser>  }
78
         {/* {userRole == 1 ? <Register userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></Register> :
66
         {/* {userRole == 1 ? <Register userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></Register> :
79
           <View>userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}
67
           <View>userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}
80
             {(userRole == 'guide' || userRole == 2) && <Guide userRole={userRole}/>}
68
             {(userRole == 'guide' || userRole == 2) && <Guide userRole={userRole}/>}

+ 18
- 4
src/pages/landlord/index.jsx 查看文件

1
 import React, { useEffect, useMemo, useState } from 'react'
1
 import React, { useEffect, useMemo, useState } from 'react'
2
-import Taro, {  } from "@tarojs/taro";
2
+import Taro, { useDidShow } from "@tarojs/taro";
3
 import { useSelector } from 'react-redux'
3
 import { useSelector } from 'react-redux'
4
 import { View, ScrollView, Button } from '@tarojs/components'
4
 import { View, ScrollView, Button } from '@tarojs/components'
5
 import Layout from '../../layout/index'
5
 import Layout from '../../layout/index'
9
 import Recommend from '../recommend/index'
9
 import Recommend from '../recommend/index'
10
 import HouseLIst from '../house/list/index'
10
 import HouseLIst from '../house/list/index'
11
 import { AtFloatLayout } from "taro-ui"
11
 import { AtFloatLayout } from "taro-ui"
12
+import request from '@/util/request'
12
 import './index.scss'
13
 import './index.scss'
13
 
14
 
14
 const index = (props) => {
15
 const index = (props) => {
15
 
16
 
16
-  const page = useSelector(state => state.page)
17
 
17
 
18
   const user = useSelector(state => state.user)
18
   const user = useSelector(state => state.user)
19
   const [isOpened, setIsOpened] = useState(false)
19
   const [isOpened, setIsOpened] = useState(false)
22
   const [list, setList] = useState([])
22
   const [list, setList] = useState([])
23
   const [radioHouseData, setRadioHouseData] = useState()
23
   const [radioHouseData, setRadioHouseData] = useState()
24
   const [radioHouseState, setRadioHouseState] = useState(false)
24
   const [radioHouseState, setRadioHouseState] = useState(false)
25
- 
25
+  console.log(user,'99999999')
26
   useEffect(() => {
26
   useEffect(() => {
27
 
27
 
28
-    console.log(page, 'page')
28
+   
29
+
29
     setList([
30
     setList([
30
       {
31
       {
31
         name: 'zhou',
32
         name: 'zhou',
40
         phone: '177'
41
         phone: '177'
41
       }
42
       }
42
     ])
43
     ])
44
+
45
+    getHouseList()
43
   }, [])
46
   }, [])
44
 
47
 
48
+  // useDidShow(()=>{
49
+  //   getHouseList()
50
+  // })
51
+
52
+  const getHouseList=()=>{
53
+    request({
54
+      url:'/taHouse',
55
+      method: 'get',
56
+    })
57
+  }
58
+
45
 
59
 
46
 
60
 
47
   const handleClose = () => {
61
   const handleClose = () => {

+ 2
- 2
src/reducers/guide.js 查看文件

1
-import { ADD, MINUS } from '../constants/user'
1
+import { LOGIN, MINUS } from '../constants/user'
2
 
2
 
3
 // landlord: 'landlord',
3
 // landlord: 'landlord',
4
 //     customer:'customer'
4
 //     customer:'customer'
15
 
15
 
16
 export default function counter (state = INITIAL_STATE, action) {
16
 export default function counter (state = INITIAL_STATE, action) {
17
   switch (action.type) {
17
   switch (action.type) {
18
-    case ADD:
18
+    case LOGIN:
19
       return {
19
       return {
20
         ...state,
20
         ...state,
21
         num: state.num + 1
21
         num: state.num + 1

+ 0
- 4
src/reducers/index.js 查看文件

1
 import { combineReducers } from 'redux'
1
 import { combineReducers } from 'redux'
2
 import user from './user'
2
 import user from './user'
3
-import page from './page'
4
-import guide from './guide'
5
 
3
 
6
 export default combineReducers({
4
 export default combineReducers({
7
   user,
5
   user,
8
-  page,
9
-  guide,
10
 })
6
 })

+ 2
- 2
src/reducers/page.js 查看文件

1
-import { ADD, MINUS } from '../constants/user'
1
+import { LOGIN, MINUS } from '../constants/user'
2
 
2
 
3
 // landlord: 'landlord',
3
 // landlord: 'landlord',
4
 //     customer:'customer'
4
 //     customer:'customer'
11
 
11
 
12
 export default function counter (state = INITIAL_STATE, action) {
12
 export default function counter (state = INITIAL_STATE, action) {
13
   switch (action.type) {
13
   switch (action.type) {
14
-    case ADD:
14
+    case LOGIN:
15
       return {
15
       return {
16
         ...state,
16
         ...state,
17
         num: state.num + 1
17
         num: state.num + 1

+ 31
- 13
src/reducers/user.js 查看文件

1
 import {
1
 import {
2
-  ADD,
2
+  LOGIN,
3
   MINUS
3
   MINUS
4
 } from '../constants/user'
4
 } from '../constants/user'
5
 
5
 
8
 // adminuser
8
 // adminuser
9
 const INITIAL_STATE = {
9
 const INITIAL_STATE = {
10
   // role: 'adminuser',
10
   // role: 'adminuser',
11
-  // role: 'landlord',
12
-  role: 'customer'
11
+  // role:''
12
+  // role: 'customer'
13
 }
13
 }
14
 
14
 
15
-export default function counter(state = INITIAL_STATE, action) {
15
+export const login = () => {
16
+  return {
17
+    type: LOGIN
18
+  }
19
+}
20
+
21
+// 异步的action
22
+export function asyncLogina() {
23
+  console.log('asyncLogin22')
24
+  return dispatch => {
25
+    dispatch({
26
+      type: 'LOGIN',
27
+      data: '333'
28
+    })
29
+
30
+  }
31
+}
32
+
33
+export default function user(state = INITIAL_STATE, action) {
34
+  console.log(state, 'state33')
16
   switch (action.type) {
35
   switch (action.type) {
17
-    case ADD:
36
+    case 'LOGIN': {
37
+      console.log(state,action, 'state')
18
       return {
38
       return {
19
         ...state,
39
         ...state,
20
-        num: state.num + 1
40
+        ...action.user,
41
+        role: 'landlord',
21
       }
42
       }
22
-      case MINUS:
23
-        return {
24
-          ...state,
25
-          num: state.num - 1
26
-        }
27
-        default:
28
-          return state
43
+    }
44
+
45
+    default:
46
+      return state
29
   }
47
   }
30
 }
48
 }

+ 20
- 9
src/util/request.js 查看文件

4
 
4
 
5
 export default async (options) => {
5
 export default async (options) => {
6
   const opts = optionBuilder(options)
6
   const opts = optionBuilder(options)
7
-  console.log(opts, "optsoptsoptsoptsoptsoptsoptsoptsoptsopts")
8
 
7
 
9
   return Taro.request(opts[0])
8
   return Taro.request(opts[0])
10
-    .then((res) =>{console.log('3322'); reqSuccess(res, opts)})
11
-    .catch((err) =>{console.log('333221'); reqFail(err, opts)})
9
+    .then((res) => {
10
+      // console.log('3322');
11
+      return res
12
+    })
13
+    .catch((err) => {
14
+      // console.log('333221');
15
+      return err
16
+    })
12
 }
17
 }
13
 
18
 
14
 
19
 
19
     method = 'GET',
24
     method = 'GET',
20
     showToast = true,
25
     showToast = true,
21
     autoLogin = true,
26
     autoLogin = true,
27
+    params = {},
22
     header
28
     header
23
   } = options
29
   } = options
24
-//   const showMessage = Object.prototype.hasOwnProperty.call(payload, 'showToast') ? payload.showToast : showToast
25
-//   const consultant = Taro.getStorageSync('consultantId') || ''
26
-//   const recommender = Taro.getStorageSync('recommender') || ''
27
-
30
+  //   const showMessage = Object.prototype.hasOwnProperty.call(payload, 'showToast') ? payload.showToast : showToast
31
+  //   const consultant = Taro.getStorageSync('consultantId') || ''
32
+  //   const recommender = Taro.getStorageSync('recommender') || ''
33
+  let api = `/api/ma${url}`
34
+  if (method == 'GET' && JSON.stringify(params) != "{}") {
35
+    api = `${api}?${paramsToString(params)}`
36
+  }
37
+  const token = Taro.getStorageSync('token')||''
38
+  console.log(token,'token')
28
   return [{
39
   return [{
29
-      url:`${baseURL}${url}`,
40
+      url: `${baseURL}${api}`,
30
       method,
41
       method,
31
       data,
42
       data,
32
       header: {
43
       header: {
33
         'content-type': 'application/json',
44
         'content-type': 'application/json',
34
-        // 'authorization': `Bearer ${Taro.getStorageSync('token')}`,
45
+        'authorization': `X-Authorization-JWT ${token}`,
35
         // 'appId': appId,
46
         // 'appId': appId,
36
         // 'x-action': 'miniapp',
47
         // 'x-action': 'miniapp',
37
         // 'x-version': Version,
48
         // 'x-version': Version,

+ 1
- 1
src/util/userRole.js 查看文件

1
 export default {
1
 export default {
2
     landlord: 'landlord',
2
     landlord: 'landlord',
3
     customer:'customer',
3
     customer:'customer',
4
-    adminuser:'adminuser'
4
+    // adminuser:'adminuser'
5
 }
5
 }