闫增涛
2025-03-27 96b0b8bb1597d825004f5a8da0728c48b6ce7dba
首页登录去除侧式
1个文件已修改
59 ■■■■■ 已修改文件
pages/home/home.js 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.js
@@ -77,17 +77,17 @@
    // 首页测试登录功能,后续注释
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        // 如果不是第一次登录,会执行回调
        if (data) {
          this.init();
          this.registe()
        } else {
          this.init();
        }
      })
    }
    // if (!token) {
    //   loginInfo(app, (data) => {
    //     // 如果不是第一次登录,会执行回调
    //     if (data) {
    //       this.init();
    //       this.registe()
    //     } else {
    //       this.init();
    //     }
    //   })
    // }
  },
  onReachBottom() {},
@@ -532,11 +532,29 @@
      })
    })
  },
  async addCart(e) {
  addCart(e) {
    const {
      info
    } = e.currentTarget.dataset;
    if (wx.getStorageSync(app.config.tokenKey)) {
    const token = wx.getStorageSync(app.config.tokenKey)
    if (token) {
      this.addCartFun(info)
    } else {
      if (!token) {
        loginInfo(app, (data) => {
          // 如果不是第一次登录,会执行回调
          if (data) {
            this.addCartFun(info)
            this.registe()
          } else {
            this.addCartFun(info)
          }
        })
      }
    }
  },
  // 剥离加入购物车方法登陆前后公用
  addCartFun(info) {
      if (info.isbuy) {
        wx.showToast({
          title: "该商品已购买",
@@ -544,12 +562,6 @@
          duration: 1000
        })
      } else {
        let query = {
          start: 0,
          size: 999,
          filterList: [],
          searchList: []
        }
        try {
          if (
            this.data.shoppingCartGetId.includes(
@@ -569,20 +581,17 @@
                agentCode: '电子书'
              }]
            }
            const addRes = await app.MG.store.addShoppingCart(query)
            if (addRes) {
              wx.showToast({
          app.MG.store.addShoppingCart(query).then(res => {
            if (res) wx.showToast({
                title: "添加成功",
                icon: 'success',
                duration: 1000
              })
            }
            this.getShoppingCartList()
          })
          }
        } catch (error) {
          console.error('出错了:', error)
        }
      }
    }
  },