app.js 3.21 KB
import Taro, { Component } from '@tarojs/taro'
import '@tarojs/async-await'
import { Provider, connect } from '@tarojs/redux'
import { bindActionCreators } from 'redux';
import Index from './pages/index'
import createStore from './store'
import * as globalData from './actions/globalData';
import udid from './utils/udid';
import './app.scss'

const store = createStore();

@connect(({ globalData, user }) => ({
		globalData
}), (dispatch) => {
    return bindActionCreators({
		...globalData
	}, dispatch)
})

class App extends Component {
	config = {
		pages: [
			'pages/index/index',
			'pages/search/index',
			'pages/searchList/index',
			'pages/filter/index',
			'pages/productDetail/index',
			'pages/sell/index',
			'pages/classify/index',
			'pages/message/message/message',
      'pages/message/messageDetail/messageDetail',
			'pages/userCenter/index',
			'pages/login/index',
			'pages/orderList/index',
			'pages/nativeTest/nativeTest',
			'pages/userCenter/collection/collection',
		],
		window: {
			backgroundTextStyle: 'light',
			navigationBarBackgroundColor: '#fff',
			// navigationBarTitleText: 'WeChat',
			navigationBarTextStyle: 'black'
		},
		tabBar: {
			color: '#bbb',
			selectedColor: '#08304B',
			backgroundColor: '#fff',
			borderStyle: '#eee',
			list: [{
				pagePath: 'pages/index/index',
				text: '首页',
				iconPath: './static/images/tab-icon-01.png',
				selectedIconPath: './static/images/tab-icon-01-focus.png'
			},{
				pagePath: 'pages/classify/index',
				text: '分类',
				iconPath: './static/images/tab-icon-02.png',
				selectedIconPath: './static/images/tab-icon-02-focus.png'
			}, {
          pagePath: 'pages/message/message/message',
				text: '消息',
				iconPath: './static/images/tab-icon-03.png',
				selectedIconPath: './static/images/tab-icon-03-focus.png'
			}, {
				pagePath: 'pages/userCenter/index',
				text: '我的',
				iconPath: './static/images/tab-icon-04.png',
				selectedIconPath: './static/images/tab-icon-04-focus.png'
			}]
		}
	};

	componentWillMount () {
		let {setSystemInfo, wechatLogin, setSessionkey} = this.props;

		// 获取系统信息
		let systemInfo = Taro.getSystemInfoSync();

		systemInfo.screenHeight = !systemInfo.screenHeight ? systemInfo.windowHeight : systemInfo.screenHeight;
		systemInfo.screenWidth = !systemInfo.screenWidth ? systemInfo.windowWidth : systemInfo.screenWidth;

		setSystemInfo(systemInfo);
		this.props.setUdid(udid.get());
		setSessionkey();

		Taro.checkSession({
			success: () =>{
				//登录态未过期
				console.log('登录态未过期');
				this.props.setWxThirdSession();
				this.props.setUserInfo();
				this.props.setWxUnionId();
				// this.props.getUnionTypeWithUid(this.props.globalData.userInfo.uid); // 有赚
			},
			fail: () => {
				console.log('登录已经过期')
				//登录态过期
				Taro.setStorage({key: 'WXThird_session', data: ''});
				Taro.setStorage({key: 'userInfo', data: ''});
				Taro.setStorage({key: 'unionID', data: ''});
				Taro.setStorage({key: 'user_union_type', data: ''});
				wechatLogin();
			}
		});
	}

	componentDidHide () {}

	componentCatchError () {}

	render () {
		return (
		<Provider store={store}>
			<Index />
		</Provider>
		)
	}
}

Taro.render(<App />, document.getElementById('app'));