import { wxLogOff, wxLoginCustomer } from '../../api/index' const { HYEventBus } = require('hy-event-store') const eventBus = new HYEventBus() Page({ /** * 页面的初始数据 */ data: { show: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, showLogout() { this.setData({ show: true }) }, onClose() { this.setData({ show: false }) }, onSubLgout() { let that = this wxLogOff().then(res => { wx.clearStorage() wx.login({ timeout: 5000, success(res) { if (res.code) { //发起网络请求 wxLoginCustomer({ code: res.code }).then(res => { console.log(res) if (res && res.data.token) { wx.setStorageSync('sessionKey', res.data.sessionKey) wx.setStorageSync('token', res.data.token) wx.showToast({ title: '注销成功', }) setTimeout(() => { wx.switchTab({ url: '/pages/index/index', }) }, 500) setTimeout(() => { eventBus.emit("reloadHome") }, 1000) } else { console.log('登录失败!') } }) } else {} }, fail(err) { wx.showToast({ title: '注销失败', }) wx.switchTab({ url: '/pages/index/index', }) } }) }) }, changeDeal(e) { const { label } = e.currentTarget.dataset wx.navigateTo({ url: '/pages/sets/protocol?label=' + label, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })