Commit 04f2dc2a authored by Jeff nan's avatar Jeff nan

fix: 精度问题处理

parent 31f3de74
...@@ -860,6 +860,12 @@ function initVueApp(savedData) { ...@@ -860,6 +860,12 @@ function initVueApp(savedData) {
}; };
}, },
// 写回时间:保留原字段类型(number/string、秒/毫秒/时码),但小数位强制 3 位(毫秒精度)
timeWriteFormat(sampleItem) {
const base = this.detectTimeFormatFromArray([sampleItem || {}]);
return Object.assign({}, base, { decimals: 3 });
},
// 校验并确认时间编辑 // 校验并确认时间编辑
confirmTimeEdit() { confirmTimeEdit() {
const d = this.timeEditDialog; const d = this.timeEditDialog;
...@@ -922,8 +928,7 @@ function initVueApp(savedData) { ...@@ -922,8 +928,7 @@ function initVueApp(savedData) {
if (d.type === 'sentence-start') { if (d.type === 'sentence-start') {
item.start = display; item.start = display;
if (words[0]) { if (words[0]) {
const fmt = this.detectTimeFormatFromArray([words[0]]); this.$set(words[0], 'start', this.serializeTimeByFormat(total, this.timeWriteFormat(words[0])));
this.$set(words[0], 'start', this.serializeTimeByFormat(total, fmt));
} }
} else if (d.type === 'sentence-end') { } else if (d.type === 'sentence-end') {
// 句子 end ↔ 末词 end ↔ 翻译末段 end 保持一致 // 句子 end ↔ 末词 end ↔ 翻译末段 end 保持一致
...@@ -935,8 +940,7 @@ function initVueApp(savedData) { ...@@ -935,8 +940,7 @@ function initVueApp(savedData) {
this.$message.error('目标分词不存在'); this.$message.error('目标分词不存在');
return; return;
} }
const fmt = this.detectTimeFormatFromArray([word]); this.$set(word, 'start', this.serializeTimeByFormat(total, this.timeWriteFormat(word)));
this.$set(word, 'start', this.serializeTimeByFormat(total, fmt));
if (d.wordIndex === 0) item.start = display; if (d.wordIndex === 0) item.start = display;
} else if (d.type === 'word-end') { } else if (d.type === 'word-end') {
const word = words[d.wordIndex]; const word = words[d.wordIndex];
...@@ -944,8 +948,7 @@ function initVueApp(savedData) { ...@@ -944,8 +948,7 @@ function initVueApp(savedData) {
this.$message.error('目标分词不存在'); this.$message.error('目标分词不存在');
return; return;
} }
const fmt = this.detectTimeFormatFromArray([word]); this.$set(word, 'end', this.serializeTimeByFormat(total, this.timeWriteFormat(word)));
this.$set(word, 'end', this.serializeTimeByFormat(total, fmt));
// 改的是最后一个单词:同步句子 end + 翻译末段 end // 改的是最后一个单词:同步句子 end + 翻译末段 end
if (d.wordIndex === words.length - 1) { if (d.wordIndex === words.length - 1) {
item.end = display; item.end = display;
...@@ -969,8 +972,7 @@ function initVueApp(savedData) { ...@@ -969,8 +972,7 @@ function initVueApp(savedData) {
if (!skipWords && words.length) { if (!skipWords && words.length) {
const last = words[words.length - 1]; const last = words[words.length - 1];
if (last) { if (last) {
const fmt = this.detectTimeFormatFromArray([last]); this.$set(last, 'end', this.serializeTimeByFormat(endSec, this.timeWriteFormat(last)));
this.$set(last, 'end', this.serializeTimeByFormat(endSec, fmt));
} }
} }
if (!skipTranslated) { if (!skipTranslated) {
...@@ -978,8 +980,7 @@ function initVueApp(savedData) { ...@@ -978,8 +980,7 @@ function initVueApp(savedData) {
if (tSegs.length) { if (tSegs.length) {
const lastT = tSegs[tSegs.length - 1]; const lastT = tSegs[tSegs.length - 1];
if (lastT) { if (lastT) {
const fmtT = this.detectTimeFormatFromArray([lastT]); this.$set(lastT, 'end', this.serializeTimeByFormat(endSec, this.timeWriteFormat(lastT)));
this.$set(lastT, 'end', this.serializeTimeByFormat(endSec, fmtT));
} }
} }
} }
...@@ -1029,9 +1030,8 @@ function initVueApp(savedData) { ...@@ -1029,9 +1030,8 @@ function initVueApp(savedData) {
if (!lastWord) return; if (!lastWord) return;
const wordEndSec = this.parseTimeToSeconds(lastWord.end); const wordEndSec = this.parseTimeToSeconds(lastWord.end);
if (!isNaN(wordEndSec) && Math.abs(wordEndSec - sentenceEndSec) < 0.001) return; if (!isNaN(wordEndSec) && Math.abs(wordEndSec - sentenceEndSec) < 0.001) return;
const fmtSample = (lastWord.end != null || lastWord.start != null) ? [lastWord] : [s]; const fmtSample = (lastWord.end != null || lastWord.start != null) ? lastWord : s;
const fmt = this.detectTimeFormatFromArray(fmtSample); lastWord.end = this.serializeTimeByFormat(sentenceEndSec, this.timeWriteFormat(fmtSample));
lastWord.end = this.serializeTimeByFormat(sentenceEndSec, fmt);
fixed += 1; fixed += 1;
}); });
if (fixed > 0) { if (fixed > 0) {
...@@ -1429,16 +1429,14 @@ function initVueApp(savedData) { ...@@ -1429,16 +1429,14 @@ function initVueApp(savedData) {
if (!isNaN(sEndSec)) { if (!isNaN(sEndSec)) {
if (sWords.length) { if (sWords.length) {
const last = sWords[sWords.length - 1]; const last = sWords[sWords.length - 1];
const fmt = this.detectTimeFormatFromArray([last]);
sWords[sWords.length - 1] = Object.assign({}, last, { sWords[sWords.length - 1] = Object.assign({}, last, {
end: this.serializeTimeByFormat(sEndSec, fmt), end: this.serializeTimeByFormat(sEndSec, this.timeWriteFormat(last)),
}); });
} }
if (tSegs.length) { if (tSegs.length) {
const lastT = tSegs[tSegs.length - 1]; const lastT = tSegs[tSegs.length - 1];
const fmtT = this.detectTimeFormatFromArray([lastT]);
tSegs[tSegs.length - 1] = Object.assign({}, lastT, { tSegs[tSegs.length - 1] = Object.assign({}, lastT, {
end: this.serializeTimeByFormat(sEndSec, fmtT), end: this.serializeTimeByFormat(sEndSec, this.timeWriteFormat(lastT)),
}); });
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment