index.js 3.1 KB

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