1
YM
2024-09-10 e38c14de9637d22d0a35ae06bede82dcf31b64ec
packageBookService/pages/bookServices/detail/components/tree/index.js
@@ -96,6 +96,7 @@
    },
    // 节点展开
    handleChange(e) {
      console.log(e.detail.value);
      this.setData({
        openIds: e.detail.value,
      });
@@ -139,38 +140,14 @@
      if (token) {
        const item = e.currentTarget.dataset.item;
        const parent = e.currentTarget.dataset.parent;
        console.log('item', item);
        const parentProductLinkPath = parent ?
          parent.productLinkPath :
          wx.getStorageSync("teachResourcesPath");
        const parentName = parent ? parent.name : "教学资源";
        let url;
        if (item.selectType == 'zip') {
          if (this.properties.applyState == 'Normal') {
            return wx.showToast({
              icon: 'error',
              title: '请前往PC端下载',
            })
          } else {
            return wx.showToast({
              icon: 'error',
              title: '请先申请下载',
            })
          }
        }
        if (this.properties.isShowCheck && this.resourceIsBuy(item)) {
          return false;
        }
        if (item.selectType == "video" || item.learnSelectType == "video") {
          url = "/packageDomain/pages/resourceDetails/myVideo/index";
        } else if (
          item.selectType == "audio" ||
          item.learnSelectType == "audio"
        ) {
          url = "/packageDomain/pages/resourceDetails/myAudio/index";
        } else if (item.selectType == "picture" || item.selectType == "zip") {
          url = "/packageDomain/pages/resourceDetails/document/index";
        }
        if (
          this.properties.tab == "jsek_cloudLearning" &&
          this.resourceIsBuy(item)
@@ -181,16 +158,8 @@
              "请先购买该资源" : "请先点击领取查看按钮",
          });
        }
        if (
          item.saleMethod.length == 0 &&
          item.sysType == "CmsItem" &&
          this.properties.tab == "jsek_cloudLearning"
        ) {
          return wx.showToast({
            icon: "error",
            title: "暂未开始销售,请联系管理员",
          });
        }
        if (this.properties.tab == "jsek_teachingResources" && (item.file || item.freeFile)) {
          let file = item.fileMap[item.file] ? item.fileMap[item.file] : item.fileMap[item.freeFile]
          if (file && file.protectType !== "Public") {
@@ -205,66 +174,50 @@
            title: '暂无资源',
          })
        }
        if (item.selectType == 'zip') {
          if (this.properties.applyState == 'Normal') {
            return wx.showToast({
              icon: 'error',
              title: '请前往PC端下载',
            })
          } else {
            return wx.showToast({
              icon: 'error',
              title: '请先申请下载',
            })
          }
        }
        let url;
        if (item.selectType == "webpage") {
          // 网页类型跳转到网址复制页,因为url传参不能传 带参数的网络地址,所以此处要把网络地址里的传参摘出来,放到url里
          let urlData = ''
          const flags = item.jsek_link.indexOf("?")
          if (flags > -1) {
            urlData = item.jsek_link.slice(flags + 1, item.jsek_link.length)
          }
          url = '/packageBookService/pages/bookServices/linkPage/index'
          return wx.navigateTo({
            url: urlData ? url + `?path=${item.jsek_link.slice(0,flags)}` + '&' + urlData : url + `?path=${item.jsek_link}`
          })
        }
        if (item.selectType == "video" || item.learnSelectType == "video") {
          url = "/packageDomain/pages/resourceDetails/myVideo/index";
        }
        if (
          item.selectType == "audio" ||
          item.learnSelectType == "audio"
        ) {
          url = "/packageDomain/pages/resourceDetails/myAudio/index";
        }
        if (item.selectType == "picture") {
          url = "/packageDomain/pages/resourceDetails/document/index";
        }
        wx.navigateTo({
          url: `${url}?productLinkPath=${item.productLinkPath}&parentProductLinkPath=${parentProductLinkPath}&parentName=${parentName}&activeId=${item.id}&bookId=${this.properties.bookInfo.id}&bookName=${this.properties.bookInfo.name}&cmsId=${this.properties.bookInfo.rootCmsItemId}&formPath=${this.properties.tab}&applyState=${this.properties.applyState}&deadline=${this.properties.deadline}`,
        });
        if (item.selectType == "pdf") {
          const fileLink = item.file ? item.file : item.freeFile
          console.log(fileLink);
          wx.navigateTo({
            url: "/packageBookService/pages/components/webView/index?md5=" +
              fileLink +
              "&fileName=" +
              item.name +
              "&fileType=" +
              item.selectType + "&bookBuy=true"
          });
        }
        if (item.selectType == "document") {
          // freeFile
          // if (item.selectType == "document") {
          //   item.selectType = "pptx";
          // }
          const fileLink = item.file ?
            app.config.requestCtx + "/file/api/ApiDownload?md5=" + item.file :
            app.config.requestCtx +
            "/file/api/ApiDownload?md5=" +
            item.freeFile;
          console.log(fileLink, "fileLink");
          //提示加载中
          // 单次下载允许的最大文件为 200MB
          wx.downloadFile({
            url: fileLink,
            // filePath: wx.env.USER_DATA_PATH + `/${item.name}.${item.selectType}`,
            filePath: wx.env.USER_DATA_PATH + `/${item.name}.${item.selectType}`,
            success: function (res) {
              console.log(res, "wx.downloadFile success res");
              if (res.statusCode != 200) {
                util.hideLoadingWithErrorTips();
                return false;
              }
              var Path = res.tempFilePath; //返回的文件临时地址,用于后面打开本地预览所用
              let data = res.filePath;
              wx.openDocument({
                filePath: data,
                showMenu: true,
                success: function (res) {
                  console.log("打开成功");
                  util.hideLoading();
                },
              });
            },
            fail: function (err) {
              console.log(err, "wx.downloadFile fail err");
              util.hideLoadingWithErrorTips();
            },
          });
        }
        if (item.selectType == "webpage") {
          this.setData({
            webpageSrc: item.jsek_link,
          });
        }
      }
    },