From 909dfdf6ceff702f65bdc15bd958589c6df4195d Mon Sep 17 00:00:00 2001
From: zhangchen <1652267879@qq.com>
Date: 星期六, 26 七月 2025 15:48:48 +0800
Subject: [PATCH] ID1825-定时任务禁止修改

---
 src/utils/utils.ts |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/src/utils/utils.ts b/src/utils/utils.ts
new file mode 100644
index 0000000..deeee91
--- /dev/null
+++ b/src/utils/utils.ts
@@ -0,0 +1,51 @@
+/**
+ * 计算某个类名元素的可用高度(视口高度 - 元素顶部距离)
+ * @param className 元素类名(不带.)
+ * @returns 可用高度(px),找不到元素则返回 0
+ */
+export function getAvailableHeightByClass(className: string): number {
+  const el = document.querySelector(`.${className}`) as HTMLElement | null
+  if (!el) return 0
+  const rect = el.getBoundingClientRect()
+  return window.innerHeight - rect.top
+}
+
+/**
+ * 将字符串转为数字
+ * @param value 
+ * @returns 
+ */
+export function tryConvertToInt(value: string): string | number {
+  const num = Number(value);
+  // 判断是否是有效数字且是整数(小数部分为 0)
+  if (!isNaN(num) && Number.isInteger(num)) {
+    return num;
+  }
+
+  // 判断是否是有效数字且小数部分为 0(例如 "1.0")
+  if (!isNaN(num) && Number(value).toString().endsWith('.0')) {
+    return parseInt(value, 10);
+  }
+
+  return value;
+}
+/**
+ * 深拷贝
+ * @param obj 
+ * @returns 
+ */
+export function deepClone<T>(obj: T): T {
+  if (obj === null || typeof obj !== "object") return obj;
+
+  if (Array.isArray(obj)) {
+    return obj.map(item => deepClone(item)) as unknown as T;
+  }
+
+  const result: any = {};
+  for (const key in obj) {
+    if (Object.prototype.hasOwnProperty.call(obj, key)) {
+      result[key] = deepClone(obj[key]);
+    }
+  }
+  return result;
+}

--
Gitblit v1.8.0