lex-xin 3 bulan lalu
induk
melakukan
6ec458daea
1 mengubah file dengan 31 tambahan dan 16 penghapusan
  1. 31 16
      src/helpers/utils.ts

+ 31 - 16
src/helpers/utils.ts

@@ -35,8 +35,8 @@ export function vaildPPTUrl() {
 }
 
 export const getHttpOrigin = () => {
-	return window.location.origin
-}
+  return window.location.origin;
+};
 
 export const browser = () => {
   // https://blog.csdn.net/qq_19309473/article/details/124138954
@@ -488,22 +488,26 @@ export const stackInstruments: any = {
  * @returns
  */
 export const getInstrumentName = (instruments: any, instrumentName: string) => {
-  const _instrumentName = instrumentName.replace(/ /g, '').toLocaleLowerCase()
-  const _instrument = Object.keys(instruments)
+  const _instrumentName = instrumentName
+    .replace(/ /g, '')
+    .replace(/\d+|\d+/g, '')
+    .trim()
+    .toLocaleLowerCase();
+  const _instrument = Object.keys(instruments);
   for (let i = 0; i < _instrument.length; i++) {
-    const _name = _instrument[i].replace(/ /g, '').toLocaleLowerCase()
+    const _name = _instrument[i].replace(/ /g, '').toLocaleLowerCase();
     if (_name === _instrumentName) {
-      return instruments[_instrument[i]] || ''
+      return instruments[_instrument[i]] || '';
     }
   }
   for (let i = 0; i < _instrument.length; i++) {
-    const _name = _instrument[i].replace(/ /g, '').toLocaleLowerCase()
+    const _name = _instrument[i].replace(/ /g, '').toLocaleLowerCase();
     if (_name.includes(_instrumentName)) {
-      return instruments[_instrument[i]] || ''
+      return instruments[_instrument[i]] || '';
     }
   }
-  return ''
-}
+  return '';
+};
 
 /**
  * 乐器排序
@@ -650,7 +654,18 @@ export function chunkArray(array: any[], size: number) {
 
 // 转换数字为中文数字
 export const convertToChineseNumber = (num: number) => {
-  const chineseNumerals = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
+  const chineseNumerals = [
+    '零',
+    '一',
+    '二',
+    '三',
+    '四',
+    '五',
+    '六',
+    '七',
+    '八',
+    '九'
+  ];
   const chineseUnits = ['', '十', '百', '千', '万', '十', '百', '千', '亿'];
 
   // 特殊处理0
@@ -663,14 +678,14 @@ export const convertToChineseNumber = (num: number) => {
 
   // 处理数字的每一位
   while (num > 0) {
-    const digit = num % 10;  // 取出最后一位数字
+    const digit = num % 10; // 取出最后一位数字
     if (digit !== 0) {
-      result = chineseNumerals[digit] + chineseUnits[unitPos] + result;  // 数字加上相应单位
+      result = chineseNumerals[digit] + chineseUnits[unitPos] + result; // 数字加上相应单位
     } else if (result && result.charAt(0) !== chineseNumerals[0]) {
-      result = chineseNumerals[0] + result;  // 处理中间的零
+      result = chineseNumerals[0] + result; // 处理中间的零
     }
 
-    num = Math.floor(num / 10);  // 移除最后一位数字
+    num = Math.floor(num / 10); // 移除最后一位数字
     unitPos++;
   }
 
@@ -680,4 +695,4 @@ export const convertToChineseNumber = (num: number) => {
   }
 
   return result;
-}
+};