-
zhangwei
2025-03-06 02ad32582e3a3b0e6f4b2d1b50593eff1d0558e3
src/common/utils/util.js
@@ -153,7 +153,7 @@
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      if (type) {
         return `${year}-${month}-${day} ${hours}:${minutes}`;
         return type=='riqi' ? `${month}-${day}`: `${year}-${month}-${day} ${hours}:${minutes}`;
      }
      return `${year}-${month}-${day}`;
   },
@@ -838,5 +838,61 @@
         }
      }
   },
   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;
            const index = urlPdf.lastIndexOf(".");
            const suffix = urlPdf.substring(index + 1);
            uni.openDocument({
               fileType: suffix,
               filePath: filePath,
               showMenu: true,
               success: function(res) {
                  console.log('打开文档成功');
                  uni.hideLoading()
               },
            });
         },
         complete: function(r) {
            uni.hideLoading()
         }
      });
   },
   //生成时间戳+随机数
   // 生成时间戳+随机数的函数
   generateTimestampWithRandom(filename) {
      // 获取当前日期和时间
      const now = new Date();
      // 获取年份,确保为四位数
      const year = now.getFullYear();
      // 获取月份,确保为两位数
      const month = String(now.getMonth() + 1).padStart(2, '0');
      // 获取日期,确保为两位数
      const day = String(now.getDate()).padStart(2, '0');
      // 获取小时,确保为两位数
      const hours = String(now.getHours()).padStart(2, '0');
      // 获取分钟,确保为两位数
      const minutes = String(now.getMinutes()).padStart(2, '0');
      // 获取秒数,确保为两位数
      const seconds = String(now.getSeconds()).padStart(2, '0');
      // 拼接时间戳
      const timestamp = `${year}${month}${day}${hours}${minutes}${seconds}`;
      // 生成一个 0 到 9999 之间的随机数,并格式化为四位数
      const randomNumber = String(Math.floor(Math.random() * 10000)).padStart(4, '0');
      // 拼接时间戳和随机数
      return `cylsg/${timestamp}_${randomNumber}` + filename.match(/\.[^.]+$/);
   },
   getFileExtensionWithDotRegex(filename) {
      const match = filename.match(/\.[^.]+$/);
      return match ? match[0] : '';
   }
}