index.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Component({
  2. data: {
  3. active: 0,
  4. list: [],
  5. initList: [
  6. {
  7. icon: 'home-o',
  8. text: '首页',
  9. url: '/pages/index/index',
  10. hidden: false
  11. },
  12. {
  13. icon: 'bar-chart-o',
  14. text: '数据中心',
  15. url: '/pages/data/index',
  16. hidden: true
  17. },
  18. {
  19. icon: 'user-o',
  20. text: '个人中心',
  21. url: '/pages/account/index',
  22. hidden: false
  23. }
  24. ],
  25. role: ''
  26. },
  27. lifetimes: {
  28. attached: function() {
  29. },
  30. },
  31. methods: {
  32. onChange(e) {
  33. this.setData({ active: e.detail });
  34. var active = e.detail
  35. var cnt = -1;
  36. var list = this.data.list
  37. var url = '';
  38. for(var i = 0; i < list.length; ++i) {
  39. if(!list[i].hidden) cnt = cnt + 1;
  40. if(cnt == active) {
  41. url = list[i].url
  42. break;
  43. }
  44. }
  45. wx.switchTab({
  46. url: url
  47. });
  48. },
  49. init() {
  50. const page = getCurrentPages().pop();
  51. var userInfo = getApp().globalData.userInfo
  52. var role = userInfo ? userInfo.topRole : ''
  53. var list = this.data.initList
  54. if(role && role.key == 'leader') {
  55. // list = this.data.initList.slice(1)
  56. list[0].hidden = true;
  57. }
  58. if(role && role.rights && role.rights.dataView) {
  59. list[1].hidden = false;
  60. }
  61. this.setData({
  62. list: list
  63. })
  64. var active = -1;
  65. for(var i = 0; i < list.length; ++i) {
  66. if(!list[i].hidden) active = active + 1;
  67. if(list[i].url == '/' + page.route) break;
  68. }
  69. this.setData({
  70. active: active
  71. });
  72. if(role) {
  73. this.setData({role})
  74. }
  75. }
  76. }
  77. });