Authored by 陈峰

commit

No preview for this file type
... ... @@ -14,6 +14,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@tarojs/async-await": "^1.0.7",
"@tarojs/components": "^1.0.0-beta.11",
"@tarojs/redux": "^1.0.7",
"@tarojs/router": "^1.0.0-beta.11",
... ...
import {
SET_OPENID
} from '../constants/user'
export const setOpenId = function(openID) {
return {
type: SET_OPENID,
openID
}
}
export const wechatIsBind = function() {
return dispatch => {
return new Promise((resolve, reject) => {
wx.login({
success: (res) => {
dispatch(setOpenId('openId'))
return resolve({name: 'openId'});
}
});
})
}
}
export const wechatLogin = function() {
return dispatch => {
return new Promise((resolve, reject) => {
wx.login({
success: (res) => {
dispatch(setOpenId('openId'))
return resolve({name: 'openId'});
}
});
})
}
}
\ No newline at end of file
... ...
import Taro, { Component } from '@tarojs/taro'
import { Provider, connect } from '@tarojs/redux'
import { bindActionCreators } from 'redux';
import Index from './pages/index'
import configStore from './store'
import user from './utils/user';
import createStore from './store'
import userUtil from './utils/user';
import {common as commonModel} from './models';
import './app.scss'
const store = configStore()
import globalData from './actions/globalData';
import { bindActionCreators } from 'redux';
import * as user from './actions/user';
@connect(({ globalData }) => ({
globalData
import './app.scss'
const store = createStore();
@connect(({ globalData, user }) => ({
globalData,
user
}), (dispatch) => {
return bindActionCreators(globalData, dispatch);
return {
globalData: bindActionCreators(globalData, dispatch),
user: bindActionCreators(user, dispatch),
};
})
class App extends Component {
... ... @@ -138,7 +144,11 @@ class App extends Component {
// // this.mtainit(options);
// }
componentDidShow () {}
async componentDidShow () {
const a = await this.props.user.wechatLogin()
console.log('-----------', this.props.user.openID)
}
componentDidHide () {}
... ... @@ -164,11 +174,11 @@ class App extends Component {
getWechatThirdSession() {
let value = this.globalData.WXThird_session;
return !value ? user.getYHStorageSync('WXThird_session','app') : value;
return !value ? userUtil.getYHStorageSync('WXThird_session','app') : value;
}
getUserInfo() {
let value = user.getYHStorageSync('userInfo','app');
let value = userUtil.getYHStorageSync('userInfo','app');
if (value) {
this.props.userInfo(value);
... ... @@ -177,7 +187,7 @@ class App extends Component {
}
getUnionID() {
let value = user.getYHStorageSync('unionID','app');
let value = userUtil.getYHStorageSync('unionID','app');
if (value) {
this.props.setWxUnionId(value);
... ... @@ -202,7 +212,7 @@ class App extends Component {
getSessionkey () {
if (this.isLogin) {
var value = user.getYHStorageSync('sessionkey','app')
var value = userUtil.getYHStorageSync('sessionkey','app')
if (value) {
// console.log(value)
this.globalData.sessionkey = value;
... ...
export const SET_OPENID = 'SET_OPENID';
... ...
... ... @@ -15,7 +15,6 @@ const INITIAL_STATE = {
}
export default function globalData (state = INITIAL_STATE, action) {
console.log(action.type)
switch (action.type) {
case USERINFO:
return {
... ...
... ... @@ -3,10 +3,12 @@ import productDetail from './productDetail'
import filterMenu from './filterMenu'
import filterData from './filterData'
import globalData from './globalData'
import user from './user'
export default combineReducers({
productDetail,
filterMenu,
filterData,
globalData
globalData,
user
})
... ...
import {
SET_OPENID
} from '../constants/user'
const INITIAL_STATE = {
openID: ''
}
export default function user (state = INITIAL_STATE, action) {
switch (action.type) {
case SET_OPENID:
return {
...state,
openID: action.openID
}
default:
return state
}
}
\ No newline at end of file
... ...
import store from '../store'
import {wechatLogin, setOpenId} from '../actions/user';
export const demoFunc = async () => {
console.log('---------', store.getState().user)
const result = await store.dispatch(wechatLogin())
console.log('++++++++', result)
store.dispatch(setOpenId())
}
\ No newline at end of file
... ...
... ... @@ -1911,10 +1911,6 @@ crypto-browserify@^3.11.0:
randombytes "^2.0.0"
randomfill "^1.0.3"
crypto-js@^3.1.9-1:
version "3.1.9-1"
resolved "http://npm.yohops.com/crypto-js/-/crypto-js-3.1.9-1.tgz#fda19e761fc077e01ffbfdc6e9fdfc59e8806cd8"
css-color-keywords@^1.0.0:
version "1.0.0"
resolved "http://npm.yohops.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
... ...