From f56e474c81bb25845b46cf99c85bd313dbfcd3b5 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期六, 31 一月 2026 19:26:25 +0800
Subject: [PATCH] 项目初始化+首页+公告详情页面

---
 src/utils/tool.js |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/src/utils/tool.js b/src/utils/tool.js
new file mode 100644
index 0000000..9826791
--- /dev/null
+++ b/src/utils/tool.js
@@ -0,0 +1,85 @@
+import { useOptionItemsStore } from '@/stores/optionItems.js';
+/**
+ * 鑾峰彇 assets/images 鐩綍涓嬬殑鍥剧墖URL
+ * @param {string} imageName - 鍥剧墖鏂囦欢鍚嶏紙鍖呭惈鎵╁睍鍚嶏級
+ * @returns {string} 鍥剧墖鐨勫畬鏁碪RL
+ */
+export const getImageUrl = (imageName) => {
+  try {
+    return new URL('../assets/images/' + imageName, import.meta.url).href;
+  } catch (error) {
+    console.warn(`Failed to load image: ${imageName}`, error);
+    return "";
+  }
+};
+export const getUUID = () => {
+  let s = []
+  let num10 = 0x10
+  let num3 = 0x3
+  let num8 = 0x8
+  let hexDigits = '0123456789abcdef'
+  for (let i = 0; i < 36; i++) {
+    s[i] = hexDigits.substr(Math.floor(Math.random() * num10), 1)
+  }
+  s[14] = '4'
+  s[19] = hexDigits.substr((s[19] & num3) | num8, 1)
+  s[8] = s[13] = s[18] = s[23] = ''
+
+  return s.join('')
+}
+export const getDictData = (key) => {
+  let list = JSON.parse(localStorage.getItem('dictData')) || []
+  return list.filter(ele => ele.dictType == key)
+}
+
+/**
+ * 闃叉姈鍑芥暟
+ * @param {Function} func - 闇�瑕侀槻鎶栫殑鍑芥暟
+ * @param {number} delay - 寤惰繜鏃堕棿锛堟绉掞級锛岄粯璁� 300ms
+ * @param {boolean} immediate - 鏄惁绔嬪嵆鎵ц锛岄粯璁� false
+ * @returns {Function} 闃叉姈鍚庣殑鍑芥暟
+ */
+export const debounce = (func, delay = 300, immediate = false) => {
+  let timer = null
+  let isImmediateExecuted = false
+
+  return function (...args) {
+    const context = this
+
+    if (timer) {
+      clearTimeout(timer)
+      timer = null
+    }
+
+    if (immediate && !isImmediateExecuted) {
+      func.apply(context, args)
+      isImmediateExecuted = true
+    }
+
+    timer = setTimeout(() => {
+      if (!immediate) {
+        func.apply(context, args)
+      }
+      isImmediateExecuted = false
+      timer = null
+    }, delay)
+  }
+}
+
+export const getOccupationName = (code) => {
+  const { occupationItems } = useOptionItemsStore()
+  const obj = occupationItems.find(ele => ele.code == code)
+  
+  return obj?.name || ''
+}
+
+export const getJobName = (occupationCode, jobCode) => {
+  const { occupationItems } = useOptionItemsStore()
+  const occupation = occupationItems.find(ele => ele.code == occupationCode)
+  if (!occupation) return ''
+  
+  const job = occupation.jobs?.find(ele => ele.jobCode == jobCode)
+  if (!job) return ''
+
+  return job.jobName || ''
+}
\ No newline at end of file

--
Gitblit v1.8.0