Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
ai_fundub
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
ai_fundub
Commits
e24a3855
Commit
e24a3855
authored
Jul 27, 2026
by
Jeff nan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加时间的微调编辑
parent
18a303ab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
434 additions
and
26 deletions
+434
-26
index.css
form/index.css
+38
-0
index.html
form/index.html
+80
-5
index.js
form/index.js
+316
-21
No files found.
form/index.css
View file @
e24a3855
...
@@ -297,6 +297,44 @@
...
@@ -297,6 +297,44 @@
background
:
#66b1ff
;
background
:
#66b1ff
;
}
}
/* 时间编辑入口 */
.time-edit-line
{
display
:
inline-flex
;
align-items
:
center
;
gap
:
4px
;
}
.time-edit-icon
{
color
:
#409eff
;
cursor
:
pointer
;
font-size
:
13px
;
margin-left
:
2px
;
}
.time-edit-icon
:hover
{
color
:
#66b1ff
;
}
/* 时间编辑弹窗 */
.time-edit-form
.time-edit-hint
{
color
:
#909399
;
font-size
:
12px
;
margin-bottom
:
14px
;
line-height
:
1.5
;
}
.time-edit-inputs
{
display
:
flex
;
gap
:
12px
;
}
.time-edit-field
{
flex
:
1
;
min-width
:
0
;
}
.time-edit-field
label
{
display
:
block
;
margin-bottom
:
6px
;
color
:
#606266
;
font-size
:
13px
;
}
/* 卡片悬停效果 */
/* 卡片悬停效果 */
.upload-section
,
.upload-section
,
.video-section
,
.video-section
,
...
...
form/index.html
View file @
e24a3855
...
@@ -241,7 +241,21 @@
...
@@ -241,7 +241,21 @@
<div
style=
"display:flex; align-items:center; color:#909399; font-size:12px; margin-bottom:4px;"
>
<div
style=
"display:flex; align-items:center; color:#909399; font-size:12px; margin-bottom:4px;"
>
<div
style=
"display:flex; align-items:center; gap:8px;"
>
<div
style=
"display:flex; align-items:center; gap:8px;"
>
<span>
#{{ item.index }}
</span>
<span>
#{{ item.index }}
</span>
<span>
{{ item.start }} - {{ item.end }}
</span>
<span
class=
"time-edit-line"
>
<span>
{{ item.start }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑开始时间"
@
click=
"openTimeEdit({ type: 'sentence-start', tlIndex: idx })"
></i>
<span>
-
</span>
<span>
{{ item.end }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑结束时间"
@
click=
"openTimeEdit({ type: 'sentence-end', tlIndex: idx })"
></i>
</span>
<el-button
<el-button
v-if=
"idx > 0"
v-if=
"idx > 0"
size=
"mini"
size=
"mini"
...
@@ -274,10 +288,17 @@
...
@@ -274,10 +288,17 @@
@
cell-mouse-enter=
"(row, column, cell, event) => onSWordsCellEnter(idx, row, column, cell, event)"
@
cell-mouse-enter=
"(row, column, cell, event) => onSWordsCellEnter(idx, row, column, cell, event)"
@
cell-mouse-leave=
"(row, column, cell, event) => onSWordsCellLeave(idx, row, column, cell, event)"
@
cell-mouse-leave=
"(row, column, cell, event) => onSWordsCellLeave(idx, row, column, cell, event)"
>
>
<el-table-column
label=
"start"
width=
"
9
0"
>
<el-table-column
label=
"start"
width=
"
13
0"
>
<template
slot-scope=
"s"
>
<template
slot-scope=
"s"
>
<div
class=
"swords-start-cell"
>
<div
class=
"swords-start-cell"
>
{{ formatTimeNumeric(s.row.start) }}
<span
class=
"time-edit-line"
>
<span>
{{ formatTimeNumeric(s.row.start) }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑分词开始时间"
@
click=
"openTimeEdit({ type: 'word-start', tlIndex: idx, wordIndex: s.$index })"
></i>
</span>
<el-tooltip
<el-tooltip
v-if=
"item._hoveredSIndex === s.$index && !isAnyTaskRunning() && s.$index < (item.sWordsRef ? item.sWordsRef.length - 1 : 0)"
v-if=
"item._hoveredSIndex === s.$index && !isAnyTaskRunning() && s.$index < (item.sWordsRef ? item.sWordsRef.length - 1 : 0)"
content=
"在此处拆分为两句"
content=
"在此处拆分为两句"
...
@@ -291,9 +312,16 @@
...
@@ -291,9 +312,16 @@
</div>
</div>
</template>
</template>
</el-table-column>
</el-table-column>
<el-table-column
label=
"end"
width=
"
9
0"
>
<el-table-column
label=
"end"
width=
"
13
0"
>
<template
slot-scope=
"s"
>
<template
slot-scope=
"s"
>
{{ formatTimeNumeric(s.row.end) }}
<span
class=
"time-edit-line"
>
<span>
{{ formatTimeNumeric(s.row.end) }}
</span>
<i
class=
"el-icon-edit time-edit-icon"
title=
"编辑分词结束时间"
@
click=
"openTimeEdit({ type: 'word-end', tlIndex: idx, wordIndex: s.$index })"
></i>
</span>
</template>
</template>
</el-table-column>
</el-table-column>
<el-table-column
label=
"word"
>
<el-table-column
label=
"word"
>
...
@@ -333,6 +361,53 @@
...
@@ -333,6 +361,53 @@
</div>
</div>
</div>
</div>
</el-dialog>
</el-dialog>
<!-- 时间编辑弹窗:句子 / 原文分词 共用 -->
<el-dialog
:title=
"timeEditDialog.title"
:visible
.
sync=
"timeEditDialog.visible"
width=
"420px"
append-to-body
:close-on-click-modal=
"false"
custom-class=
"time-edit-dialog"
>
<div
class=
"time-edit-form"
>
<div
v-if=
"timeEditDialog.boundHint"
class=
"time-edit-hint"
>
{{ timeEditDialog.boundHint }}
</div>
<div
class=
"time-edit-inputs"
>
<div
class=
"time-edit-field"
>
<label>
分钟
</label>
<el-input
v-model=
"timeEditDialog.minutes"
size=
"small"
placeholder=
"0"
maxlength=
"6"
></el-input>
</div>
<div
class=
"time-edit-field"
>
<label>
秒
</label>
<el-input
v-model=
"timeEditDialog.seconds"
size=
"small"
placeholder=
"0"
maxlength=
"2"
></el-input>
</div>
<div
class=
"time-edit-field"
>
<label>
毫秒
</label>
<el-input
v-model=
"timeEditDialog.milliseconds"
size=
"small"
placeholder=
"0"
maxlength=
"3"
></el-input>
</div>
</div>
</div>
<span
slot=
"footer"
class=
"dialog-footer"
>
<el-button
size=
"small"
@
click=
"timeEditDialog.visible = false"
>
取消
</el-button>
<el-button
size=
"small"
type=
"primary"
@
click=
"confirmTimeEdit"
>
确定
</el-button>
</span>
</el-dialog>
</div>
</div>
</div>
</div>
</body>
</body>
...
...
form/index.js
View file @
e24a3855
...
@@ -28,13 +28,13 @@ document.addEventListener('DOMContentLoaded', () => {
...
@@ -28,13 +28,13 @@ document.addEventListener('DOMContentLoaded', () => {
window
.
courseware
.
getData
(
function
(
data
)
{
window
.
courseware
.
getData
(
function
(
data
)
{
window
.
air
.
hideAirClassLoading
(
key
,
data
);
window
.
air
.
hideAirClassLoading
(
key
,
data
);
//
if (!data) {
if
(
!
data
)
{
//
// 加载默认数据
// 加载默认数据
//
$.getJSON('../play/defaultData.json', function (defaultData) {
$
.
getJSON
(
'
../play/defaultData.json
'
,
function
(
defaultData
)
{
//
initVueApp(defaultData);
initVueApp
(
defaultData
);
//
})
})
//
return;
return
;
//
}
}
//数据加载完,才算页面加载完成
//数据加载完,才算页面加载完成
initVueApp
(
data
);
initVueApp
(
data
);
},
key
);
},
key
);
...
@@ -79,6 +79,22 @@ function initVueApp(savedData) {
...
@@ -79,6 +79,22 @@ function initVueApp(savedData) {
clearedSIndices
:
[],
clearedSIndices
:
[],
clearedTIndices
:
[]
clearedTIndices
:
[]
},
},
// 时间编辑弹窗(句子 / 分词 共用)
timeEditDialog
:
{
visible
:
false
,
title
:
''
,
type
:
''
,
// sentence-start | sentence-end | word-start | word-end
tlIndex
:
null
,
wordIndex
:
null
,
minutes
:
''
,
seconds
:
''
,
milliseconds
:
''
,
minSec
:
0
,
maxSec
:
Infinity
,
minInclusive
:
true
,
maxInclusive
:
true
,
boundHint
:
''
,
},
},
},
mounted
()
{
mounted
()
{
// 如果有保存的数据,恢复状态
// 如果有保存的数据,恢复状态
...
@@ -684,6 +700,8 @@ function initVueApp(savedData) {
...
@@ -684,6 +700,8 @@ function initVueApp(savedData) {
// 兼容数据根可能不是数组(深度搜索)
// 兼容数据根可能不是数组(深度搜索)
const
subtitleList
=
this
.
extractArrayFromJson
(
subtitleJson
,
'
subtitle
'
);
const
subtitleList
=
this
.
extractArrayFromJson
(
subtitleJson
,
'
subtitle
'
);
const
translatedList
=
this
.
extractArrayFromJson
(
translatedJson
,
'
translated
'
);
const
translatedList
=
this
.
extractArrayFromJson
(
translatedJson
,
'
translated
'
);
// 打开编辑前校准:末词 end 与句子 end 不一致时,以句子 end 为准
this
.
calibrateSubtitleWordEndTimes
(
subtitleList
);
this
.
subtitleEditor
.
subtitleList
=
subtitleList
||
[];
this
.
subtitleEditor
.
subtitleList
=
subtitleList
||
[];
this
.
subtitleEditor
.
translatedList
=
translatedList
||
[];
this
.
subtitleEditor
.
translatedList
=
translatedList
||
[];
this
.
subtitleEditor
.
mergedList
=
this
.
buildMergedList
(
this
.
subtitleEditor
.
subtitleList
,
this
.
subtitleEditor
.
translatedList
);
this
.
subtitleEditor
.
mergedList
=
this
.
buildMergedList
(
this
.
subtitleEditor
.
subtitleList
,
this
.
subtitleEditor
.
translatedList
);
...
@@ -696,6 +714,276 @@ function initVueApp(savedData) {
...
@@ -696,6 +714,276 @@ function initVueApp(savedData) {
}
}
},
},
// 秒数拆成 分/秒/毫秒
secondsToTimeParts
(
sec
)
{
let
s
=
Number
(
sec
);
if
(
isNaN
(
s
)
||
s
<
0
)
s
=
0
;
const
totalMs
=
Math
.
round
(
s
*
1000
);
return
{
minutes
:
Math
.
floor
(
totalMs
/
60000
),
seconds
:
Math
.
floor
((
totalMs
%
60000
)
/
1000
),
milliseconds
:
totalMs
%
1000
,
};
},
// 分/秒/毫秒合成秒数(先按整数毫秒累加,避免浮点误差导致差 1ms)
timePartsToSeconds
(
minutes
,
seconds
,
milliseconds
)
{
const
totalMs
=
Number
(
minutes
)
*
60000
+
Number
(
seconds
)
*
1000
+
Number
(
milliseconds
);
return
totalMs
/
1000
;
},
// 计算时间编辑的合法区间
getTimeEditBounds
(
type
,
tlIndex
,
wordIndex
)
{
const
list
=
this
.
subtitleEditor
.
mergedList
||
[];
const
item
=
list
[
tlIndex
];
if
(
!
item
)
return
null
;
const
prev
=
tlIndex
>
0
?
list
[
tlIndex
-
1
]
:
null
;
const
next
=
tlIndex
<
list
.
length
-
1
?
list
[
tlIndex
+
1
]
:
null
;
const
prevEnd
=
prev
?
this
.
parseTimeToSeconds
(
prev
.
end
)
:
0
;
const
nextStart
=
next
?
this
.
parseTimeToSeconds
(
next
.
start
)
:
Infinity
;
const
itemStart
=
this
.
parseTimeToSeconds
(
item
.
start
);
const
itemEnd
=
this
.
parseTimeToSeconds
(
item
.
end
);
const
words
=
Array
.
isArray
(
item
.
sWordsRef
)
?
item
.
sWordsRef
:
[];
if
(
type
===
'
sentence-start
'
)
{
let
maxSec
=
itemEnd
;
if
(
words
.
length
)
{
const
firstEnd
=
this
.
parseTimeToSeconds
(
words
[
0
].
end
);
if
(
!
isNaN
(
firstEnd
))
maxSec
=
Math
.
min
(
maxSec
,
firstEnd
);
}
return
{
title
:
'
编辑句子开始时间
'
,
currentSec
:
itemStart
,
minSec
:
isNaN
(
prevEnd
)
?
0
:
Math
.
max
(
0
,
prevEnd
),
maxSec
:
isNaN
(
maxSec
)
?
Infinity
:
maxSec
,
minInclusive
:
true
,
maxInclusive
:
false
,
};
}
if
(
type
===
'
sentence-end
'
)
{
let
minSec
=
itemStart
;
if
(
words
.
length
)
{
const
lastStart
=
this
.
parseTimeToSeconds
(
words
[
words
.
length
-
1
].
start
);
if
(
!
isNaN
(
lastStart
))
minSec
=
Math
.
max
(
minSec
,
lastStart
);
}
return
{
title
:
'
编辑句子结束时间
'
,
currentSec
:
itemEnd
,
minSec
:
isNaN
(
minSec
)
?
0
:
minSec
,
maxSec
:
isNaN
(
nextStart
)
?
Infinity
:
nextStart
,
minInclusive
:
false
,
maxInclusive
:
true
,
};
}
if
(
type
===
'
word-start
'
||
type
===
'
word-end
'
)
{
const
word
=
words
[
wordIndex
];
if
(
!
word
)
return
null
;
const
wordStart
=
this
.
parseTimeToSeconds
(
word
.
start
);
const
wordEnd
=
this
.
parseTimeToSeconds
(
word
.
end
);
if
(
type
===
'
word-start
'
)
{
let
minSec
=
0
;
if
(
wordIndex
>
0
)
{
minSec
=
this
.
parseTimeToSeconds
(
words
[
wordIndex
-
1
].
end
);
}
else
{
minSec
=
isNaN
(
prevEnd
)
?
0
:
prevEnd
;
}
return
{
title
:
'
编辑分词开始时间
'
,
currentSec
:
wordStart
,
minSec
:
isNaN
(
minSec
)
?
0
:
Math
.
max
(
0
,
minSec
),
maxSec
:
isNaN
(
wordEnd
)
?
Infinity
:
wordEnd
,
minInclusive
:
true
,
maxInclusive
:
false
,
};
}
// word-end
let
maxSec
=
Infinity
;
if
(
wordIndex
<
words
.
length
-
1
)
{
maxSec
=
this
.
parseTimeToSeconds
(
words
[
wordIndex
+
1
].
start
);
}
else
{
maxSec
=
isNaN
(
nextStart
)
?
Infinity
:
nextStart
;
}
return
{
title
:
'
编辑分词结束时间
'
,
currentSec
:
wordEnd
,
minSec
:
isNaN
(
wordStart
)
?
0
:
wordStart
,
maxSec
:
isNaN
(
maxSec
)
?
Infinity
:
maxSec
,
minInclusive
:
false
,
maxInclusive
:
true
,
};
}
return
null
;
},
formatBoundLabel
(
sec
,
inclusive
,
isMin
)
{
if
(
sec
==
null
||
!
isFinite
(
sec
))
{
return
isMin
?
'
0
'
:
'
无上限
'
;
}
const
t
=
this
.
formatTime
(
Math
.
max
(
0
,
sec
));
if
(
isMin
)
return
inclusive
?
`≥
${
t
}
`
:
`>
${
t
}
`
;
return
inclusive
?
`≤
${
t
}
`
:
`<
${
t
}
`
;
},
// 打开时间编辑弹窗
openTimeEdit
({
type
,
tlIndex
,
wordIndex
=
null
}
=
{})
{
if
(
this
.
isAnyTaskRunning
&&
this
.
isAnyTaskRunning
())
{
this
.
$message
.
warning
(
'
有任务进行中,暂不可编辑时间
'
);
return
;
}
const
bounds
=
this
.
getTimeEditBounds
(
type
,
tlIndex
,
wordIndex
);
if
(
!
bounds
)
{
this
.
$message
.
error
(
'
无法获取时间边界
'
);
return
;
}
const
parts
=
this
.
secondsToTimeParts
(
bounds
.
currentSec
);
const
minLabel
=
this
.
formatBoundLabel
(
bounds
.
minSec
,
bounds
.
minInclusive
,
true
);
const
maxLabel
=
this
.
formatBoundLabel
(
bounds
.
maxSec
,
bounds
.
maxInclusive
,
false
);
this
.
timeEditDialog
=
{
visible
:
true
,
title
:
bounds
.
title
,
type
,
tlIndex
,
wordIndex
,
minutes
:
String
(
parts
.
minutes
),
seconds
:
String
(
parts
.
seconds
),
milliseconds
:
String
(
parts
.
milliseconds
),
minSec
:
bounds
.
minSec
,
maxSec
:
bounds
.
maxSec
,
minInclusive
:
bounds
.
minInclusive
,
maxInclusive
:
bounds
.
maxInclusive
,
boundHint
:
`允许范围:
${
minLabel
}
,
${
maxLabel
}
`
,
};
},
// 校验并确认时间编辑
confirmTimeEdit
()
{
const
d
=
this
.
timeEditDialog
;
const
minStr
=
(
d
.
minutes
==
null
?
''
:
String
(
d
.
minutes
)).
trim
();
const
secStr
=
(
d
.
seconds
==
null
?
''
:
String
(
d
.
seconds
)).
trim
();
const
msStr
=
(
d
.
milliseconds
==
null
?
''
:
String
(
d
.
milliseconds
)).
trim
();
if
(
minStr
===
''
||
secStr
===
''
||
msStr
===
''
)
{
this
.
$message
.
warning
(
'
分钟、秒、毫秒均不能为空
'
);
return
;
}
if
(
!
/^
\d
+$/
.
test
(
minStr
)
||
!
/^
\d
+$/
.
test
(
secStr
)
||
!
/^
\d
+$/
.
test
(
msStr
))
{
this
.
$message
.
warning
(
'
分钟、秒、毫秒必须为非负整数
'
);
return
;
}
const
minutes
=
parseInt
(
minStr
,
10
);
const
seconds
=
parseInt
(
secStr
,
10
);
const
milliseconds
=
parseInt
(
msStr
,
10
);
if
(
minutes
<
0
)
{
this
.
$message
.
warning
(
'
分钟不能小于 0
'
);
return
;
}
if
(
seconds
<
0
||
seconds
>
59
)
{
this
.
$message
.
warning
(
'
秒数需在 0–59 之间
'
);
return
;
}
if
(
milliseconds
<
0
||
milliseconds
>
999
)
{
this
.
$message
.
warning
(
'
毫秒需在 0–999 之间
'
);
return
;
}
const
total
=
this
.
timePartsToSeconds
(
minutes
,
seconds
,
milliseconds
);
if
(
total
<
0
)
{
this
.
$message
.
warning
(
'
时间不能小于 0
'
);
return
;
}
const
EPS
=
1
e
-
6
;
const
minSec
=
d
.
minSec
;
const
maxSec
=
d
.
maxSec
;
if
(
isFinite
(
minSec
))
{
if
(
d
.
minInclusive
?
total
+
EPS
<
minSec
:
total
<=
minSec
+
EPS
)
{
this
.
$message
.
warning
(
`开始边界不合法,需
${
this
.
formatBoundLabel
(
minSec
,
d
.
minInclusive
,
true
)}
`
);
return
;
}
}
if
(
isFinite
(
maxSec
))
{
if
(
d
.
maxInclusive
?
total
-
EPS
>
maxSec
:
total
>=
maxSec
-
EPS
)
{
this
.
$message
.
warning
(
`结束边界不合法,需
${
this
.
formatBoundLabel
(
maxSec
,
d
.
maxInclusive
,
false
)}
`
);
return
;
}
}
const
list
=
this
.
subtitleEditor
.
mergedList
||
[];
const
item
=
list
[
d
.
tlIndex
];
if
(
!
item
)
{
this
.
$message
.
error
(
'
目标句子不存在
'
);
return
;
}
const
words
=
Array
.
isArray
(
item
.
sWordsRef
)
?
item
.
sWordsRef
:
[];
const
display
=
this
.
formatTime
(
total
);
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
));
}
}
else
if
(
d
.
type
===
'
sentence-end
'
)
{
item
.
end
=
display
;
if
(
words
.
length
)
{
const
last
=
words
[
words
.
length
-
1
];
const
fmt
=
this
.
detectTimeFormatFromArray
([
last
]);
this
.
$set
(
last
,
'
end
'
,
this
.
serializeTimeByFormat
(
total
,
fmt
));
}
}
else
if
(
d
.
type
===
'
word-start
'
)
{
const
word
=
words
[
d
.
wordIndex
];
if
(
!
word
)
{
this
.
$message
.
error
(
'
目标分词不存在
'
);
return
;
}
const
fmt
=
this
.
detectTimeFormatFromArray
([
word
]);
this
.
$set
(
word
,
'
start
'
,
this
.
serializeTimeByFormat
(
total
,
fmt
));
if
(
d
.
wordIndex
===
0
)
item
.
start
=
display
;
}
else
if
(
d
.
type
===
'
word-end
'
)
{
const
word
=
words
[
d
.
wordIndex
];
if
(
!
word
)
{
this
.
$message
.
error
(
'
目标分词不存在
'
);
return
;
}
const
fmt
=
this
.
detectTimeFormatFromArray
([
word
]);
this
.
$set
(
word
,
'
end
'
,
this
.
serializeTimeByFormat
(
total
,
fmt
));
if
(
d
.
wordIndex
===
words
.
length
-
1
)
item
.
end
=
display
;
}
else
{
this
.
$message
.
error
(
'
未知编辑类型
'
);
return
;
}
d
.
visible
=
false
;
this
.
$message
.
success
(
'
时间已更新
'
);
},
// 校准字幕:若句子 end 与最后一个单词 end 不一致,将末词 end 改为句子 end
calibrateSubtitleWordEndTimes
(
subtitleList
)
{
let
fixed
=
0
;
(
subtitleList
||
[]).
forEach
((
s
)
=>
{
if
(
!
s
)
return
;
const
words
=
Array
.
isArray
(
s
.
words
)
?
s
.
words
:
(
Array
.
isArray
(
s
.
word
)
?
s
.
word
:
null
);
if
(
!
words
||
!
words
.
length
)
return
;
const
{
end
:
sentenceEnd
}
=
this
.
extractTimesFromItem
(
s
,
null
);
const
sentenceEndSec
=
this
.
parseTimeToSeconds
(
sentenceEnd
);
if
(
isNaN
(
sentenceEndSec
))
return
;
const
lastWord
=
words
[
words
.
length
-
1
];
if
(
!
lastWord
)
return
;
const
wordEndSec
=
this
.
parseTimeToSeconds
(
lastWord
.
end
);
// 已一致(允许 1ms 误差)则跳过
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
);
fixed
+=
1
;
});
if
(
fixed
>
0
)
{
console
.
info
(
`[字幕校准] 已修正
${
fixed
}
处末词结束时间`
);
}
return
fixed
;
},
// 将当前条目与上一条合并(仅编辑视图,最终以 applyEditorChanges 写回)
// 将当前条目与上一条合并(仅编辑视图,最终以 applyEditorChanges 写回)
mergeWithPrevious
(
idx
)
{
mergeWithPrevious
(
idx
)
{
if
(
!
this
.
subtitleEditor
||
!
Array
.
isArray
(
this
.
subtitleEditor
.
mergedList
))
return
;
if
(
!
this
.
subtitleEditor
||
!
Array
.
isArray
(
this
.
subtitleEditor
.
mergedList
))
return
;
...
@@ -1387,35 +1675,40 @@ function initVueApp(savedData) {
...
@@ -1387,35 +1675,40 @@ function initVueApp(savedData) {
return
{
kind
:
'
string
'
,
unit
:
'
clock
'
,
segments
:
2
,
decimals
:
3
,
decimalSeparator
:
'
.
'
,
};
return
{
kind
:
'
string
'
,
unit
:
'
clock
'
,
segments
:
2
,
decimals
:
3
,
decimalSeparator
:
'
.
'
,
};
},
},
// 将秒数序列化回原始格式
// 将秒数序列化回原始格式
(统一先 round 到毫秒,避免浮点差 1ms)
serializeTimeByFormat
(
seconds
,
fmt
)
{
serializeTimeByFormat
(
seconds
,
fmt
)
{
if
(
seconds
==
null
||
isNaN
(
seconds
))
return
seconds
;
if
(
seconds
==
null
||
isNaN
(
seconds
))
return
seconds
;
const
f
=
fmt
||
{
kind
:
'
string
'
,
unit
:
'
clock
'
,
segments
:
2
,
decimals
:
3
,
decimalSeparator
:
'
.
'
};
const
f
=
fmt
||
{
kind
:
'
string
'
,
unit
:
'
clock
'
,
segments
:
2
,
decimals
:
3
,
decimalSeparator
:
'
.
'
};
const
totalMs
=
Math
.
round
(
Number
(
seconds
)
*
1000
);
if
(
f
.
kind
===
'
number
'
)
{
if
(
f
.
kind
===
'
number
'
)
{
if
(
f
.
unit
===
'
ms
'
)
return
Math
.
round
(
seconds
*
1000
)
;
if
(
f
.
unit
===
'
ms
'
)
return
totalMs
;
const
dec
=
typeof
f
.
decimals
===
'
number
'
?
f
.
decimals
:
3
;
const
dec
=
typeof
f
.
decimals
===
'
number
'
?
f
.
decimals
:
3
;
const
val
=
Number
(
seconds
.
toFixed
(
dec
));
const
val
=
Number
(
(
totalMs
/
1000
)
.
toFixed
(
dec
));
return
val
;
return
val
;
}
}
// 字符串
// 字符串
const
decSep
=
f
.
decimalSeparator
||
'
.
'
;
const
decSep
=
f
.
decimalSeparator
||
'
.
'
;
const
decimals
=
typeof
f
.
decimals
===
'
number
'
?
f
.
decimals
:
3
;
const
decimals
=
typeof
f
.
decimals
===
'
number
'
?
f
.
decimals
:
3
;
const
pad
=
n
=>
n
.
toString
().
padStart
(
2
,
'
0
'
);
const
pad
=
n
=>
n
.
toString
().
padStart
(
2
,
'
0
'
);
const
msInt
=
Math
.
round
((
seconds
%
1
)
*
Math
.
pow
(
10
,
decimals
));
const
scale
=
Math
.
pow
(
10
,
Math
.
min
(
Math
.
max
(
decimals
,
0
),
3
));
// decimals 为 3 时直接用毫秒;更少位数时再按位四舍五入
const
fracInt
=
decimals
>=
3
?
(
totalMs
%
1000
)
:
Math
.
round
((
totalMs
%
1000
)
/
(
1000
/
scale
));
if
(
f
.
unit
===
'
clock
'
)
{
if
(
f
.
unit
===
'
clock
'
)
{
let
s
=
Math
.
floor
(
seconds
);
let
s
=
Math
.
floor
(
totalMs
/
1000
);
const
h
=
Math
.
floor
(
s
/
3600
);
s
=
s
%
3600
;
const
h
=
Math
.
floor
(
s
/
3600
);
s
=
s
%
3600
;
const
m
=
Math
.
floor
(
s
/
60
);
const
m
=
Math
.
floor
(
s
/
60
);
const
sec
=
s
%
60
;
const
sec
=
s
%
60
;
const
frac
=
decimals
>
0
?
(
decSep
+
ms
Int
.
toString
().
padStart
(
decimals
,
'
0
'
))
:
''
;
const
frac
=
decimals
>
0
?
(
decSep
+
frac
Int
.
toString
().
padStart
(
decimals
,
'
0
'
))
:
''
;
if
(
f
.
segments
===
3
||
h
>
0
)
{
if
(
f
.
segments
===
3
||
h
>
0
)
{
return
`
${
pad
(
h
)}
:
${
pad
(
m
)}
:
${
pad
(
sec
)}${
frac
}
`
;
return
`
${
pad
(
h
)}
:
${
pad
(
m
)}
:
${
pad
(
sec
)}${
frac
}
`
;
}
}
return
`
${
pad
(
m
)}
:
${
pad
(
sec
)}${
frac
}
`
;
return
`
${
pad
(
m
)}
:
${
pad
(
sec
)}${
frac
}
`
;
}
}
// 纯秒字符串
// 纯秒字符串
const
intPart
=
Math
.
floor
(
seconds
);
const
intPart
=
Math
.
floor
(
totalMs
/
1000
);
const
frac
=
decimals
>
0
?
(
decSep
+
Math
.
round
((
seconds
-
intPart
)
*
Math
.
pow
(
10
,
decimals
))
.
toString
().
padStart
(
decimals
,
'
0
'
))
:
''
;
const
frac
=
decimals
>
0
?
(
decSep
+
fracInt
.
toString
().
padStart
(
decimals
,
'
0
'
))
:
''
;
return
`
${
intPart
}${
frac
}
`
;
return
`
${
intPart
}${
frac
}
`
;
},
},
...
@@ -1477,12 +1770,14 @@ function initVueApp(savedData) {
...
@@ -1477,12 +1770,14 @@ function initVueApp(savedData) {
return
'
00:00.000
'
;
return
'
00:00.000
'
;
}
}
const
hours
=
Math
.
floor
(
seconds
/
3600
);
// 先 round 成整数毫秒,再拆分,避免 (seconds % 1) * 1000 浮点少 1ms
const
minutes
=
Math
.
floor
((
seconds
%
3600
)
/
60
);
const
totalMs
=
Math
.
round
(
Math
.
max
(
0
,
seconds
)
*
1000
);
const
secs
=
Math
.
floor
(
seconds
%
60
);
let
rest
=
Math
.
floor
(
totalMs
/
1000
);
const
ms
=
Math
.
floor
((
seconds
%
1
)
*
1000
);
const
ms
=
totalMs
%
1000
;
const
hours
=
Math
.
floor
(
rest
/
3600
);
rest
=
rest
%
3600
;
const
minutes
=
Math
.
floor
(
rest
/
60
);
const
secs
=
rest
%
60
;
if
(
hours
>
0
)
{
if
(
hours
>
0
)
{
return
`
${
hours
.
toString
().
padStart
(
2
,
'
0
'
)}
:
${
minutes
.
toString
().
padStart
(
2
,
'
0
'
)}
:
${
secs
.
toString
().
padStart
(
2
,
'
0
'
)}
.
${
ms
.
toString
().
padStart
(
3
,
'
0
'
)}
`
;
return
`
${
hours
.
toString
().
padStart
(
2
,
'
0
'
)}
:
${
minutes
.
toString
().
padStart
(
2
,
'
0
'
)}
:
${
secs
.
toString
().
padStart
(
2
,
'
0
'
)}
.
${
ms
.
toString
().
padStart
(
3
,
'
0
'
)}
`
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment