index.js 3.8 KB

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