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

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

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

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

@@ -1,3 +1,5 @@
1
+const path = require('path')
2
+
1 3
 const config = {
2 4
   projectName: 'shigongliApp',
3 5
   date: '2020-12-12',
@@ -65,6 +67,14 @@ const config = {
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,24 +1,20 @@
1 1
 import {
2
-  ADD,
3
-  MINUS
2
+  LOGIN,
4 3
 } from '../constants/user'
5 4
 
6
-export const add = () => {
5
+export const login = () => {
6
+  console.log('login')
7 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 12
 // 异步的action
18
-export function asyncAdd () {
13
+export function asyncLogin () {
14
+  console.log('asyncLogin')
19 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,33 +1,65 @@
1
-
2 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 10
 import configStore from './store'
11
+import {asyncLogin} from './reducers/user'
7 12
 
8 13
 import './app.scss'
14
+import request from './util/request'
9 15
 
10 16
 const store = configStore()
11 17
 
12 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 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 65
 export default App
33
-

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

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

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

@@ -13,7 +13,6 @@ import './index.scss'
13 13
 import request from '../../util/request'
14 14
 const index = (props) => {
15 15
 
16
-  const page = useSelector(state => state.page)
17 16
 
18 17
   const user = useSelector(state => state.user)
19 18
 
@@ -21,8 +20,6 @@ const index = (props) => {
21 20
   const [pageState, SetPageState] = useState('1')
22 21
   const [list, setList] = useState([])
23 22
   useEffect(() => {
24
-
25
-    console.log(page,'page')
26 23
     setList([
27 24
       {
28 25
         name: 'zhou',
@@ -40,15 +37,7 @@ const index = (props) => {
40 37
 
41 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,7 +63,6 @@ const index = (props) => {
74 63
 
75 64
       {user.role==roleList.customer&&<Customer></Customer>  }
76 65
       {user.role==roleList.landlord&&<Landlord></Landlord>  }
77
-      {user.role==roleList.adminuser&&<AdminUser></AdminUser>  }
78 66
         {/* {userRole == 1 ? <Register userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}></Register> :
79 67
           <View>userRole={userRole} list={list} onChange={(e) => onRegisterChange(e)}
80 68
             {(userRole == 'guide' || userRole == 2) && <Guide userRole={userRole}/>}

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

@@ -1,5 +1,5 @@
1 1
 import React, { useEffect, useMemo, useState } from 'react'
2
-import Taro, {  } from "@tarojs/taro";
2
+import Taro, { useDidShow } from "@tarojs/taro";
3 3
 import { useSelector } from 'react-redux'
4 4
 import { View, ScrollView, Button } from '@tarojs/components'
5 5
 import Layout from '../../layout/index'
@@ -9,11 +9,11 @@ import Guide from '../guide/index'
9 9
 import Recommend from '../recommend/index'
10 10
 import HouseLIst from '../house/list/index'
11 11
 import { AtFloatLayout } from "taro-ui"
12
+import request from '@/util/request'
12 13
 import './index.scss'
13 14
 
14 15
 const index = (props) => {
15 16
 
16
-  const page = useSelector(state => state.page)
17 17
 
18 18
   const user = useSelector(state => state.user)
19 19
   const [isOpened, setIsOpened] = useState(false)
@@ -22,10 +22,11 @@ const index = (props) => {
22 22
   const [list, setList] = useState([])
23 23
   const [radioHouseData, setRadioHouseData] = useState()
24 24
   const [radioHouseState, setRadioHouseState] = useState(false)
25
- 
25
+  console.log(user,'99999999')
26 26
   useEffect(() => {
27 27
 
28
-    console.log(page, 'page')
28
+   
29
+
29 30
     setList([
30 31
       {
31 32
         name: 'zhou',
@@ -40,8 +41,21 @@ const index = (props) => {
40 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 61
   const handleClose = () => {

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

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

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

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

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

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

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

@@ -1,5 +1,5 @@
1 1
 import {
2
-  ADD,
2
+  LOGIN,
3 3
   MINUS
4 4
 } from '../constants/user'
5 5
 
@@ -8,23 +8,41 @@ import {
8 8
 // adminuser
9 9
 const INITIAL_STATE = {
10 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 35
   switch (action.type) {
17
-    case ADD:
36
+    case 'LOGIN': {
37
+      console.log(state,action, 'state')
18 38
       return {
19 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,11 +4,16 @@ const baseURL = HOST
4 4
 
5 5
 export default async (options) => {
6 6
   const opts = optionBuilder(options)
7
-  console.log(opts, "optsoptsoptsoptsoptsoptsoptsoptsoptsopts")
8 7
 
9 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,19 +24,25 @@ export function optionBuilder(options) {
19 24
     method = 'GET',
20 25
     showToast = true,
21 26
     autoLogin = true,
27
+    params = {},
22 28
     header
23 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 39
   return [{
29
-      url:`${baseURL}${url}`,
40
+      url: `${baseURL}${api}`,
30 41
       method,
31 42
       data,
32 43
       header: {
33 44
         'content-type': 'application/json',
34
-        // 'authorization': `Bearer ${Taro.getStorageSync('token')}`,
45
+        'authorization': `X-Authorization-JWT ${token}`,
35 46
         // 'appId': appId,
36 47
         // 'x-action': 'miniapp',
37 48
         // 'x-version': Version,

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

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