浏览代码

feat: 加载优化

TIANYONG 3 月之前
父节点
当前提交
29b969a38b
共有 3 个文件被更改,包括 13 次插入12 次删除
  1. 2 2
      src/helpers/calcSpeed.ts
  2. 9 8
      src/helpers/formateMusic.ts
  3. 2 2
      src/state.ts

+ 2 - 2
src/helpers/calcSpeed.ts

@@ -117,9 +117,9 @@ export type GradualItem = {
  */
 export const getGradualLengthByXml = (xml: string) => {
 	const firstPartXml = onlyVisible(xml, 0, 'calc')
-	console.time('解析xml 耗时2')
+	//console.time('解析xml 耗时2')
 	const xmlParse = new DOMParser().parseFromString(firstPartXml, "text/xml");
-	console.timeEnd('解析xml 耗时2')
+	//console.timeEnd('解析xml 耗时2')
 	const measures = Array.from(xmlParse.querySelectorAll("measure"));
 	const notes = Array.from(xmlParse.querySelectorAll("note"));
 	const words = Array.from(xmlParse.querySelectorAll("words"));

+ 9 - 8
src/helpers/formateMusic.ts

@@ -252,10 +252,10 @@ export const getCustomInfo = (xml: string): CustomInfo => {
 		showSpeed: true,
 		parsedXML: xml,
 	};
-	console.time('解析xml 耗时3')
+	//console.time('解析xml 耗时3')
 	// const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
 	const xmlParse = xmlDocRef.value ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
-	console.timeEnd('解析xml 耗时3')
+	//console.timeEnd('解析xml 耗时3')
 	const words: any = xmlParse?.getElementsByTagName("words");
 	for (const word of words) {
 		if (word && word.textContent?.trim() === "隐藏速度") {
@@ -365,10 +365,10 @@ export const onlyVisible = (xml: string, partIndex: number, resourceType?: strin
 	if (!xml) return "";
 	// console.log('原始xml')
 	const detailId = state.examSongId + "";
-	console.time('解析xml 耗时4')
+	//console.time('解析xml 耗时4')
 	// const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
 	const xmlParse = xmlDocRef.value ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
-	console.timeEnd('解析xml 耗时4')
+	//console.timeEnd('解析xml 耗时4')
 	const partList = xmlParse.getElementsByTagName("part-list")?.[0]?.getElementsByTagName("score-part") || [];
 	const partListNames = Array.from(partList).map((item) => item.getElementsByTagName("part-name")?.[0]?.textContent?.trim() || "");
 	const parts: any = xmlParse.getElementsByTagName("part");
@@ -634,9 +634,9 @@ export const formatZoom = (num = 1) => {
 /** 妙极客多分轨的曲子,可能没有part-name标签,需要手动加上该标签 */
 export const xmlAddPartName = (xml: string) => {
 	if (!xml) return "";
-	console.time('解析xml 耗时6')
+	console.time('解析xml 耗时')
 	const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
-	console.timeEnd('解析xml 耗时6')
+	console.timeEnd('解析xml 耗时')
 	const scoreParts = Array.from(xmlParse.getElementsByTagName("score-part"));
 	for (const scorePart of scoreParts) {
 		if (scorePart.getElementsByTagName("part-name").length === 0) {
@@ -659,10 +659,10 @@ export const xmlAddPartName = (xml: string) => {
  */
 export const formatXML = (xml: string, xmlUrl?: string): string => {
 	if (!xml) return "";
-	console.time('解析xml 耗时7')
+	//console.time('解析xml 耗时7')
 	// const xmlParse = new DOMParser().parseFromString(xml, "text/xml");
 	const xmlParse = xmlDocRef.value ? xmlDocRef.value : new DOMParser().parseFromString(xml, "text/xml");
-	console.timeEnd('解析xml 耗时7')
+	//console.timeEnd('解析xml 耗时7')
 	// 声调
 	const fifths = xmlParse.getElementsByTagName("fifths");
 	if (fifths && fifths.length) {
@@ -818,6 +818,7 @@ export const formatXML = (xml: string, xmlUrl?: string): string => {
 			transferJianNote(measure, divisions, preBeats, preBeatType)
 		}
 	}
+	xmlDocRef.value = xmlParse;
 	return new XMLSerializer().serializeToString(xmlParse);
 };
 

+ 2 - 2
src/state.ts

@@ -1557,10 +1557,10 @@ const getMusicInfo = async (res: any) => {
 //获取xml中的音轨数据
 function xmlToTracks(xmlString: string) {
   //console.time('domparse')
-  console.time('解析xml 耗时1')
+  // console.time('解析xml 耗时1')
   // const xmlParse = new DOMParser().parseFromString(xmlString, "text/xml");
   const xmlParse = xmlDocRef.value;
-  console.timeEnd('解析xml 耗时1')
+  // console.timeEnd('解析xml 耗时1')
   //console.timeEnd('domparse')
   const partNames = xmlParse ? Array.from(xmlParse.getElementsByTagName('part-name')) : [];
   return partNames.reduce((arr: string[], item) => {