纸通宝小程序
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.
 

155 lines
4.8 KiB

import { config, getUserInfo } from "../api/user"
import { zconfig, loginToken, getBaseInfo, getPopupInfo } from "../api/ztb"
import { pconfig } from "../api/payment"
import { mconfig } from "../api/moment"
const util = require('../../utils/util')
const event = require('../../utils/event')
const storage = require('../../utils/storage')
const app = getApp()
Page({
data: {
TabList: [{ index: 0, value: 'article', badge: 0, name: '情报' },
{ index: 1, value: 'mall', badge: 0, name: '交易' },
{ index: 2, value: 'home', badge: 0, name: '我的' }
],
pageIndex: 1,
safeBottom: app.globalData.safeBottom,
inited: false,
path: null,
landInfo: null,
visible: false
},
/************************************** 初始化流程 ********************************************/
onLoad: function (options) {
if (options.url) {
this.data.path = options.url
if (options.key && options.value) {
this.data.path += '?' + options.key + '=' + options.value
}
}
event.on('EventMessage', this, this.onEvent)
this.data.inited = true
wx.showLoading({ title: '获取中', mask: true })
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
this.setData({ fragment: fheght, safeBottom: app.globalData.safeBottom })
var authorization = app.globalData.token || storage.get('Authorization')
if (authorization) {
app.globalData.token = authorization
config.header = { 'Authorization': 'QNT ' + app.globalData.token }
getUserInfo().then(result => {
this.toIndex()
}).catch(err => {
wx.hideLoading()
})
} else {
this.toIndex()
}
},
defaultIndex: function () {
this.onResume()
if (this.data.path) {
wx.navigateTo({ url: this.data.path })
}
getPopupInfo().then(result => {
if (result.data) {
this.setData({ landInfo: result.data })
}
})
},
toIndex: function () {
if (!app.globalData.token) {
wx.hideLoading()
this.defaultIndex()
return
}
loginToken({loginToken: app.globalData.token}).then(result => {
zconfig.header = { 'Authorization': 'QNT ' + result.data.token }
pconfig.header = { 'Authorization': 'QNT ' + result.data.token }
mconfig.header = { 'Authorization': 'QNT ' + result.data.token }
getBaseInfo().then(result => {
app.globalData.userInfo = result.data
wx.hideLoading()
if(!app.globalData.userInfo.hasShowedLoginTag){
wx.navigateTo({ url: '/pages/home/tab1/index' })
}
this.defaultIndex()
}).catch(err => {
wx.hideLoading()
this.defaultIndex()
})
}).catch(err => {
wx.hideLoading()
this.defaultIndex()
})
},
onResume: function () {
var pageView = this.selectComponent('#' + this.data.TabList[this.data.pageIndex].value)
if (pageView && this.data.inited) {
pageView.onRestart()
}
},
//事件处理函数
onNavChange: function (e) {
// 处理用户的登录校验
this.setData({ pageIndex: Number(e.currentTarget.dataset.tab) })
this.onResume()
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (this.data.inited) {
this.onResume()
}
if(app.globalData.userInfo && !app.globalData.userInfo.hasShowedLoginTag){
wx.navigateTo({ url: '/pages/home/tab1/index' })
}
},
onEvent: function (message) {
if(message.what == 250){
this.setData({ pageIndex: 0 })
}
},
stopTouchMove: function (e) {
return false
},
// 弹出框的处理;
onClose: function () {
this.setData({ visible: false, landInfo: null })
},
onImageLoad: function () {
this.setData({ visible: true })
},
onImageClick: function () {
if (this.data.landInfo.redirectInfo.targetView == 'showH5') {
util.navigateTo('/pages/html/html/index?link=' + this.data.landInfo.redirectInfo.params.id + '?title=' + this.data.landInfo.title)
return
}
util.navigateTarget(this.data.landInfo.redirectInfo)
this.setData({ visible: false, landInfo: null })
},
toRule: function () {
if (this.data.landInfo.ruleRedirectInfo.targetView == 'showH5') {
util.navigateTo('/pages/html/html/index?link=' + this.data.landInfo.ruleRedirectInfo.params.id + '?title=' + this.data.landInfo.title)
return
}
util.navigateTarget(this.data.landInfo.ruleRedirectInfo)
},
onUnload: function(){
event.remove('EventMessage', this)
},
onShareAppMessage: function () {
return {
title: '纸通宝--废纸交易、最新情报、最优资讯',
path: '/pages/index/index'
}
},
// 分享至朋友圈
onShareTimeline() {
return {
title: '纸通宝--废纸交易、最新情报、最优资讯',
path: '/pages/index/index'
}
},
})