From a647b8fb3c96791c126dcf26c78676adc35c670f Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期五, 27 十月 2023 17:12:18 +0800
Subject: [PATCH] 修改编码规则管理基础码段编辑bug,修改ts日期转换报错bug

---
 Source/UBCS-WEB/src/util/func.js |   78 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/Source/UBCS-WEB/src/util/func.js b/Source/UBCS-WEB/src/util/func.js
index 12f731b..78bd256 100644
--- a/Source/UBCS-WEB/src/util/func.js
+++ b/Source/UBCS-WEB/src/util/func.js
@@ -74,6 +74,23 @@
   }
 
   /**
+   * ts鏃ユ湡鏍煎紡澶勭悊
+   * @param {瑕佸鐞嗙殑鏃ユ湡} thisDate 
+   * @returns 
+   */
+  static formattedDateTime(thisDate) {
+    const date = new Date(thisDate);
+    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');
+    const seconds = date.getSeconds().toString().padStart(2, '0');
+    const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
+    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
+  }
+
+  /**
    * 鏍规嵁閫楀彿鑱斿悎
    * @param arr
    * @returns {string}
@@ -110,4 +127,65 @@
   static isValuableObj(value) {
     return typeof value === 'object' && value !== null && Object.keys(value).length > 0;
   }
+  /**
+   * 鑾峰彇娴佹枃浠惰繘琛屾枃浠朵笅
+   * @param value
+   * @returns {Boolean}
+   */
+  static downloadFileByBlobHandler(res) {
+    const fileNames = res.headers['content-disposition'].split(";");
+    let characterSet = fileNames[2].split("filename*=")[1];
+    let fileName = decodeURI(fileNames[1].split("filename=")[1],characterSet);  // 涓嬭浇鐨勬枃浠跺悕
+    let blob = new Blob([res.data], {
+      type: res.data.type + ";charset=utf-8",
+    });
+    const url = URL.createObjectURL(blob); // 鐢熸垚涓嬭浇閾炬帴
+    const link = document.createElement("a");
+    link.href = url;
+    link.download = fileName; // 鎸囧畾鏂囦欢鍚嶅拰鏍煎紡
+    document.body.appendChild(link); // 娣诲姞涓嬭浇閾炬帴鍒伴〉闈�
+    link.click(); // 瑙﹀彂涓嬭浇
+    document.body.removeChild(link); //鍒犻櫎涓嬭浇
+    window.URL.revokeObjectURL(url); //閲婃斁鎺塨lob瀵硅薄
+  }
+
+  /**
+   * 鑾峰彇娴佹枃浠惰繘琛屾枃浠朵笅
+   * @param value
+   * @returns {Boolean}
+   */
+  static downloadFileByBlob(blobData, name) {
+    const url = URL.createObjectURL(blobData); // 鐢熸垚涓嬭浇閾炬帴
+    const link = document.createElement("a");
+    link.href = url;
+    link.download = name; // 鎸囧畾鏂囦欢鍚嶅拰鏍煎紡
+    document.body.appendChild(link); // 娣诲姞涓嬭浇閾炬帴鍒伴〉闈�
+    link.click(); // 瑙﹀彂涓嬭浇
+    document.body.removeChild(link); //鍒犻櫎涓嬭浇
+  }
+
+  /**
+   * 灏嗘暟缁勪腑鐨勫睘鎬ф嫾鎺ユ垚瀛楃涓�
+   * @param {鏁扮粍} array 
+   * @param {灞炴� attr 
+   * @returns 
+   */
+  static joinedString(array,attr) {
+    return array.reduce((accumulator, item) => {
+      return accumulator + (accumulator ? ',' : '') + item[attr];
+    }, '');
+  }
+
+  /**
+   * 姣斿鏁扮粍涓殑瀵硅薄鐨勬煇涓睘鎬ф槸鍚﹀叏閮ㄤ竴鑷�
+   * @param {鏁扮粍} array 
+   * @param {灞炴� attr 
+   * @returns 涓�鑷磋繑鍥瀎asle,涓嶄竴鑷磋繑鍥瀟rue
+   */
+  static isAttrInconsistent(array,attr) {
+    return Object.values(array).some((item, index, array) => {
+      return item[attr] !== array[0][attr];
+    });
+  }
+
 }

--
Gitblit v1.9.3