| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <script>
- export default {
- onLaunch: function() {
- console.log('App Launch')
- },
- onShow: function(options) {
- // console.log('app-options===>', options)
- if (Object.keys(options.query).length > 0) {
- if (options.query.invitationCode) {
- uni.setStorageSync('invitationCode', options.query.invitationCode);
- }
- }
- console.log('App Show')
- // #ifdef MP-WEIXIN
- //小程序更新
- if (uni.getUpdateManager) {
- const updateManager = uni.getUpdateManager();
- updateManager.onCheckForUpdate(function(res) {
- // 请求完新版本信息的回调
- // console.log(res.hasUpdate);
- });
- updateManager.onUpdateReady(function(res) {
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate();
- }
- }
- });
- });
- updateManager.onUpdateFailed(function(res) {
- // 新的版本下载失败
- uni.showModal({
- title: '已经有新版本了哟~',
- content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
- showCancel: false
- });
- });
- }
- // #endif
- // #ifdef APP-PLUS
- this.getPush();
- // #endif
- },
- onHide: function() {
- console.log('App Hide')
- },
- methods: {
- getPush() {
- // #ifdef APP-PLUS
- plus.push.setAutoNotification(true); //设置通知栏显示通知必须设置
- //从系统消息中心点击消息启动应用事件
- let that = this;
- let platform = uni.getSystemInfoSync().platform;
- plus.push.addEventListener(
- "click",
- (data) => {
- if (platform == "ios" && data.type == "click") {
- //苹果离线点击事件
- let obj = data.payload.payload.message_body;
- let item = data.payload.payload;
- that.jump(item, obj);
- }
- if (platform == "ios") {
- //苹果在线点击事件
- let item = JSON.parse(data.payload);
- let obj = item.message_body;
- that.jump(item, obj);
- }
- if (platform == "android") {
- //安卓在线点击事件
- let item = data.payload;
- let obj = item.message_body;
- that.jump(item, obj);
- }
- },
- false
- );
- //应用从推送服务器接收到推送消息事件
- plus.push.addEventListener(
- "receive",
- (res) => {
- if (platform == "android") {
- //安卓在线推送
- // item = res.payload
- const options = {
- cover: false,
- title: res.title,
- };
- plus.push.createMessage(res.content, res.payload, options);
- } else {
- //苹果在线推送事件
- if (res.aps == null || res.type == "receive") {
- const options = {
- cover: false,
- title: res.title,
- };
- plus.push.createMessage(
- res.content,
- JSON.stringify(res.payload),
- options
- );
- }
- }
- },
- false
- );
- // #endif
- },
- //跳转
- jump(item, obj) {
- // const then = this;
- console.log("item===>", item)
- // console.log("obj===>", obj)
- let messageName = {
- 'PAY_MESSAGE': {
- name: "支付消息",
- type: 1
- },
- 'LOGISTICS_MESSAGE': {
- name: "物流消息",
- type: 2
- },
- 'RIGHTS_MESSAGE': {
- name: "售后消息",
- type: 3
- },
- };
- let item1 = messageName[item.type] || null;
- console.log("item1===>", item1)
- if(!item1) return
- // 跳转到消息列表页面
- uni.navigateTo({
- url: `/pages/user/eventDetails?type=${item1.type || ''}&name=${item1.name || ''}`,
- });
- },
- }
- }
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import "@/static/font/iconfont.css";
- @import "@/static/style/basics.scss";
- @import "@/uni_modules/uv-ui-tools/index.scss";
- @import "@/static/style/common.scss";
- view{
- box-sizing: border-box;
- }
- .u-btn-two {
- width: 100%;
- height: 70rpx;
- background: #fa6138;
- border-radius: 45rpx;
- /* border: 1px solid #0B844A; */
- font-size: 30rpx;
- color: #ffffff;
- text-align: center;
- line-height: 70rpx;
- margin: 0;
- }
- .u-plr30 {
- padding: 0 30rpx;
- }
- .u-FFF {
- color: #fff;
- }
-
- </style>
|