index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Component({
  2. /**
  3. * 组件的属性列表
  4. */
  5. properties: {},
  6. lifetimes: {
  7. attached() {
  8. // 在组件实例进入页面节点树时执行
  9. },
  10. ready: function () {
  11. if (this.data.count == 1) return;
  12. if (!wx.getStorageSync('userauth')) return;
  13. //判断页面 以免一直触发
  14. let pages = getCurrentPages();
  15. let prevPage = pages[pages.length - 1];
  16. if (prevPage.route == 'pages/login/selectSite' || prevPage.route.includes('pages/tabbar/')) {
  17. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心', '消息中心']);
  18. let auth2 = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['营销物料']);
  19. let list = ['首页'];
  20. auth.forEach(v => {
  21. switch (v.systemmodulename) {
  22. case "个人中心":
  23. list.push('我的')
  24. break;
  25. case "消息中心":
  26. list.push('信息')
  27. break;
  28. }
  29. })
  30. if (auth2.length == 1) list.push('营销物料');
  31. this.setData({
  32. Permission: list,
  33. auth
  34. })
  35. }
  36. },
  37. },
  38. /**
  39. * 组件的初始数据
  40. */
  41. /*
  42. {
  43. icon: 'icon-a-biaoqianlangongzuo',
  44. text: '工作',
  45. url: '/pages/tabbar/workbench/index'
  46. },
  47. */
  48. data: {
  49. active: 'home',
  50. Permission: ['首页'],
  51. auth: [], //个人信息和消息信息的权限
  52. tabbarList: [{
  53. icon: 'icon-a-biaoqianlanshouyexuanzhong',
  54. text: '首页',
  55. url: '/pages/tabbar/home/index',
  56. name: 'home'
  57. },
  58. {
  59. icon: 'icon-a-biaoqianlanxiaoxi',
  60. text: '信息',
  61. url: '/pages/tabbar/message/index',
  62. name: 'message'
  63. },
  64. {
  65. icon: 'icon-a-biaoqianlanzhiku',
  66. text: '营销物料',
  67. url: '/pages/tabbar/smartStore/index',
  68. name: 'smartStore'
  69. },
  70. {
  71. icon: 'icon-a-biaoqianlanwode',
  72. text: '我的',
  73. url: '/pages/tabbar/mine/index',
  74. name: 'mine'
  75. }
  76. ],
  77. },
  78. /**
  79. * 组件的方法列表
  80. */
  81. methods: {
  82. /* tabbar */
  83. onChange(event) {
  84. let active = event.detail,
  85. obj = this.data.tabbarList.find(v => v.name == active);
  86. wx.switchTab({
  87. url: obj.url
  88. });
  89. this.setData({
  90. active
  91. });
  92. },
  93. init() {
  94. const page = getCurrentPages().pop();
  95. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  96. this.setData({
  97. active: obj.name
  98. });
  99. },
  100. },
  101. })