From 55bf797dcc730b37bc691ebab2b51ff9db8ed245 Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周二, 06 5月 2025 17:37:23 +0800
Subject: [PATCH] 修改代码样式

---
 HIAWms/web/src/utils/index.ts |  162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/HIAWms/web/src/utils/index.ts b/HIAWms/web/src/utils/index.ts
new file mode 100644
index 0000000..67d42e2
--- /dev/null
+++ b/HIAWms/web/src/utils/index.ts
@@ -0,0 +1,162 @@
+// 宸ュ叿绫诲嚱鏁�
+
+// 闅忔満id
+function createRandomId(): string {
+  return (
+    (Math.random() * 10000000).toString(16).substr(0, 4) +
+    new Date().getTime() +
+    Math.random().toString().substr(2, 5)
+  )
+}
+
+// 闅忔満鏁�
+function randomNumber(min = 1, max = 100) {
+  return parseInt(Math.random() * (max - min + 1) + min.toString())
+}
+
+function getTableHeight(num?: number | undefined) {
+  const pageHeight = window.innerHeight
+  const height = num ? num / 100 : 0.81
+  const heightPx = Math.floor(pageHeight * height)
+
+  return heightPx
+}
+
+// 鏄惁鏁板瓧
+function isNumber(val: string | number): boolean {
+  // 涓嶈兘杞崲涓烘暟瀛楃殑鐩存帴鎶涘嚭
+  if (isNaN(Number(val))) return false
+
+  // 鍘婚櫎鎵�鏈夌┖鏍硷紝浠�涔堥兘娌℃湁
+  const val1 = val.toString().replace(/\s+/g, '')
+  if (!val1) return false
+
+  // 灏忔暟鐐瑰悗锛屼粈涔堥兘娌℃湁
+  const val2 = val.toString().split('.')
+  if (val2.length >= 2) {
+    if (!val2[1]) return false
+  }
+
+  return true
+}
+
+// 鑷�傚簲鍒嗚鲸鐜�
+function adaptiveResolution() {
+  // 鑾峰彇灞忓箷瀹姐�侀珮
+  // bodyW = document.body.clientWidth,
+  // bodyH = document.body.clientHeight,
+  var bodyW = window.innerWidth
+  var bodyH = window.innerHeight
+  // var bodyW = window.screen.width;
+  // var bodyH = window.screen.height;
+
+  var appBodyWRatio = bodyW / 1920 // 灞忓箷瀹� 涓� 璁惧畾鐨勬渶灏忓搴� 鐨勬瘮鍊�
+  var appBodyHRatio = bodyH / 1080 // 灞忓箷瀹� 涓� 璁惧畾鐨勬渶灏忓搴� 鐨勬瘮鍊�
+  // var appEle = document.getElementById('app') // #app
+  var appEle = document.body // body
+  appEle.style.position = 'relative'
+  // console.log('appBodyWRatio == ', appBodyWRatio, 'appBodyHRatio == ', appBodyHRatio)
+  if (appBodyWRatio <= 1 || appBodyHRatio <= 1) {
+    // 姣斿�煎皬浜�1鏃讹紝闇�瑕佸鐞�
+    var appH = bodyH / appBodyHRatio // 閲嶆柊璁剧疆椤甸潰楂樺害
+    var appW = bodyW / appBodyWRatio // 閲嶆柊璁剧疆椤甸潰楂樺害
+    // var positionBase = (1 - appBodyRatio) / 2 * 100 + 9; // 閲嶆柊璁剧疆浣嶇Щ鍊�
+    // var positionLeft = (1920 - bodyW) / 2; // 閲嶆柊璁剧疆left浣嶇Щ鍊�
+    var positionRight = (appH - bodyH) / 2 // 閲嶆柊璁剧疆left浣嶇Щ鍊�
+    // var positionRight = (appH - bodyH) / 2; // 閲嶆柊璁剧疆right浣嶇Щ鍊�
+    var positionLeft = (appW - bodyW) / 2 // 閲嶆柊璁剧疆right浣嶇Щ鍊�
+    // appEle.style.width = "1920px";
+    appEle.style.width = appW + 'px'
+    appEle.style.height = appH + 'px'
+    // appEle.style.height = "1080px";
+    appEle.style.transform =
+      'scale(' + appBodyWRatio + ', ' + appBodyHRatio + ')'
+    appEle.style.left = -positionLeft + 'px'
+    appEle.style.top = -positionRight + 'px'
+  } else {
+    appEle.style.width = '100%'
+    appEle.style.height = '100%'
+    appEle.style.transform = ''
+    appEle.style.position = '0'
+    appEle.style.top = '0'
+  }
+}
+
+function generateUniqueId() {
+  let id = ''
+  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
+  const charactersLength = characters.length
+  for (let i = 0; i < 10; i++) {
+    id += characters.charAt(Math.floor(Math.random() * charactersLength))
+  }
+  return id
+}
+
+// @ts-ignore
+function downloadFile(file, fileName) {
+  const blob = new Blob([file])
+  // 鍏煎涓嶅悓娴忚鍣ㄧ殑URL瀵硅薄
+  // const url:any = window.URL || window.webkitURL || window.moxURL
+  const url = window.URL || window.webkitURL
+  // 鍒涘缓涓嬭浇閾炬帴
+  const downloadHref = url.createObjectURL(blob)
+  // 鍒涘缓a鏍囩骞朵负鍏舵坊鍔犲睘鎬�
+  let downloadLink = document.createElement('a')
+  downloadLink.href = downloadHref
+  downloadLink.download = fileName
+  // 瑙﹀彂鐐瑰嚮浜嬩欢鎵ц涓嬭浇
+  downloadLink.click()
+  // @ts-ignore
+  window.URL.revokeObjectURL(url)
+}
+
+/**
+ * 灏唌ap杞崲鎴愭暟缁刲ist
+ * @param map
+ */
+function genMapToArrayList(map: Record<string, any>): any[] {
+  const list: any[] = []
+  for (const key in map) {
+    if (map.hasOwnProperty(key)) {
+      list.push(map[key])
+    }
+  }
+  return list
+}
+
+/**
+ * 灏哰{description: 'xx', value: 1}]杞垚鎴怺{label: 'xx',value: 1}]
+ */
+export function transformOptions(data: any): any[] {
+  return data.map((item: any) => {
+    return {
+      label: item.description,
+      value: item.value,
+      name: item.name,
+    }
+  })
+}
+
+/**
+ * 鍒ゆ柇鏁扮粍鐨勬煇涓瓧娈垫槸鍚︽湁閲嶅椤�
+ * @param array 鏁扮粍婧�
+ * @param property 闇�瑕佸垽鏂暟缁勪腑瀵硅薄鐨勫瓧娈靛悕
+ * @returns boolean
+ */
+const hasDuplicates = (array: any[], property: string) => {
+  var values = array.map((element) => element[property])
+  var uniqueValues = new Set(values)
+  return values.length !== uniqueValues.size
+}
+
+export {
+  hasDuplicates,
+  genMapToArrayList,
+  createRandomId,
+  randomNumber,
+  isNumber,
+  adaptiveResolution,
+  getTableHeight,
+  generateUniqueId,
+  downloadFile,
+}

--
Gitblit v1.9.3