index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. wx.showModal({
  40. title: '登录身份选择',
  41. content: '请选择您的身份以完成登录',
  42. confirmText: '我是老师',
  43. cancelText: '我是家长',
  44. success: (res) => {
  45. if (res.confirm) {
  46. wx.navigateTo({
  47. url: '/pages/logins/logins'
  48. });
  49. } else if (res.cancel) {
  50. wx.navigateToMiniProgram({
  51. appId: 'wx06f2b1b09ac5684f',
  52. path: 'pages/logins/logins',
  53. });
  54. }
  55. }
  56. });
  57. return;
  58. }
  59. // if (!isLoggedIn && index !== 0) {
  60. // // 非首页才拦截
  61. // wx.showModal({
  62. // title: '绑定手机号',
  63. // content: '防止账号丢失以及方便找回,建议您绑定手机号码',
  64. // confirmText: '去绑定',
  65. // cancelText: '取消',
  66. // success(res) {
  67. // if (res.confirm) {
  68. // wx.navigateTo({
  69. // url: '/pages/logins/logins'
  70. // });
  71. // }
  72. // }
  73. // });
  74. // return;
  75. // }
  76. // 切换 tab 页
  77. wx.switchTab({
  78. url: target.pagePath
  79. });
  80. this.setData({ selected: index });
  81. },
  82. // 支持外部更新选中项
  83. setSelected(index) {
  84. this.setData({ selected: index });
  85. }
  86. }
  87. });