index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. lifetimes: {
  4. ready: function () {
  5. if (this.data.count == 1) return;
  6. if (wx.getStorageSync('userauth') != 0) {
  7. //判断页面 以免一直触发
  8. const pages = getCurrentPages(),
  9. prevPage = pages[pages.length - 1];
  10. if (prevPage.route == 'pages/login/selectSite' || prevPage.route.includes('pages/tabbar/')) {
  11. const auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['营销物料']);
  12. if (auth.length == 1) this.setData({
  13. Permission: ['首页', '信息', '营销物料', '我的']
  14. })
  15. }
  16. }
  17. },
  18. },
  19. data: {
  20. active: 'home',
  21. Permission: ['首页', '信息', '我的'], //可看模块
  22. tabbarList: [{
  23. icon: 'icon-a-biaoqianlanshouyexuanzhong',
  24. acicon: 'icon-a-biaoqianlanshouyexuanzhong',
  25. text: '首页',
  26. url: '/pages/tabbar/home/index',
  27. name: 'home'
  28. },
  29. {
  30. icon: 'icon-a-biaoqianlanxiaoxi',
  31. acicon: 'icon-a-biaoqianlanxiaoxixuanzhong',
  32. text: '信息',
  33. url: '/pages/tabbar/message/index',
  34. name: 'message'
  35. },
  36. {
  37. icon: 'icon-a-biaoqianlanzhiku',
  38. acicon: 'icon-xiaochengxu_yingxiaowuliaoxuanzhong',
  39. text: '营销物料',
  40. url: '/pages/tabbar/smartStore/index',
  41. name: 'smartStore'
  42. },
  43. {
  44. icon: 'icon-a-biaoqianlanwode',
  45. acicon: 'icon-a-biaoqianlanwodexuanzhong',
  46. text: '我的',
  47. url: '/pages/tabbar/mine/index',
  48. name: 'mine'
  49. }
  50. ],
  51. },
  52. methods: {
  53. onChange({
  54. detail
  55. }) {
  56. if (detail == "smartStore") {
  57. let item = wx.getStorageSync('gridList').find(v => v.label == '营销物料');
  58. if (!item) return wx.showToast({
  59. title: `暂无进入‘营销物料’应用权限`,
  60. icon: "none",
  61. mask: true
  62. })
  63. getApp().globalData.evidence(item)
  64. } else {
  65. const obj = this.data.tabbarList.find(v => v.name == detail);
  66. wx.switchTab({
  67. url: obj.url
  68. });
  69. this.setData({
  70. active: detail
  71. });
  72. }
  73. },
  74. init() {
  75. const page = getCurrentPages().pop();
  76. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  77. this.setData({
  78. active: obj.name
  79. });
  80. //socket
  81. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  82. getApp().globalData.socket = {
  83. that: this,
  84. callback: this.unReadMessageCount
  85. }
  86. this.unReadMessageCount()
  87. },
  88. /* 更新信息数量 */
  89. unReadMessageCount() {
  90. _Http.basic({
  91. "classname": "system.message.Message",
  92. "method": "unReadMessageCount",
  93. "content": {
  94. nochace: true
  95. }
  96. }, false).then(res => {
  97. if (res.msg != '成功') return;
  98. let fcount = res.data.fcount > 99 ? '99+' : res.data.fcount;
  99. if (res.data.fcount == 0) fcount = "";
  100. getApp().globalData.socket.that.setData({
  101. 'tabbarList[1].fcount': fcount
  102. })
  103. })
  104. }
  105. },
  106. })