wwf
4 天以前 f56e474c81bb25845b46cf99c85bd313dbfcd3b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useOptionItemsStore } from '@/stores/optionItems.js';
/**
 * 获取 assets/images 目录下的图片URL
 * @param {string} imageName - 图片文件名(包含扩展名)
 * @returns {string} 图片的完整URL
 */
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 || ''
}