index.js 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Component({
  2. data: {
  3. active: 0,
  4. list: [],
  5. initList: [
  6. {
  7. icon: 'home-o',
  8. text: '首页',
  9. url: '/pages/index/index'
  10. },
  11. {
  12. icon: 'bar-chart-o',
  13. text: '数据中心',
  14. url: '/pages/data/index'
  15. },
  16. {
  17. icon: 'user-o',
  18. text: '个人中心',
  19. url: '/pages/account/index'
  20. }
  21. ],
  22. role: ''
  23. },
  24. lifetimes: {
  25. attached: function() {
  26. },
  27. },
  28. methods: {
  29. onChange(event) {
  30. this.setData({ active: event.detail });
  31. wx.switchTab({
  32. url: this.data.list[event.detail].url
  33. });
  34. },
  35. init() {
  36. const page = getCurrentPages().pop();
  37. var userInfo = getApp().globalData.userInfo
  38. var role = userInfo ? userInfo.topRole : ''
  39. var list = this.data.initList
  40. if(role && role.key == 'leader') {
  41. list = this.data.initList.slice(1)
  42. }
  43. this.setData({
  44. list: list
  45. })
  46. this.setData({
  47. active: this.data.list.findIndex(item => item.url === `/${page.route}`),
  48. role: role
  49. });
  50. }
  51. }
  52. });