-
zhangwei
2025-01-22 9f0f5d7767506658ab5ca47ba8ff4ede423e47e3
src/common/utils/util.js
@@ -133,12 +133,18 @@
         parseInt(t[2], 10) || null
      )).getTime() / 1000;
   },
   minutesBetweenDates(date1, date2) {
      let dateOne = new Date(date1)
      const oneMinute = 60 * 1000; // 1分钟的毫秒数
      const difference = Math.abs(date2.getTime() - dateOne.getTime()); // 计算两个日期的毫秒差
      return Math.floor(difference / oneMinute); // 将差异转换为分钟并向下取整
   },
   formatDate(dat, type, addNum) {
      if(!dat){
      if (!dat) {
         return '-'
      }
      let date = new Date(dat)
      if(addNum){
      if (addNum) {
         date = new Date(date.setDate(date.getDate() + addNum));
      }
      const year = date.getFullYear();
@@ -714,7 +720,7 @@
      }
      typeof callback == 'function' && callback(theRequest);
   },
   /**
    * 路径转base64
    * @param {Object} string
@@ -739,7 +745,7 @@
            reject(error);
         };
         // #endif
         // #ifdef MP
         if (uni.canIUse('getFileSystemManager')) {
            uni.getFileSystemManager().readFile({
@@ -754,7 +760,7 @@
            })
         }
         // #endif
         // #ifdef APP-PLUS
         plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), (entry) => {
            entry.file((file) => {
@@ -771,8 +777,8 @@
         // #endif
      })
   },
   roundToTwo(num){
      if(isNaN(num)){
   roundToTwo(num) {
      if (isNaN(num)) {
         return 0
      }
      return Math.round((num + Number.EPSILON) * 100) / 100;
@@ -832,5 +838,30 @@
         }
      }
   },
}
   checkFileExtensions(str) {
      const extensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx'];
      return extensions.some(extension => str.includes(extension));
   },
   previewWechat(urlPdf) {
      uni.showLoading({
         title: '正在加载中..'
      })
      uni.downloadFile({
         url: urlPdf,
         success: function(res) {
            var filePath = res.tempFilePath;
            uni.openDocument({
               filePath: filePath,
               showMenu: true,
               success: function(res) {
                  console.log('打开文档成功');
                  uni.hideLoading()
               },
            });
         },
         complete: function(r) {
            uni.hideLoading()
         }
      });
   },
}