index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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') != 0) {
  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. {
  44. icon: 'icon-a-biaoqianlangongzuo',
  45. text: '工作',
  46. url: '/pages/tabbar/workbench/index'
  47. },
  48. */
  49. data: {
  50. active: 'home',
  51. Permission: ['首页'],
  52. auth: [], //个人信息和消息信息的权限
  53. tabbarList: [{
  54. icon: 'icon-a-biaoqianlanshouyexuanzhong',
  55. text: '首页',
  56. url: '/pages/tabbar/home/index',
  57. name: 'home'
  58. },
  59. {
  60. icon: 'icon-a-biaoqianlanxiaoxi',
  61. text: '信息',
  62. url: '/pages/tabbar/message/index',
  63. name: 'message'
  64. },
  65. {
  66. icon: 'icon-a-biaoqianlanzhiku',
  67. text: '营销物料',
  68. url: '/pages/tabbar/smartStore/index',
  69. name: 'smartStore'
  70. },
  71. {
  72. icon: 'icon-a-biaoqianlanwode',
  73. text: '我的',
  74. url: '/pages/tabbar/mine/index',
  75. name: 'mine'
  76. }
  77. ],
  78. },
  79. /**
  80. * 组件的方法列表
  81. */
  82. methods: {
  83. /* tabbar */
  84. onChange(event) {
  85. let active = event.detail,
  86. obj = this.data.tabbarList.find(v => v.name == active);
  87. wx.switchTab({
  88. url: obj.url
  89. });
  90. this.setData({
  91. active
  92. });
  93. },
  94. init() {
  95. const page = getCurrentPages().pop();
  96. let obj = this.data.tabbarList.find(item => item.url === `/${page.route}`);
  97. this.setData({
  98. active: obj.name
  99. });
  100. },
  101. },
  102. })