瀏覽代碼

时间计算修改

wolyshaw 2 年之前
父節點
當前提交
d5374b6096
共有 1 個文件被更改,包括 39 次插入13 次删除
  1. 39 13
      src/views/accompaniment/modals/form.vue

+ 39 - 13
src/views/accompaniment/modals/form.vue

@@ -265,7 +265,8 @@
             gradual.length
           }}处渐变速度,请输入Dorico对应小节时间信息</el-alert
         >
-        <div v-for="(item,index) in gradual" :key="index">
+        <div class="gradual-item" v-for="(item,index) in gradual" :key="index">
+          {{item[0].type}}
           <el-form-item
             :label="item[0].measureIndex + 2 + ' 小节'"
             :rules="[
@@ -519,6 +520,7 @@ export default {
       this.gradual = getGradualLengthByXml(xmlres.data).filter(
         (item) => item.length === 2
       );
+      console.log(this.gradual)
       this.partListNames = this.getPartListNames(xmlres.data);
       this.FeatchDetailList();
     } else {
@@ -936,26 +938,32 @@ export function getGradualLengthByXml(xml) {
     }
   }
 
+  // 结尾处手动插入一个音符节点
+  eles.push({
+    ele: notes[notes.length - 1],
+    index: notes.length,
+    noteInMeasureIndex: 0,
+    textContent: '',
+    type: 'metronome',
+    allDuration: 1,
+    leftDuration: 1,
+    measureIndex: measures.length,
+  })
+
   const gradualNotes = [];
   eles.sort((a, b) => a.index - b.index);
   const keys = Object.keys(speedInfo).map((w) => w.toLocaleLowerCase());
+  let isLastNoteAndNotClosed = false;
   for (const ele of eles) {
     const textContent = ele.textContent?.toLocaleLowerCase().trim();
-    if (ele.type === "words" && keys.includes(textContent)) {
-      gradualNotes.push([
-        {
-          start: ele.index,
-          measureIndex: ele.measureIndex,
-          noteInMeasureIndex: ele.noteInMeasureIndex,
-          allDuration: ele.allDuration,
-          leftDuration: ele.leftDuration,
-          type: textContent,
-        },
-      ]);
+    if (ele === eles[eles.length - 1]) {
+      if (gradualNotes[gradualNotes.length - 1]?.length === 1) {
+        isLastNoteAndNotClosed = true;
+      }
     }
     if (
       ele.type === "metronome" ||
-      (ele.type === "words" && textContent === "a tempo")
+      (ele.type === "words" && (textContent === "a tempo" || keys.includes(textContent)) || isLastNoteAndNotClosed)
     ) {
       const indexOf = gradualNotes.findIndex((item) => item.length === 1);
       if (indexOf > -1 && ele.index > gradualNotes[indexOf]?.[0].start) {
@@ -969,6 +977,18 @@ export function getGradualLengthByXml(xml) {
         };
       }
     }
+    if (ele.type === "words" && keys.includes(textContent)) {
+      gradualNotes.push([
+        {
+          start: ele.index,
+          measureIndex: ele.measureIndex,
+          noteInMeasureIndex: ele.noteInMeasureIndex,
+          allDuration: ele.allDuration,
+          leftDuration: ele.leftDuration,
+          type: textContent,
+        },
+      ]);
+    }
   }
   return gradualNotes;
 }
@@ -990,4 +1010,10 @@ export function getGradualLengthByXml(xml) {
     bottom: 10px;
   }
 }
+.gradual-item{
+  background-color: #f8f8f8;
+  margin-bottom: 10px;
+  padding: 10px;
+  border-radius: 6px;
+}
 </style>