Commit 2b202d76 authored by 肖健's avatar 肖健

挪车订阅消息

parent 4835d151
...@@ -3,156 +3,157 @@ ...@@ -3,156 +3,157 @@
* @Description: 帮助使用 * @Description: 帮助使用
--> -->
<template> <template>
<view class="appCotent"> <view class="appCotent">
<div class="hlep"> <div class="hlep">
<u-cell-group> <u-cell-group>
<u-cell title="设置消息订阅" :isLink="true" @click="changeMessages()"></u-cell> <u-cell title="设置消息订阅" :isLink="true" @click="openMsg()"></u-cell>
</u-cell-group> </u-cell-group>
<image v-if="image" :src="image" /> <image v-if="image" :src="image"/>
<image v-else src="@/static/my/help.png" /> <image v-else src="@/static/my/help.png"/>
</div> </div>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
image: '', image: '',
//是否订阅消息 //是否订阅消息
is_authorization: uni.getStorageSync('is_authorization'), is_authorization: uni.getStorageSync('is_authorization'),
}
},
methods: {
getHelpInfo() {
let opts = {url: '/app/user/help', method: 'get'};
this.http.httpTokenRequest(opts, {}).then(res => {
if (res.data.code == 200) {
if (res.data.data.imgPath != '') {
this.image = this.http.baseUrl + res.data.data.imgPath
}
}
})
},
//获取消息订阅
openMsg() {
var that = this;
let nc_templateid = that.nc_templateid;
// 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问”
wx.getSetting({
withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
success(res) {
if (that.is_authorization) {
} else {
if (res.subscriptionsSetting[nc_templateid] == "reject") {
//用户点击了“总是保持以上,不再询问”
wx.showModal({
title: "温馨提示",
content: "检测到您没有开启订阅消息的权限,是否去设置?",
success: function (modal) {
if (modal.confirm) {
// 点击肯定
wx.openSetting({
withSubscriptions: true,
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您已拒绝订阅消息授权,无法接收通知",
icon: "error",
});
that.is_authorization = false;
}
},
});
} else {
// 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
// var templateid = that.setting.templateid.map(item => item.tempid);
let tmpid = [nc_templateid];
uni.requestSubscribeMessage({
tmplIds: tmpid,
success(res) {
if (res[tmpid[0]] == "accept") {
uni.showToast({
title: "订阅成功",
icon: "none",
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您拒绝订阅消息授权,无法接收通知",
icon: "none",
});
that.is_authorization = false;
}
},
fail: (res) => {
wx.showModal({
title: "温馨提示",
content: "检测到您没有开启订阅消息的权限,是否去设置?",
success: function (modal) {
if (modal.confirm) {
// 点击肯定
wx.openSetting({
withSubscriptions: true,
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您已拒绝订阅消息授权,无法接收通知",
icon: "error",
});
that.is_authorization = false;
}
},
});
},
});
} }
}
}, },
methods: { });
getHelpInfo(){ },
let opts = { url: '/app/user/help', method: 'get' }; //改变消息订阅
this.http.httpTokenRequest(opts, {}).then(res => { changeMessages() {
if (res.data.code == 200) { wx.openSetting({
if(res.data.data.imgPath!=''){ withSubscriptions: true,
this.image = this.http.baseUrl + res.data.data.imgPath });
} // if(!this.is_authorization){
} // wx.openSetting({
}) // withSubscriptions: true,
}, // });
//获取消息订阅 // this.is_authorization = false;
openMsg() { // uni.setStorageSync("is_authorization", false);
var that = this; // }else{
let nc_templateid = that.nc_templateid; // wx.openSetting({
// 获取用户的当前设置,判断是否点击了“总是保持以上,不在询问” // withSubscriptions: true,
wx.getSetting({ // });
withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回 // this.is_authorization = false;
success(res) { // uni.setStorageSync("is_authorization", false);
if (that.is_authorization) { // }
} else { },
if (res.subscriptionsSetting[nc_templateid] == "reject") { },
//用户点击了“总是保持以上,不再询问” onShow() {
wx.showModal({ this.getHelpInfo()
title: "温馨提示", //this.openMsg()
content: "检测到您没有开启订阅消息的权限,是否去设置?", },
success: function (modal) { }
if (modal.confirm) {
// 点击肯定
wx.openSetting({
withSubscriptions: true,
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您已拒绝订阅消息授权,无法预约领取",
icon: "error",
});
that.is_authorization = false;
}
},
});
} else {
// 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
// var templateid = that.setting.templateid.map(item => item.tempid);
let tmpid = [nc_templateid];
uni.requestSubscribeMessage({
tmplIds: tmpid,
success(res) {
if (res[tmpid[0]] == "accept") {
uni.showToast({
title: "订阅成功",
icon: "none",
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您拒绝订阅消息授权,无法预约领取",
icon: "none",
});
that.is_authorization = false;
}
},
fail: (res) => {
wx.showModal({
title: "温馨提示",
content: "检测到您没有开启订阅消息的权限,是否去设置?",
success: function (modal) {
if (modal.confirm) {
// 点击肯定
wx.openSetting({
withSubscriptions: true,
});
that.is_authorization = true;
uni.setStorageSync("is_authorization", true);
} else {
uni.showToast({
title: "您已拒绝订阅消息授权,无法预约领取",
icon: "error",
});
that.is_authorization = false;
}
},
});
},
});
}
}
},
});
},
//改变消息订阅
changeMessages(){
wx.openSetting({
withSubscriptions: true,
});
// if(!this.is_authorization){
// wx.openSetting({
// withSubscriptions: true,
// });
// this.is_authorization = false;
// uni.setStorageSync("is_authorization", false);
// }else{
// wx.openSetting({
// withSubscriptions: true,
// });
// this.is_authorization = false;
// uni.setStorageSync("is_authorization", false);
// }
},
},
onShow() {
this.getHelpInfo()
//this.openMsg()
},
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.hlep{ .hlep {
padding:0rpx 0; padding: 0 rpx 0;
height: 1092rpx; height: 1092 rpx;
image{
height: 100%; image {
width: 100%; height: 100%;
} width: 100%;
}
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment