api.js 1.7 KB

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