api.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const tempId = 'klhtcMH_MixbhY2AqKjZ6sl7y51UkpWJ4Xj4P4Cn9U0'
  2. export const getSubOpen = () => {
  3. let userInfo = wx.getStorageSync('userInfo');
  4. if (!userInfo.isAdmin) {
  5. return;
  6. }
  7. wx.getSetting({
  8. withSubscriptions: true,
  9. success: res => {
  10. let itemSettings = res.subscriptionsSetting
  11. if (!itemSettings || !itemSettings[tempId] || itemSettings[tempId] === 'reject') {
  12. wx.showModal({
  13. title: '温馨提示',
  14. content: '您是工作人员,请允许消息推送',
  15. showCancel: true, //是否显示取消按钮
  16. cancelText: "取消", //默认是“取消”
  17. confirmText: "确定", //默认是“确定”
  18. success: (res) => {
  19. authMsg()
  20. }
  21. })
  22. }
  23. }
  24. })
  25. }
  26. export const authMsg = () => {
  27. wx.requestSubscribeMessage({
  28. tmplIds: [tempId],
  29. success(res) {
  30. console.log('成功订阅消息', res)
  31. if (res[tempId] === 'reject') {
  32. rejectAuth()
  33. }
  34. },
  35. fail: (e) => {
  36. console.error(e)
  37. if (e.errCode === 20004) {
  38. rejectAuth()
  39. }
  40. }
  41. })
  42. }
  43. export const rejectAuth = () => {
  44. wx.showModal({
  45. title: '温馨提示',
  46. content: '您关闭了授权,将跳转到设置页面,请打开VR带看提醒开关',
  47. showCancel: true, //是否显示取消按钮
  48. cancelText: "取消", //默认是“取消”
  49. confirmText: "确定", //默认是“确定”
  50. success: (res) => {
  51. wx.openSetting({
  52. withSubscriptions: true,
  53. success: (res) => {
  54. if (!res.subscriptionsSetting.mainSwitch) {
  55. this.getSubOpen()
  56. }
  57. }
  58. })
  59. }
  60. })
  61. }