index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const app = getApp();
  2. Component({
  3. data: {
  4. selected: 0,
  5. list: [
  6. {
  7. pagePath: "/pages/index/index",
  8. text: "教学",
  9. iconPath: "/image/shouye.png",
  10. selectedIconPath: "/image/shouye_1.png"
  11. },
  12. {
  13. pagePath: "/pages/groupbuying/groupbuying",
  14. text: "团购",
  15. iconPath: "/image/tuangou.png",
  16. selectedIconPath: "/image/tuangou_1.png"
  17. },
  18. {
  19. pagePath: "/pages/shoppingcart/shoppingcart",
  20. text: "购物车",
  21. iconPath: "/image/gouwuche.png",
  22. selectedIconPath: "/image/gouwuche_1.png"
  23. },
  24. {
  25. pagePath: "/pages/me/me",
  26. text: "我的",
  27. iconPath: "/image/me.png",
  28. selectedIconPath: "/image/my_1.png"
  29. }
  30. ]
  31. },
  32. methods: {
  33. onTabTap(e) {
  34. const index = e.currentTarget.dataset.index;
  35. const target = this.data.list[index];
  36. // 判断登录状态
  37. // const isLoggedIn = wx.getStorageSync('userInfo');
  38. // if (!isLoggedIn && index !== 0) {
  39. // // 非首页才拦截
  40. // wx.showModal({
  41. // title: '去登录',
  42. // content: '防止账号丢失以及方便找回,建议您绑定手机号码',
  43. // confirmText: '去绑定',
  44. // cancelText: '取消',
  45. // success(res) {
  46. // if (res.confirm) {
  47. // wx.navigateTo({
  48. // url: '/pages/logins/logins'
  49. // });
  50. // }
  51. // }
  52. // });
  53. // return;
  54. // }
  55. const isLoggedIn = wx.getStorageSync('userInfo');
  56. if (!isLoggedIn && index !== 0) {
  57. wx.showModal({
  58. title: '登录身份选择',
  59. content: '请选择您的身份以完成登录',
  60. confirmText: '我是家长',
  61. cancelText: '我是老师',
  62. success: (res) => {
  63. if (res.confirm) {
  64. wx.navigateTo({
  65. url: '/pages/logins/logins'
  66. });
  67. } else if (res.cancel) {
  68. wx.navigateToMiniProgram({
  69. appId: 'wx06f2b1b09ac5684f',
  70. path: 'pages/logins/logins',
  71. });
  72. }
  73. }
  74. });
  75. return;
  76. }
  77. // 切换 tab 页
  78. wx.switchTab({
  79. url: target.pagePath
  80. });
  81. this.setData({ selected: index });
  82. },
  83. // 支持外部更新选中项
  84. setSelected(index) {
  85. this.setData({ selected: index });
  86. }
  87. }
  88. });