index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. text: '首页',
  41. url: '/pages/tabbar/home/index',
  42. name: 'home'
  43. },
  44. {
  45. icon: 'icon-a-biaoqianlanxiaoxi',
  46. text: '信息',
  47. url: '/pages/tabbar/message/index',
  48. name: 'message'
  49. },
  50. {
  51. icon: 'icon-a-biaoqianlanzhiku',
  52. text: '营销物料',
  53. url: '/pages/tabbar/smartStore/index',
  54. name: 'smartStore'
  55. },
  56. {
  57. icon: 'icon-a-biaoqianlanwode',
  58. text: '我的',
  59. url: '/pages/tabbar/mine/index',
  60. name: 'mine'
  61. }
  62. ],
  63. },
  64. methods: {
  65. /* tabbar */
  66. onChange(event) {
  67. let active = event.detail,
  68. obj = this.data.tabbarList.find(v => v.name == active);
  69. wx.switchTab({
  70. url: obj.url
  71. });
  72. this.setData({
  73. active
  74. });
  75. },
  76. init() {
  77. const page = getCurrentPages().pop();
  78. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  79. this.setData({
  80. active: obj.name
  81. });
  82. this.unReadMessageCount();
  83. },
  84. /* 更新信息数量 */
  85. unReadMessageCount() {
  86. _Http.basic({
  87. "classname": "system.message.Message",
  88. "method": "unReadMessageCount",
  89. "content": {
  90. nochace: true
  91. }
  92. }, false).then(res => {
  93. if (res.msg != '成功') return;
  94. if (res.data.fcount > 99) res.data.fcount = '99+';
  95. this.setData({
  96. 'tabbarList[1].fcount': res.data.fcount
  97. })
  98. })
  99. }
  100. },
  101. })