index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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(event) {
  54. let active = event.detail,
  55. obj = this.data.tabbarList.find(v => v.name == active);
  56. wx.switchTab({
  57. url: obj.url
  58. });
  59. this.setData({
  60. active
  61. });
  62. },
  63. init() {
  64. const page = getCurrentPages().pop();
  65. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  66. this.setData({
  67. active: obj.name
  68. });
  69. //socket
  70. if (!getApp().globalData.socketEstablish) getApp().initSocket();
  71. getApp().globalData.socket = {
  72. that: this,
  73. callback: this.unReadMessageCount
  74. }
  75. this.unReadMessageCount()
  76. },
  77. /* 更新信息数量 */
  78. unReadMessageCount() {
  79. _Http.basic({
  80. "classname": "system.message.Message",
  81. "method": "unReadMessageCount",
  82. "content": {
  83. nochace: true
  84. }
  85. }, false).then(res => {
  86. if (res.msg != '成功' || res.data.fcount == 0) return;
  87. getApp().globalData.socket.that.setData({
  88. 'tabbarList[1].fcount': res.data.fcount > 99 ? '99+' : res.data.fcount
  89. })
  90. })
  91. }
  92. },
  93. })