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

fix: 精度问题处理

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