app.js
5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import Taro, { Component } from '@tarojs/taro'
import { Provider, connect } from '@tarojs/redux'
import { bindActionCreators } from 'redux';
import Index from './pages/index'
import createStore from './store'
import userUtil from './utils/user';
import {common as commonModel} from './models';
import globalData from './actions/globalData';
import * as user from './actions/user';
import './app.scss'
const store = createStore();
@connect(({ globalData, user }) => ({
globalData,
user
}), (dispatch) => {
return {
globalData: bindActionCreators(globalData, dispatch),
user: bindActionCreators(user, dispatch),
};
})
class App extends Component {
config = {
pages: [
'pages/index/index',
'pages/search/index',
'pages/searchList/index',
'pages/filter/index',
// 'pages/brand/index',
'pages/productDetail/index',
'pages/classify/index',
'pages/message/index',
'pages/userCenter/index',
'pages/login/index'
],
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/index',
text: '消息',
iconPath: './static/images/tab-icon-03.png',
selectedIconPath: './static/images/tab-icon-03-focus.png'
}, {
pagePath: 'pages/index/index',
text: '我的',
iconPath: './static/images/tab-icon-04.png',
selectedIconPath: './static/images/tab-icon-04-focus.png'
}]
}
};
// componentDidMount () {
// let {setSystemInfo} = this.props;
// console.log(this.props)
// // 获取系统信息
// let systemInfo = Taro.getSystemInfoSync();
// console.log('系统信息')
// console.log(systemInfo)
// systemInfo.screenHeight = !systemInfo.screenHeight ? systemInfo.windowHeight : systemInfo.screenHeight;
// systemInfo.screenWidth = !systemInfo.screenWidth ? systemInfo.windowWidth : systemInfo.screenWidth;
// setSystemInfo(systemInfo);
// // this.checkUDID();
// // that.getSimplePise()
// // this.checkNetworkType()
// // if (options && options.scene){
// // this.globalData.ch = options.scene
// // }
// // if (options && options.query && options.query.union_type){
// // this.updateUnionType(options.query.union_type)
// // }
// Taro.checkSession({
// success() {
// //登录态未过期
// this.getWechatThirdSession();
// this.getUserInfo();
// this.getUnionID();
// this.getUnionTypeWithUid(this.getUid());
// },
// fail() {
// //登录态过期
// Taro.setStorage({
// key: 'WXThird_session',
// data: ''
// });
// Taro.setStorage({
// key: 'userInfo',
// data: {}
// });
// Taro.setStorage({
// key: 'unionID',
// data: ''
// });
// Taro.setStorage({
// key: 'user_union_type',
// data: ''
// });
// }
// })
// // this.getSessionkey();
// // let timestamp = new Date().getTime() + ''
// // this.globalData.sid = md5(timestamp);
// // if (options){
// // let channel = options.query.channel;
// // let channelType = options.query.type;
// // let params = { 'CHANNEL': channel, 'TYPE': channelType };
// // logEvent(YB_LAUNCH_APP, params, this);
// // }
// // setTimeout(function () {
// // wechatLoginAction(function (response) {
// // that.getShareInfo();
// // });
// // }, 1000);
// // this.mtainit(options);
// }
async componentDidShow () {
const a = await this.props.user.wechatLogin()
console.log('-----------', this.props.user.openID)
}
componentDidHide () {}
componentCatchError () {}
isLogin() {
let {globalData} = this.props;
return globalData.userInfo.uid > 0 ? true : false;
}
getUid() {
let uid = this.props.globalData.userInfo.uid;
if (!uid) {
let userInfo = this.getUserInfo();
uid = userInfo && userInfo.uid;
}
return uid;
}
getWechatThirdSession() {
let value = this.globalData.WXThird_session;
return !value ? userUtil.getYHStorageSync('WXThird_session','app') : value;
}
getUserInfo() {
let value = userUtil.getYHStorageSync('userInfo','app');
if (value) {
this.props.userInfo(value);
}
return value;
}
getUnionID() {
let value = userUtil.getYHStorageSync('unionID','app');
if (value) {
this.props.setWxUnionId(value);
}
}
/*
获取用户相关union_type
*/
getUnionTypeWithUid(uid) {
commonModel.queryUnionTypeByUid({uid: uid}).then(ret => {
if (ret && ret.code == 200) {
this.props.setUnionInfo({
userUnionType: ret.data.unionType,
userUnionTypeImageUrl: ret.data.imageUrl,
shareId: ret.data.shareId,
userNounionTypeImageUrl: ret.data.applyImageUrl
});
}
})
}
getSessionkey () {
if (this.isLogin) {
var value = userUtil.getYHStorageSync('sessionkey','app')
if (value) {
// console.log(value)
this.globalData.sessionkey = value;
}
}
return undefined;
}
render () {
return (
<Provider store={store}>
<Index />
</Provider>
)
}
}
Taro.render(<App />, document.getElementById('app'));