|
@@ -2,6 +2,7 @@ const pages = require('../../mixin/pages')
|
|
|
const { getProductCategoryList } = require('../../api/common')
|
|
|
const { getLunboList } = require('./api/index')
|
|
|
const app = getApp()
|
|
|
+const tmplIds = '1kIBK-L1ksxYCxY7Pmezhp4FSS-BOqiIAl6K7PAGvDE'
|
|
|
let leftHeight = 0
|
|
|
let rightHeight = 0
|
|
|
let query = wx.createSelectorQuery()
|
|
@@ -229,8 +230,7 @@ Page({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- handleNav(e) {
|
|
|
- const { item } = e.currentTarget.dataset
|
|
|
+ handleNav(item) {
|
|
|
if (Object.prototype.toString.call(item) === '[object Object]' && item.path) {
|
|
|
const path = item.path
|
|
|
|
|
@@ -251,5 +251,53 @@ Page({
|
|
|
wx.navigateTo({
|
|
|
url: `/pages/${page}/${page}`
|
|
|
})
|
|
|
+ },
|
|
|
+ async handleSubscribeMessage(e) {
|
|
|
+ const { item } = e.currentTarget.dataset
|
|
|
+ const that = this
|
|
|
+
|
|
|
+ try {
|
|
|
+ const { errMsg, subscriptionsSetting } = await wx.getSetting({ withSubscriptions: true })
|
|
|
+ if (errMsg === 'getSetting:ok') {
|
|
|
+ // 用户打开了订阅消息总开关
|
|
|
+ if (subscriptionsSetting.mainSwitch) {
|
|
|
+ // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
|
|
|
+ if (subscriptionsSetting.itemSettings != null) {
|
|
|
+ const moIdState = subscriptionsSetting.itemSettings[tmplIds]
|
|
|
+ if (moIdState === 'accept') {
|
|
|
+ // 接受了消息推送
|
|
|
+ } else if (moIdState === 'reject') {
|
|
|
+ // 拒绝消息推送
|
|
|
+ } else if (moIdState === 'ban') {
|
|
|
+ // 已被后台封禁
|
|
|
+ }
|
|
|
+
|
|
|
+ that.handleNav(item)
|
|
|
+ } else {
|
|
|
+ // 当用户没有点击 ’总是保持以上选择,不再询问‘ 按钮。那每次执到这都会拉起授权弹窗
|
|
|
+ wx.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请授权开通服务通知',
|
|
|
+ showCancel: true,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm) {
|
|
|
+ wx.requestSubscribeMessage({
|
|
|
+ tmplIds: [tmplIds],
|
|
|
+ success(res) {
|
|
|
+ that.handleNav(item)
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ that.handleNav(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 订阅消息未开启
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
}
|
|
|
})
|