index.js 1000 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. });
  49. if(role) {
  50. this.setData({role})
  51. }
  52. }
  53. }
  54. });