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.

184 lines
6.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<script>
export default {
globalData: {
register_layer_status: false, //注册浮层是否显示 false--不显示 true--显示
order: {
// 我的地址ID
myAddressId: '',
// 是否手动选择过优惠券
isHasChooseCoupon: 0,
// 我的优惠券ID
myCouponId: ''
},
// 场景值,现微信小程序有该参数
scene: ''
},
onLaunch: function() {
console.log('App Launch')
let user_agent = this.cn.userAgent()
console.log('当前代理器:' + user_agent)
//(小程序环境)更新小程序版本
// #ifdef MP
if (uni.canIUse('getUpdateManager')) { //判断方法是否在当前版本可用
const updateManager = uni.getUpdateManager() //本API返回全局唯一的版本更新管理器对象用于管理小程序更新
updateManager.onCheckForUpdate((res) => { //当向小程序后台请求完新版本信息,会进行回调
// console.log('onCheckForUpdate====', res)
// 请求完新版本信息的回调
if (res.hasUpdate) { //是否有新的版本
console.log('res.hasUpdate====')
updateManager.onUpdateReady(() => {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: (res) => {
console.log('success====', res)
// res: {errMsg: "showModal: ok", cancel: false, confirm: true}
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager
.applyUpdate() //当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
}
}
})
})
updateManager.onUpdateFailed(() => { //当新版本下载失败,会进行回调
// 新的版本下载失败
uni.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
})
})
}
})
} else {
uni.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
// #endif
// #ifdef APP-PLUS
// 监听返回键 安卓机型TABBAR页面点击2次返回退出应用
this.cn.listenBackButtonQuitApp([
'pages/mall/index',
'pages/mall/category',
'pages/mall/cart',
'pages/mine/index'
])
// 监听接收透传消息事件 ios需要开发者手动在receive透传回调中创建通知安卓UniPush推送服务对透传消息的数据特定格式时做了特殊处理监听不到该事件
plus.push.addEventListener('receive', (msg) => {
console.log('receive', msg)
if (this.cn.platform == 'ios') { //如果是IOS
//【APP离线】收到消息但没有提醒发生在一次收到多个离线消息时只有一个有提醒但其他的没有提醒
//【APP在线】收到消息不会触发系统消息,需要创建本地消息但不能重复创建。必须加msg.type验证去除死循环
if (msg.aps) { // Apple APNS message
//APNS下发的消息应用在前台
} else if ('LocalMSG' == msg.payload) { // 特殊payload标识本地创建的消息
//本地创建的消息,通常不需要处理
//注意不要在这种情况下再此调用plus.push.createMessage从而引起循环创建本地消息
} else {
// 接收到在线透传消息
// 创建本地消息并添加到系统消息中心。发送的本地消息也会被receive方法接收到但没有type属性且aps是null
plus.push.createMessage(msg.content, msg.payload, {
title: msg.title
})
}
}
}, false)
// 监听系统通知栏消息点击事件
plus.push.addEventListener('click', function(msg) {
console.log('click', msg)
// 处理点击消息的业务逻辑代码
let payloadArr = msg.payload.split("_")
// 秒杀提醒 -- 跳转对应秒杀详情
if (payloadArr[0] == 'spikenotice') { //秒杀
setTimeout(res => {
uni.navigateTo({
url: 'pages/mall/spike/detail?id=' + payloadArr[1]
});
}, 500)
}
}, false)
// #endif
// #ifdef H5
if (user_agent == 'weixin') {
this.wx.setConfig() //注册微信JSSDK所有方法
}
// #endif
},
onShow: function(e) {
console.log('App Show')
// #ifdef APP-PLUS
setTimeout(function() {
// 当其它三方App通过scheme启动App时可以通过plus.runtime.arguments获取完整的urlscheme字符串
let args = plus.runtime.arguments
// args = 'https://tp-universal.jucheng01.net/h5toapp?id=8'
console.log('--监听第三方渠道打开APP事件 接收到的参数--', args)
if (args) {
let param = new Object()
try {
// 处理JSON对象aj
param = JSON.parse(args)
// 若传入的参数不是JSON格式字符需处理异常情况一般为通过URL Scheme调用
} catch (e) {
// 以//分割字符串
let paramStrArr = args.split("//")
// 没有传参数,不进行下面的操作
if (paramStrArr.length <= 1) {
return false
}
// 获取参数
let paramStr = paramStrArr[1]
// 以&分割多个参数
let jsonStr = paramStr.split("&") //多个参数组
// 组合参数数组
jsonStr.forEach((val, index) => {
let arr = val.split("=")
param[arr[0]] = arr[1]
})
//根据不同的类型不同的参数进行不同的操作
if (param.hasOwnProperty('type') && param.type == 'abc') {
console.log('--matched--')
}
}
}
}, 1000);
// #endif
},
onHide: function() {
// console.log('App Hide')
}
}
</script>
<style>
@import url('components/colorui/main.css');
@import url('components/colorui/icon.css');
@import url('components/hzjc/style/common.css');
/* 汇总了自定义样式,自定义边框,自定义icon */
@import url('components/hzjc/style/iconfont/iconfont.css');
/*每个页面公共css */
</style>