api.js 1.7 KB

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