Showing
10 changed files
with
92 additions
and
20 deletions
No preview for this file type
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | "author": "", | 14 | "author": "", |
15 | "license": "MIT", | 15 | "license": "MIT", |
16 | "dependencies": { | 16 | "dependencies": { |
17 | + "@tarojs/async-await": "^1.0.7", | ||
17 | "@tarojs/components": "^1.0.0-beta.11", | 18 | "@tarojs/components": "^1.0.0-beta.11", |
18 | "@tarojs/redux": "^1.0.7", | 19 | "@tarojs/redux": "^1.0.7", |
19 | "@tarojs/router": "^1.0.0-beta.11", | 20 | "@tarojs/router": "^1.0.0-beta.11", |
src/actions/user.js
0 → 100644
1 | +import { | ||
2 | + SET_OPENID | ||
3 | +} from '../constants/user' | ||
4 | + | ||
5 | +export const setOpenId = function(openID) { | ||
6 | + return { | ||
7 | + type: SET_OPENID, | ||
8 | + openID | ||
9 | + } | ||
10 | +} | ||
11 | +export const wechatIsBind = function() { | ||
12 | + return dispatch => { | ||
13 | + return new Promise((resolve, reject) => { | ||
14 | + wx.login({ | ||
15 | + success: (res) => { | ||
16 | + dispatch(setOpenId('openId')) | ||
17 | + return resolve({name: 'openId'}); | ||
18 | + } | ||
19 | + }); | ||
20 | + }) | ||
21 | + } | ||
22 | +} | ||
23 | +export const wechatLogin = function() { | ||
24 | + return dispatch => { | ||
25 | + return new Promise((resolve, reject) => { | ||
26 | + wx.login({ | ||
27 | + success: (res) => { | ||
28 | + dispatch(setOpenId('openId')) | ||
29 | + return resolve({name: 'openId'}); | ||
30 | + } | ||
31 | + }); | ||
32 | + }) | ||
33 | + } | ||
34 | +} |
1 | import Taro, { Component } from '@tarojs/taro' | 1 | import Taro, { Component } from '@tarojs/taro' |
2 | import { Provider, connect } from '@tarojs/redux' | 2 | import { Provider, connect } from '@tarojs/redux' |
3 | +import { bindActionCreators } from 'redux'; | ||
3 | import Index from './pages/index' | 4 | import Index from './pages/index' |
4 | -import configStore from './store' | ||
5 | -import user from './utils/user'; | 5 | +import createStore from './store' |
6 | +import userUtil from './utils/user'; | ||
6 | import {common as commonModel} from './models'; | 7 | import {common as commonModel} from './models'; |
7 | -import './app.scss' | ||
8 | - | ||
9 | -const store = configStore() | ||
10 | 8 | ||
11 | import globalData from './actions/globalData'; | 9 | import globalData from './actions/globalData'; |
12 | -import { bindActionCreators } from 'redux'; | 10 | +import * as user from './actions/user'; |
11 | + | ||
12 | +import './app.scss' | ||
13 | + | ||
14 | +const store = createStore(); | ||
13 | 15 | ||
14 | -@connect(({ globalData }) => ({ | ||
15 | - globalData | 16 | +@connect(({ globalData, user }) => ({ |
17 | + globalData, | ||
18 | + user | ||
16 | }), (dispatch) => { | 19 | }), (dispatch) => { |
17 | - return bindActionCreators(globalData, dispatch); | 20 | + return { |
21 | + globalData: bindActionCreators(globalData, dispatch), | ||
22 | + user: bindActionCreators(user, dispatch), | ||
23 | + }; | ||
18 | }) | 24 | }) |
19 | 25 | ||
20 | class App extends Component { | 26 | class App extends Component { |
@@ -138,7 +144,11 @@ class App extends Component { | @@ -138,7 +144,11 @@ class App extends Component { | ||
138 | // // this.mtainit(options); | 144 | // // this.mtainit(options); |
139 | // } | 145 | // } |
140 | 146 | ||
141 | - componentDidShow () {} | 147 | + async componentDidShow () { |
148 | + const a = await this.props.user.wechatLogin() | ||
149 | + | ||
150 | + console.log('-----------', this.props.user.openID) | ||
151 | + } | ||
142 | 152 | ||
143 | componentDidHide () {} | 153 | componentDidHide () {} |
144 | 154 | ||
@@ -164,11 +174,11 @@ class App extends Component { | @@ -164,11 +174,11 @@ class App extends Component { | ||
164 | getWechatThirdSession() { | 174 | getWechatThirdSession() { |
165 | let value = this.globalData.WXThird_session; | 175 | let value = this.globalData.WXThird_session; |
166 | 176 | ||
167 | - return !value ? user.getYHStorageSync('WXThird_session','app') : value; | 177 | + return !value ? userUtil.getYHStorageSync('WXThird_session','app') : value; |
168 | } | 178 | } |
169 | 179 | ||
170 | getUserInfo() { | 180 | getUserInfo() { |
171 | - let value = user.getYHStorageSync('userInfo','app'); | 181 | + let value = userUtil.getYHStorageSync('userInfo','app'); |
172 | 182 | ||
173 | if (value) { | 183 | if (value) { |
174 | this.props.userInfo(value); | 184 | this.props.userInfo(value); |
@@ -177,7 +187,7 @@ class App extends Component { | @@ -177,7 +187,7 @@ class App extends Component { | ||
177 | } | 187 | } |
178 | 188 | ||
179 | getUnionID() { | 189 | getUnionID() { |
180 | - let value = user.getYHStorageSync('unionID','app'); | 190 | + let value = userUtil.getYHStorageSync('unionID','app'); |
181 | 191 | ||
182 | if (value) { | 192 | if (value) { |
183 | this.props.setWxUnionId(value); | 193 | this.props.setWxUnionId(value); |
@@ -202,7 +212,7 @@ class App extends Component { | @@ -202,7 +212,7 @@ class App extends Component { | ||
202 | 212 | ||
203 | getSessionkey () { | 213 | getSessionkey () { |
204 | if (this.isLogin) { | 214 | if (this.isLogin) { |
205 | - var value = user.getYHStorageSync('sessionkey','app') | 215 | + var value = userUtil.getYHStorageSync('sessionkey','app') |
206 | if (value) { | 216 | if (value) { |
207 | // console.log(value) | 217 | // console.log(value) |
208 | this.globalData.sessionkey = value; | 218 | this.globalData.sessionkey = value; |
src/constants/user.js
0 → 100644
1 | +export const SET_OPENID = 'SET_OPENID'; |
@@ -15,7 +15,6 @@ const INITIAL_STATE = { | @@ -15,7 +15,6 @@ const INITIAL_STATE = { | ||
15 | } | 15 | } |
16 | 16 | ||
17 | export default function globalData (state = INITIAL_STATE, action) { | 17 | export default function globalData (state = INITIAL_STATE, action) { |
18 | - console.log(action.type) | ||
19 | switch (action.type) { | 18 | switch (action.type) { |
20 | case USERINFO: | 19 | case USERINFO: |
21 | return { | 20 | return { |
@@ -3,10 +3,12 @@ import productDetail from './productDetail' | @@ -3,10 +3,12 @@ import productDetail from './productDetail' | ||
3 | import filterMenu from './filterMenu' | 3 | import filterMenu from './filterMenu' |
4 | import filterData from './filterData' | 4 | import filterData from './filterData' |
5 | import globalData from './globalData' | 5 | import globalData from './globalData' |
6 | +import user from './user' | ||
6 | 7 | ||
7 | export default combineReducers({ | 8 | export default combineReducers({ |
8 | productDetail, | 9 | productDetail, |
9 | filterMenu, | 10 | filterMenu, |
10 | filterData, | 11 | filterData, |
11 | - globalData | 12 | + globalData, |
13 | + user | ||
12 | }) | 14 | }) |
src/reducers/user.js
0 → 100644
1 | +import { | ||
2 | + SET_OPENID | ||
3 | +} from '../constants/user' | ||
4 | + | ||
5 | +const INITIAL_STATE = { | ||
6 | + openID: '' | ||
7 | +} | ||
8 | + | ||
9 | +export default function user (state = INITIAL_STATE, action) { | ||
10 | + switch (action.type) { | ||
11 | + case SET_OPENID: | ||
12 | + return { | ||
13 | + ...state, | ||
14 | + openID: action.openID | ||
15 | + } | ||
16 | + default: | ||
17 | + return state | ||
18 | + } | ||
19 | +} |
src/utils/demo.js
0 → 100644
1 | +import store from '../store' | ||
2 | +import {wechatLogin, setOpenId} from '../actions/user'; | ||
3 | + | ||
4 | +export const demoFunc = async () => { | ||
5 | + console.log('---------', store.getState().user) | ||
6 | + const result = await store.dispatch(wechatLogin()) | ||
7 | + | ||
8 | + console.log('++++++++', result) | ||
9 | + store.dispatch(setOpenId()) | ||
10 | +} |
@@ -1911,10 +1911,6 @@ crypto-browserify@^3.11.0: | @@ -1911,10 +1911,6 @@ crypto-browserify@^3.11.0: | ||
1911 | randombytes "^2.0.0" | 1911 | randombytes "^2.0.0" |
1912 | randomfill "^1.0.3" | 1912 | randomfill "^1.0.3" |
1913 | 1913 | ||
1914 | -crypto-js@^3.1.9-1: | ||
1915 | - version "3.1.9-1" | ||
1916 | - resolved "http://npm.yohops.com/crypto-js/-/crypto-js-3.1.9-1.tgz#fda19e761fc077e01ffbfdc6e9fdfc59e8806cd8" | ||
1917 | - | ||
1918 | css-color-keywords@^1.0.0: | 1914 | css-color-keywords@^1.0.0: |
1919 | version "1.0.0" | 1915 | version "1.0.0" |
1920 | resolved "http://npm.yohops.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05" | 1916 | resolved "http://npm.yohops.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05" |
-
Please register or login to post a comment