You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
const app = getApp()
|
|
const util = require('../../utils/util');
|
|
const event = require('../../utils/event.js')
|
|
|
|
Page({
|
|
data: {
|
|
TabList: [
|
|
{ index: 0, value: 'message', icon: 'messagefill', name: '消息' },
|
|
{ index: 1, value: 'task', icon: 'deliver_fill', badge: 0, name: '任务' },
|
|
{ index: 2, value: 'home', icon: 'myfill', badge: 0, name: '我的' }
|
|
],
|
|
pageIndex: 1
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.checkLogin()
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
//事件处理函数
|
|
onNavChange(e) {
|
|
// 处理用户的登录校验
|
|
this.setData({ pageIndex: Number(e.currentTarget.dataset.tab) })
|
|
var pageView = this.selectComponent('#' + this.data.TabList[this.data.pageIndex].value);
|
|
pageView.onRestart()
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
var pageView = this.selectComponent('#' + this.data.TabList[this.data.pageIndex].value);
|
|
if (pageView) {
|
|
pageView.onRestart()
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
event.remove('EventMessage', this)
|
|
},
|
|
|
|
// 进行登录,同时获取到openId,为下一步的微信登录做准备,
|
|
checkLogin: function () {
|
|
wx.login({
|
|
success: res => {
|
|
wx.request({
|
|
url: app.httpUrl + '/user-centre/wx/bxe/session',
|
|
data: { code: res.code },
|
|
method: 'POST',
|
|
success: function (result) {
|
|
if (result.data.code != 0) {
|
|
event.emit('EventMessage', { what: 1, desc: 'Login' })
|
|
return
|
|
}
|
|
app.globalData.openId = result.data.data.openid
|
|
// /commonLogin/login通用登录
|
|
wx.request({
|
|
url: app.httpUrl + '/user-centre/commonLogin/login',
|
|
data: { openid: app.globalData.openId },
|
|
method: 'POST',
|
|
success: function (result) {
|
|
if (result.data.code == 0 && result.data.data.token) {
|
|
app.globalData.token = result.data.data.token
|
|
}
|
|
},
|
|
complete: function () {
|
|
event.emit('EventMessage', { what: 1, desc: 'Login' })
|
|
}
|
|
})
|
|
},
|
|
fail: function () {
|
|
event.emit('EventMessage', { what: 1, desc: 'Login' })
|
|
}
|
|
})
|
|
},
|
|
fail: function () {
|
|
event.emit('EventMessage', { what: 1, desc: 'Login' })
|
|
}
|
|
})
|
|
}
|
|
|
|
})
|