api.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // const tempId = 'klhtcMH_MixbhY2AqKjZ6sl7y51UkpWJ4Xj4P4Cn9U0' //四维指房宝
  2. const tempId = 'tb7kt53SnuJpwLyivqFVhW7KIqEzdMh_oc29iUzv9Bc' //四维指房
  3. export const getSubOpen = () => {
  4. let userInfo = wx.getStorageSync('userInfo');
  5. if (!userInfo.isAdmin) {
  6. return;
  7. }
  8. wx.getSetting({
  9. withSubscriptions: true,
  10. success: res => {
  11. let itemSettings = res.subscriptionsSetting
  12. console.log('itemSettings', itemSettings)
  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. }