From 2d43a1df3f5ba42710e6d21c27d1e13bdb8dfd56 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期一, 24 三月 2025 09:23:08 +0800
Subject: [PATCH] -
---
src/common/utils/util.js | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 101 insertions(+), 10 deletions(-)
diff --git a/src/common/utils/util.js b/src/common/utils/util.js
index 3594f55..bd7bb9c 100644
--- a/src/common/utils/util.js
+++ b/src/common/utils/util.js
@@ -133,18 +133,27 @@
parseInt(t[2], 10) || null
)).getTime() / 1000;
},
- formatDate(dat, type) {
- if(!dat){
+ 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) {
return '-'
}
let date = new Date(dat)
+ if (addNum) {
+ date = new Date(date.setDate(date.getDate() + addNum));
+ }
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
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}`;
},
@@ -711,7 +720,7 @@
}
typeof callback == 'function' && callback(theRequest);
},
-
+
/**
* 璺緞杞琤ase64
* @param {Object} string
@@ -736,7 +745,7 @@
reject(error);
};
// #endif
-
+
// #ifdef MP
if (uni.canIUse('getFileSystemManager')) {
uni.getFileSystemManager().readFile({
@@ -751,7 +760,7 @@
})
}
// #endif
-
+
// #ifdef APP-PLUS
plus.io.resolveLocalFileSystemURL(getLocalFilePath(path), (entry) => {
entry.file((file) => {
@@ -768,8 +777,8 @@
// #endif
})
},
- roundToTwo(num){
- if(isNaN(num)){
+ roundToTwo(num) {
+ if (isNaN(num)) {
return 0
}
return Math.round((num + Number.EPSILON) * 100) / 100;
@@ -829,5 +838,87 @@
}
}
},
-
-}
+ checkFileExtensions(str) {
+ const extensions = ['pdf', 'doc', 'docx', 'xls', 'xlsx'];
+ return extensions.some(extension => str.includes(extension));
+ },
+ previewWechat(urlPdf) {
+ uni.showLoading({
+ title: '姝e湪鍔犺浇涓�..'
+ })
+ 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] : '';
+ },
+ isEmpty(value) {
+ return (
+ value === null ||
+ value === undefined ||
+ value === '' ||
+ (Array.isArray(value) && value.length === 0) ||
+ (typeof value === 'object' &&!Array.isArray(value) && Object.keys(value).length === 0)
+ );
+ },
+
+ removeEmptyValuesRecursive(obj) {
+ const newObj = {};
+ for (const key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ const value = obj[key];
+ if (!this.isEmpty(value)) {
+ if (typeof value === 'object' &&!Array.isArray(value)) {
+ newObj[key] = removeEmptyValuesRecursive(value);
+ } else {
+ newObj[key] = value;
+ }
+ }
+ }
+ }
+ return newObj;
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.1