zhongshujie
15 小时以前 e2bf73079051769b7b7cdc9627fc32ce64226144
packageBookService/pages/psychologyAnswer/psychologyAnswer.js
@@ -9,6 +9,7 @@
   * 页面的初始数据
   */
  data: {
    isBuy: false, // 是否需要购买
    questuionName: "", //试卷名称
    dataList: "",
    barHeight: "",
@@ -37,15 +38,48 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const questuionName = options.listName
    // 在此进行是否购买的查询
    const questionId = options.listId;
    const query = {
      "cmsItemId": Number(questionId)
    };
    app.MG.file.checkCmsItem(query)
      .then((res) => {
        const isBuys = res;
    this.setData({
      questuionName: questuionName
    })
          isBuy: isBuys
        });
        if (!isBuys) {
          wx.showModal({
            icon: 'error',
            title: '温馨提示',
            content: '请购买题库,即将返回首页',
            confirmText: '确定',
            showCancel: false, // 关闭取消按钮
            success: function (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/pages/home/home', // 替换为你的首页路径
                });
              }
            }
          });
          return; // 直接返回,避免执行后续代码
        }
        // 其他逻辑
        const questuionName = options.listName;
        this.setData({
          questionName: questuionName
        });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight =
      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    const token = wx.getStorageSync(app.config.tokenKey)
        const token = wx.getStorageSync(app.config.tokenKey);
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
@@ -53,12 +87,21 @@
        } else {
          this.init();
        }
      })
          });
    } else {
      this.init()
          this.init();
    }
      })
      .catch((err) => {
        console.error('检查题库失败:', err);
        wx.showToast({
          icon: 'error',
          title: '加载失败,请重试'
        });
      });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */