tarbar.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // compontents/tarbar/tarbar.js
  2. const util = require('../../utils/util.js');
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. motto: ['我的','本周推荐','语文','数学','中文','英语','科学','艺术'],
  14. navBtnSelectIdx: 0,
  15. left: 0
  16. },
  17. /**
  18. * 组件的方法列表
  19. */
  20. methods: {
  21. navItemTap: function (e) {
  22. //更改navBtnSelectIdx加class
  23. let index = e.target.dataset.index;
  24. if (index != this.navBtnSelectIdx) {
  25. this.setData({ navBtnSelectIdx: index});
  26. }
  27. //移动nav
  28. if (index <= 2) {
  29. this.setData({ left: 0 });
  30. }
  31. if(index > 2){
  32. this.setData({left: 200 });
  33. }
  34. if(index == 0) {
  35. wx.redirectTo({
  36. url: '../index/index?ind=0'
  37. })
  38. }
  39. if(index == 1) {
  40. wx.redirectTo({
  41. url: '../recommend/recommend?ind=1'
  42. })
  43. }
  44. if(index == 2) {
  45. wx.redirectTo({
  46. url: '../language/language?ind=2'
  47. })
  48. }
  49. if(index == 3) {
  50. wx.redirectTo({
  51. url: '../mathematics/mathematics?ind=3'
  52. })
  53. }
  54. if(index == 4) {
  55. wx.redirectTo({
  56. url: '../chinese/chinese?ind=4'
  57. })
  58. }
  59. if(index == 5) {
  60. wx.redirectTo({
  61. url: '../english/english?ind=5'
  62. })
  63. }
  64. if(index == 6) {
  65. wx.redirectTo({
  66. url: '../science/science?ind=6'
  67. })
  68. }
  69. if(index == 7) {
  70. wx.redirectTo({
  71. url: '../art/art?ind=7'
  72. })
  73. }
  74. }
  75. },
  76. ready() {
  77. let options = util.getUrl();
  78. console.log(options)
  79. if(options.ind) {
  80. this.setData({ navBtnSelectIdx: options.ind});
  81. }
  82. if (options.ind <= 2) {
  83. this.setData({ left: 0 });
  84. }
  85. if(options.ind > 2){
  86. this.setData({left: 200 });
  87. }
  88. }
  89. })