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

183 lines
6.0 KiB

const app = getApp()
const event = require('../../utils/event')
const util = require('../../utils/util')
const request = require('../../utils/request') //导入模块
const storage = require('../../utils/storage')
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) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
// console.log('updateManager>>>' + res.hasUpdate)
})
updateManager.onUpdateReady(function () {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
})
if(options.url){
this.data.path = options.url
if(options.key && options.value){
this.data.path += '?' + options.key + '=' + options.value
}
}
},
onReady: function () {
wx.showLoading({ title: '获取中', mask: true })
wx.getSystemInfo({
success: e => {
app.globalData.isIPhoneX = this.checkIPhoneX(e)
app.globalData.isIos = this.checkIos(e)
app.globalData.dev = e.platform == 'devtools'
let custom = wx.getMenuButtonBoundingClientRect()
app.globalData.Custom = custom
// 顶部操作栏高度
app.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight + (app.globalData.isIos ? 4 : 0)
let windowHeight = e.windowHeight * (750 / e.windowWidth)
let safeBottom = e.windowHeight - e.safeArea.bottom
if(safeBottom > e.windowHeight){
safeBottom = 34
}
app.globalData.safeBottom = safeBottom * (750 / e.windowWidth)
// 状态栏高度
app.globalData.StatusBar = e.statusBarHeight * (750 / e.windowWidth)
let statusBarHeight = app.globalData.CustomBar * (750 / e.windowWidth)
app.globalData.statusBarHeight = statusBarHeight
// fragmentHeight:指的是整个页面statusBarHeight以下的高度
app.globalData.fragmentHeight = windowHeight - statusBarHeight
app.globalData.safeFragmentHeight = windowHeight - statusBarHeight - app.globalData.safeBottom
app.globalData.windowWidth = e.windowWidth
this.data.inited = true
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
event.emit('InitMessage', { what: 8, desc: 'Logined' })
this.setData({fragment: fheght, safeBottom: app.globalData.safeBottom })
var authorization = app.globalData.token || storage.get('Authorization')
if(authorization){
app.globalData.token = authorization
this.fetchUserInfo()
} else {
wx.hideLoading()
this.toIndex()
}
}
})
},
checkIos: function (e) {
if ('ios' === e.platform) {
return true
}
if (e.system.startsWith('iOS')) {
return true
}
return false
},
checkIPhoneX: function (e) {
var t = e.model
return (/iPhone 11/.test(t) || /iPhone X/.test(t) || /iPhone 12/.test(t)) && this.checkIos(e)
},
fetchUserInfo:function(){
request.get('/recycle-service/user/get/base-info').then(result => {
app.globalData.userInfo = result.data
var accessToken = wx.getStorageSync('accessToken')
if(accessToken){
app.globalData.userToken = accessToken
request.get('/saas-trade/receive/v150/get/OrderExists').then(result => {
wx.hideLoading()
if (Number(result.data) != 1 || !app.release) {
this.toIndex()
} else {
wx.reLaunch({ url: '/pages/paper/index' })
}
}).catch(err => {
//异常回调
wx.hideLoading()
this.toIndex()
})
} else {
wx.hideLoading()
this.toIndex()
}
}).catch(err => {
wx.hideLoading()
})
},
toIndex: function(){
this.onResume()
if(this.data.path){
wx.navigateTo({ url: this.data.path })
}
// 进行弹窗的dialog显示处理;/popup/get/popup 获取popup
request.get('/recycle-service/popup/get/popup').then(result => {
if(result.data){
this.setData({ landInfo: result.data })
}
})
},
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()
}
},
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)
}
})