|
@@ -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
|
|
@@ -481,20 +481,29 @@ export const stackInstruments: any = {
|
|
|
Cymbals: '镲'
|
|
|
};
|
|
|
|
|
|
-/** 获取分轨名称 */
|
|
|
-export const getInstrumentName = (instruments: any, name = '') => {
|
|
|
- name = name.toLocaleLowerCase().replace(/ /g, '');
|
|
|
- if (!name) return '';
|
|
|
- for (let key in instruments) {
|
|
|
- const _key = key.toLocaleLowerCase().replace(/ /g, '');
|
|
|
- if (_key.includes(name)) {
|
|
|
- return instruments[key];
|
|
|
+/**
|
|
|
+ * 获取乐器名称
|
|
|
+ * @param instruments 乐器列表
|
|
|
+ * @param instrumentName 乐器code
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export const getInstrumentName = (instruments: any, instrumentName: string) => {
|
|
|
+ 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();
|
|
|
+ if (_name === _instrumentName) {
|
|
|
+ return instruments[_instrument[i]] || '';
|
|
|
}
|
|
|
}
|
|
|
- for (let key in instruments) {
|
|
|
- const _key = key.toLocaleLowerCase().replace(/ /g, '');
|
|
|
- if (name.includes(_key)) {
|
|
|
- return instruments[key];
|
|
|
+ for (let i = 0; i < _instrument.length; i++) {
|
|
|
+ const _name = _instrument[i].replace(/ /g, '').toLocaleLowerCase();
|
|
|
+ if (_name.includes(_instrumentName)) {
|
|
|
+ return instruments[_instrument[i]] || '';
|
|
|
}
|
|
|
}
|
|
|
return '';
|
|
@@ -645,7 +654,18 @@ export function chunkArray(array: any[], size: number) {
|
|
|
|
|
|
// 转换数字为中文数字
|
|
|
export const convertToChineseNumber = (num: number) => {
|
|
|
- const chineseNumerals = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
|
+ const chineseNumerals = [
|
|
|
+ '零',
|
|
|
+ '一',
|
|
|
+ '二',
|
|
|
+ '三',
|
|
|
+ '四',
|
|
|
+ '五',
|
|
|
+ '六',
|
|
|
+ '七',
|
|
|
+ '八',
|
|
|
+ '九'
|
|
|
+ ];
|
|
|
const chineseUnits = ['', '十', '百', '千', '万', '十', '百', '千', '亿'];
|
|
|
|
|
|
// 特殊处理0
|
|
@@ -658,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++;
|
|
|
}
|
|
|
|
|
@@ -675,4 +695,4 @@ export const convertToChineseNumber = (num: number) => {
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
-}
|
|
|
+};
|