From 3d43ffa3152110b7823f9fa6320c08a6ae02358a Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周三, 10 9月 2025 11:15:40 +0800
Subject: [PATCH] 1、增加 堆垛机运行统计 2、增加po单空物料描述
---
SiemensWarehouse/siemens2-site/src/utils/formatTime.js | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 180 insertions(+), 0 deletions(-)
diff --git a/SiemensWarehouse/siemens2-site/src/utils/formatTime.js b/SiemensWarehouse/siemens2-site/src/utils/formatTime.js
new file mode 100644
index 0000000..125a411
--- /dev/null
+++ b/SiemensWarehouse/siemens2-site/src/utils/formatTime.js
@@ -0,0 +1,180 @@
+/**
+ * 鏃堕棿鏃ユ湡杞崲
+ * @param date 褰撳墠鏃堕棿锛宯ew Date() 鏍煎紡
+ * @param format 闇�瑕佽浆鎹㈢殑鏃堕棿鏍煎紡瀛楃涓�
+ * @description format 瀛楃涓查殢鎰忥紝濡� `YYYY-mm銆乊YYY-mm-dd`
+ * @description format 瀛e害锛�"YYYY-mm-dd HH:MM:SS QQQQ"
+ * @description format 鏄熸湡锛�"YYYY-mm-dd HH:MM:SS WWW"
+ * @description format 鍑犲懆锛�"YYYY-mm-dd HH:MM:SS ZZZ"
+ * @description format 瀛e害 + 鏄熸湡 + 鍑犲懆锛�"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ"
+ * @returns 杩斿洖鎷兼帴鍚庣殑鏃堕棿瀛楃涓�
+ */
+export function formatDate(date, format) {
+ const we = date.getDay(); // 鏄熸湡
+ const z = getWeek(date); // 鍛�
+ const qut = Math.floor((date.getMonth() + 3) / 3).toString(); // 瀛e害
+ const opt = {
+ 'Y+': date.getFullYear().toString(), // 骞�
+ 'm+': (date.getMonth() + 1).toString(), // 鏈�(鏈堜唤浠�0寮�濮嬶紝瑕�+1)
+ 'd+': date.getDate().toString(), // 鏃�
+ 'H+': date.getHours().toString(), // 鏃�
+ 'M+': date.getMinutes().toString(), // 鍒�
+ 'S+': date.getSeconds().toString(), // 绉�
+ 'q+': qut, // 瀛e害
+ };
+ // 涓枃鏁板瓧 (鏄熸湡)
+ const week = {
+ '0': '鏃�',
+ '1': '涓�',
+ '2': '浜�',
+ '3': '涓�',
+ '4': '鍥�',
+ '5': '浜�',
+ '6': '鍏�',
+ };
+ // 涓枃鏁板瓧锛堝搴︼級
+ const quarter = {
+ '1': '涓�',
+ '2': '浜�',
+ '3': '涓�',
+ '4': '鍥�',
+ };
+ if (/(W+)/.test(format))
+ format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '鏄熸湡' + week[we] : '鍛�' + week[we]) : week[we]);
+ if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? '绗�' + quarter[qut] + '瀛e害' : quarter[qut]);
+ if (/(Z+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? '绗�' + z + '鍛�' : z + '');
+ for (const k in opt) {
+ const r = new RegExp('(' + k + ')').exec(format);
+ // 鑻ヨ緭鍏ョ殑闀垮害涓嶄负1锛屽垯鍓嶉潰琛ラ浂
+ if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0'));
+ }
+ return format;
+}
+
+/**
+ * 鏃堕棿鏃ユ湡杞崲
+ * @param date 褰撳墠鏃堕棿锛宯ew Date() 鏍煎紡
+ * @param format 闇�瑕佽浆鎹㈢殑鏃堕棿鏍煎紡瀛楃涓�
+ * @description format 瀛楃涓查殢鎰忥紝濡� `YYYY-mm銆乊YYY-mm-dd`
+ * @description format 瀛e害锛�"YYYY-mm-dd HH:MM:SS QQQQ"
+ * @description format 鏄熸湡锛�"YYYY-mm-dd HH:MM:SS WWW"
+ * @description format 鍑犲懆锛�"YYYY-mm-dd HH:MM:SS ZZZ"
+ * @description format 瀛e害 + 鏄熸湡 + 鍑犲懆锛�"YYYY/MM/DD HH:mm:ss WWW QQQQ ZZZ"
+ * @returns 杩斿洖鎷兼帴鍚庣殑鏃堕棿瀛楃涓� YYYY-MM-DD HH:mm:ss
+ */
+export function formatDateV2(date, format) {
+ //debugger
+ const we = date.getDay(); // 鏄熸湡
+ const z = getWeek(date); // 鍛�
+ const qut = Math.floor((date.getMonth() + 3) / 3).toString(); // 瀛e害
+ const opt = {
+ 'Y+': date.getFullYear().toString(), // 骞�
+ 'M+': (date.getMonth() + 1).toString(), // 鏈�(鏈堜唤浠�0寮�濮嬶紝瑕�+1)
+ 'D+': date.getDate().toString(), // 鏃�
+ 'H+': date.getHours().toString(), // 鏃�
+ 'm+': date.getMinutes().toString(), // 鍒�
+ 's+': date.getSeconds().toString(), // 绉�
+ 'q+': qut, // 瀛e害
+ };
+ // 涓枃鏁板瓧 (鏄熸湡)
+ const week = {
+ '0': '鏃�',
+ '1': '涓�',
+ '2': '浜�',
+ '3': '涓�',
+ '4': '鍥�',
+ '5': '浜�',
+ '6': '鍏�',
+ };
+ // 涓枃鏁板瓧锛堝搴︼級
+ const quarter = {
+ '1': '涓�',
+ '2': '浜�',
+ '3': '涓�',
+ '4': '鍥�',
+ };
+ if (/(W+)/.test(format))
+ format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '鏄熸湡' + week[we] : '鍛�' + week[we]) : week[we]);
+ if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? '绗�' + quarter[qut] + '瀛e害' : quarter[qut]);
+ if (/(Z+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? '绗�' + z + '鍛�' : z + '');
+ for (const k in opt) {
+ const r = new RegExp('(' + k + ')').exec(format);
+ // 鑻ヨ緭鍏ョ殑闀垮害涓嶄负1锛屽垯鍓嶉潰琛ラ浂
+ if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0'));
+ }
+ return format;
+}
+
+/**
+ * 鑾峰彇褰撳墠鏃ユ湡鏄鍑犲懆
+ * @param dateTime 褰撳墠浼犲叆鐨勬棩鏈熷��
+ * @returns 杩斿洖绗嚑鍛ㄦ暟瀛楀��
+ */
+export function getWeek(dateTime) {
+ const temptTime = new Date(dateTime.getTime());
+ // 鍛ㄥ嚑
+ const weekday = temptTime.getDay() || 7;
+ // 鍛�1+5澶�=鍛ㄥ叚
+ temptTime.setDate(temptTime.getDate() - weekday + 1 + 5);
+ let firstDay = new Date(temptTime.getFullYear(), 0, 1);
+ const dayOfWeek = firstDay.getDay();
+ let spendDay = 1;
+ if (dayOfWeek != 0) spendDay = 7 - dayOfWeek + 1;
+ firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay);
+ const d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 86400000);
+ const result = Math.ceil(d / 7);
+ return result;
+}
+
+/**
+ * 鏃堕棿闂�欒
+ * @param param 褰撳墠鏃堕棿锛宯ew Date() 鏍煎紡
+ * @description param 璋冪敤 `formatAxis(new Date())` 杈撳嚭 `涓婂崍濂絗
+ * @returns 杩斿洖鎷兼帴鍚庣殑鏃堕棿瀛楃涓�
+ */
+export function formatAxis(param) {
+ const hour = new Date(param).getHours();
+ if (hour < 6) return '鍑屾櫒濂�';
+ else if (hour < 9) return '鏃╀笂濂�';
+ else if (hour < 12) return '涓婂崍濂�';
+ else if (hour < 14) return '涓崍濂�';
+ else if (hour < 17) return '涓嬪崍濂�';
+ else if (hour < 19) return '鍌嶆櫄濂�';
+ else if (hour < 22) return '鏅氫笂濂�';
+ else return '澶滈噷濂�';
+}
+
+//榛樿璧嬪�� 褰撳墠涓�鍛ㄧ殑鏃堕棿
+export function getThisWeekRange(flag) {
+
+ //鏆傛椂閮借繑鍥炵┖
+ //return ["",""];
+
+ const today = new Date();
+ const startOfWeek = new Date();
+ // if(flag==1){//琛ㄧず瑕佹煡7澶╁唴鏁版嵁
+ // //startOfWeek.setDate(today.getDate() -6); // 鍑忓幓浠婂ぉ鏄竴鍛ㄧ殑绗嚑澶╋紝寰楀埌鍛ㄤ竴鐨勬棩鏈焥tartOfWeek
+ // startOfWeek.setDate(today.getDate() -2); // 鍑忓幓浠婂ぉ鏄竴鍛ㄧ殑绗嚑澶╋紝寰楀埌鍛ㄤ竴鐨勬棩鏈焥tartOfWeek
+ // }
+ startOfWeek.setDate(today.getDate() - flag); // 鍑忓幓浠婂ぉ鏄竴鍛ㄧ殑绗嚑澶╋紝寰楀埌鍛ㄤ竴鐨勬棩鏈焥tartOfWeek
+ startOfWeek.setHours(0, 0, 0, 0); // 璁剧疆鏃躲�佸垎銆佺鍜屾绉掓暟
+
+ const endOfWeek = new Date(today);
+ endOfWeek.setDate(endOfWeek.getDate() + 1);
+ //endOfWeek.setHours(23, 59, 59, 999); // 璁剧疆鏃躲�佸垎銆佺鍜屾绉掓暟
+ endOfWeek.setHours(0, 0, 0, 0); // 璁剧疆鏃躲�佸垎銆佺鍜屾绉掓暟
+
+
+ //return [moment(startOfWeek,"YYYY-MM-DD HH:mm"), moment(endOfWeek,"YYYY-MM-DD HH:mm")];
+ //return [moment(startOfWeek), moment(endOfWeek)];
+
+ // const startStr = formatDateV2(startOfWeek,'YYYY-MM-DD HH:mm:ss');
+ // const endStr = formatDateV2(endOfWeek,'YYYY-MM-DD HH:mm:ss');
+ //return [new Date(startStr), new Date(endStr)];
+ // const startStr = formatDateV2(startOfWeek, 'yyyy-MM-dd HH:mm:ss');
+ // const endStr = formatDateV2(endOfWeek, 'yyyy-MM-dd HH:mm:ss');
+ // return [startStr, endStr];
+ // 鉁� 鐩存帴杩斿洖 Date 瀵硅薄鐨勬暟缁�
+ return [startOfWeek, endOfWeek];
+ //*/
+}
--
Gitblit v1.9.3