12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- const app = getApp();
- Component({
- data: {
- selected: 0,
- list: [
- {
- pagePath: "/pages/index/index",
- text: "教学",
- iconPath: "/image/shouye.png",
- selectedIconPath: "/image/shouye_1.png"
- },
- {
- pagePath: "/pages/groupbuying/groupbuying",
- text: "团购",
- iconPath: "/image/tuangou.png",
- selectedIconPath: "/image/tuangou_1.png"
- },
- {
- pagePath: "/pages/shoppingcart/shoppingcart",
- text: "购物车",
- iconPath: "/image/gouwuche.png",
- selectedIconPath: "/image/gouwuche_1.png"
- },
- {
- pagePath: "/pages/me/me",
- text: "我的",
- iconPath: "/image/me.png",
- selectedIconPath: "/image/my_1.png"
- }
- ]
- },
- methods: {
- onTabTap(e) {
- const index = e.currentTarget.dataset.index;
- const target = this.data.list[index];
- // 判断登录状态
- const isLoggedIn = wx.getStorageSync('userInfo');
- if (!isLoggedIn && index !== 0) {
- wx.showModal({
- title: '登录身份选择',
- content: '请选择您的身份以完成登录',
- confirmText: '我是老师',
- cancelText: '我是家长',
- success: (res) => {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/logins/logins'
- });
- } else if (res.cancel) {
- wx.navigateToMiniProgram({
- appId: 'wx06f2b1b09ac5684f',
- path: 'pages/logins/logins',
- });
- }
- }
- });
- return;
- }
- // if (!isLoggedIn && index !== 0) {
- // // 非首页才拦截
- // wx.showModal({
- // title: '绑定手机号',
- // content: '防止账号丢失以及方便找回,建议您绑定手机号码',
- // confirmText: '去绑定',
- // cancelText: '取消',
- // success(res) {
- // if (res.confirm) {
- // wx.navigateTo({
- // url: '/pages/logins/logins'
- // });
- // }
- // }
- // });
- // return;
- // }
- // 切换 tab 页
- wx.switchTab({
- url: target.pagePath
- });
- this.setData({ selected: index });
- },
- // 支持外部更新选中项
- setSelected(index) {
- this.setData({ selected: index });
- }
- }
- });
|