From c6a61bf9bf4d1ae57098aa26dcf2448ce6bb80e4 Mon Sep 17 00:00:00 2001
From: WXL (wul) <wl_5969728@163.com>
Date: 星期五, 05 九月 2025 10:16:43 +0800
Subject: [PATCH] 测试完成
---
src/utils/ruoyi.js | 144 ++++++++++++++++++++++++++++++------------------
1 files changed, 90 insertions(+), 54 deletions(-)
diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js
index 243c4c7..f02bc0d 100644
--- a/src/utils/ruoyi.js
+++ b/src/utils/ruoyi.js
@@ -1,29 +1,31 @@
-
-
/**
* 閫氱敤js鏂规硶灏佽澶勭悊
* Copyright (c) 2019 ruoyi
*/
+import dayjs from "dayjs";
// 鏃ユ湡鏍煎紡鍖�
export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) {
- return null
+ return null;
}
- const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
+ const format = pattern || "{y}-{m}-{d} {h}:{i}:{s}";
+ let date;
+ if (typeof time === "object") {
+ date = time;
} else {
- if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
- time = parseInt(time)
- } else if (typeof time === 'string') {
- time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
+ if (typeof time === "string" && /^[0-9]+$/.test(time)) {
+ time = parseInt(time);
+ } else if (typeof time === "string") {
+ time = time
+ .replace(new RegExp(/-/gm), "/")
+ .replace("T", " ")
+ .replace(new RegExp(/\.[\d]{3}/gm), "");
}
- if ((typeof time === 'number') && (time.toString().length === 10)) {
- time = time * 1000
+ if (typeof time === "number" && time.toString().length === 10) {
+ time = time * 1000;
}
- date = new Date(time)
+ date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
@@ -32,18 +34,41 @@
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
- a: date.getDay()
- }
+ a: date.getDay(),
+ };
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
- let value = formatObj[key]
+ let value = formatObj[key];
// Note: getDay() returns 0 on Sunday
- if (key === 'a') { return ['鏃�', '涓�', '浜�', '涓�', '鍥�', '浜�', '鍏�'][value] }
- if (result.length > 0 && value < 10) {
- value = '0' + value
+ if (key === "a") {
+ return ["鏃�", "涓�", "浜�", "涓�", "鍥�", "浜�", "鍏�"][value];
}
- return value || 0
- })
- return time_str
+ if (result.length > 0 && value < 10) {
+ value = "0" + value;
+ }
+ return value || 0;
+ });
+ return time_str;
+}
+// 鍑洪櫌/鍏ラ櫌澶╂暟璁$畻
+export function daysBetween(dateString) {
+ // 灏嗚緭鍏ョ殑鏃ユ湡瀛楃涓茶浆鎹负Date瀵硅薄
+ var startDate = new Date(dateString);
+ // 鑾峰彇褰撳墠鏃ユ湡
+ var currentDate = new Date();
+ // 璁$畻涓や釜鏃ユ湡涔嬮棿鐨勬椂闂村樊锛堟绉掞級
+ var differenceInTime = currentDate - startDate;
+ // 灏嗘椂闂村樊杞崲涓哄ぉ鏁�
+ var differenceInDays = differenceInTime / (1000 * 3600 * 24);
+ // 杩斿洖澶╂暟锛屽洓鑸嶄簲鍏ュ埌鏈�鎺ヨ繎鐨勬暣鏁�
+ return Math.round(differenceInDays);
+}
+// 杩囨护鍣�
+export function formatTime(val) {
+ if (val) {
+ return dayjs(val).format("YYYY-MM-DD");
+ } else {
+ return "";
+ }
}
// 琛ㄥ崟閲嶇疆
@@ -56,14 +81,19 @@
// 娣诲姞鏃ユ湡鑼冨洿
export function addDateRange(params, dateRange, propName) {
let search = params;
- search.params = typeof (search.params) === 'object' && search.params !== null && !Array.isArray(search.params) ? search.params : {};
+ search.params =
+ typeof search.params === "object" &&
+ search.params !== null &&
+ !Array.isArray(search.params)
+ ? search.params
+ : {};
dateRange = Array.isArray(dateRange) ? dateRange : [];
- if (typeof (propName) === 'undefined') {
- search.params['beginTime'] = dateRange[0];
- search.params['endTime'] = dateRange[1];
+ if (typeof propName === "undefined") {
+ search.params["beginTime"] = dateRange[0];
+ search.params["endTime"] = dateRange[1];
} else {
- search.params['begin' + propName] = dateRange[0];
- search.params['end' + propName] = dateRange[1];
+ search.params["begin" + propName] = dateRange[0];
+ search.params["end" + propName] = dateRange[1];
}
return search;
}
@@ -75,20 +105,20 @@
}
var actions = [];
Object.keys(datas).some((key) => {
- if (datas[key].value == ('' + value)) {
+ if (datas[key].value == "" + value) {
actions.push(datas[key].label);
return true;
}
- })
+ });
if (actions.length === 0) {
actions.push(value);
}
- return actions.join('');
+ return actions.join("");
}
// 鍥炴樉鏁版嵁瀛楀吀锛堝瓧绗︿覆銆佹暟缁勶級
export function selectDictLabels(datas, value, separator) {
- if (value === undefined || value.length ===0) {
+ if (value === undefined || value.length === 0) {
return "";
}
if (Array.isArray(value)) {
@@ -100,30 +130,32 @@
Object.keys(value.split(currentSeparator)).some((val) => {
var match = false;
Object.keys(datas).some((key) => {
- if (datas[key].value == ('' + temp[val])) {
+ if (datas[key].value == "" + temp[val]) {
actions.push(datas[key].label + currentSeparator);
match = true;
}
- })
+ });
if (!match) {
actions.push(temp[val] + currentSeparator);
}
- })
- return actions.join('').substring(0, actions.join('').length - 1);
+ });
+ return actions.join("").substring(0, actions.join("").length - 1);
}
// 瀛楃涓叉牸寮忓寲(%s )
export function sprintf(str) {
- var args = arguments, flag = true, i = 1;
+ var args = arguments,
+ flag = true,
+ i = 1;
str = str.replace(/%s/g, function () {
var arg = args[i++];
- if (typeof arg === 'undefined') {
+ if (typeof arg === "undefined") {
flag = false;
- return '';
+ return "";
}
return arg;
});
- return flag ? str : '';
+ return flag ? str : "";
}
// 杞崲瀛楃涓诧紝undefined,null绛夎浆鍖栦负""
@@ -148,7 +180,7 @@
}
}
return source;
-};
+}
/**
* 鏋勯�犳爲鍨嬬粨鏋勬暟鎹�
@@ -159,9 +191,9 @@
*/
export function handleTree(data, id, parentId, children) {
let config = {
- id: id || 'id',
- parentId: parentId || 'parentId',
- childrenList: children || 'children'
+ id: id || "id",
+ parentId: parentId || "parentId",
+ childrenList: children || "children",
};
var childrenListMap = {};
@@ -202,19 +234,23 @@
}
/**
-* 鍙傛暟澶勭悊
-* @param {*} params 鍙傛暟
-*/
+ * 鍙傛暟澶勭悊
+ * @param {*} params 鍙傛暟
+ */
export function tansParams(params) {
- let result = ''
+ let result = "";
for (const propName of Object.keys(params)) {
const value = params[propName];
var part = encodeURIComponent(propName) + "=";
- if (value !== null && value !== "" && typeof (value) !== "undefined") {
- if (typeof value === 'object') {
+ if (value !== null && value !== "" && typeof value !== "undefined") {
+ if (typeof value === "object") {
for (const key of Object.keys(value)) {
- if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
- let params = propName + '[' + key + ']';
+ if (
+ value[key] !== null &&
+ value[key] !== "" &&
+ typeof value[key] !== "undefined"
+ ) {
+ let params = propName + "[" + key + "]";
var subPart = encodeURIComponent(params) + "=";
result += subPart + encodeURIComponent(value[key]) + "&";
}
@@ -224,7 +260,7 @@
}
}
}
- return result
+ return result;
}
// 楠岃瘉鏄惁涓篵lob鏍煎紡
--
Gitblit v1.9.3