Commit 87fd0f75 by 李伟康

"优化对话组件时间轴渲染逻辑及重叠处理"

1 parent 1ddc9066
...@@ -65,6 +65,7 @@ Component({ ...@@ -65,6 +65,7 @@ Component({
} }
this.barTop = barTop this.barTop = barTop
this.containerHeight = containerHeight this.containerHeight = containerHeight
let axisList = []
data?.sort((a, b) => a.offset - b.offset).forEach(e => { data?.sort((a, b) => a.offset - b.offset).forEach(e => {
const { const {
offset: mergedOffset, offset: mergedOffset,
...@@ -73,19 +74,20 @@ Component({ ...@@ -73,19 +74,20 @@ Component({
e.docTop = mergedOffset / totalDuration * containerHeight e.docTop = mergedOffset / totalDuration * containerHeight
e.text_id = `text_${mergedOffset}` e.text_id = `text_${mergedOffset}`
e.mergedOffset = mergedOffset e.mergedOffset = mergedOffset
if (mergedOffset != null) axisList.push(e)
}) })
data?.map((e, index) => { axisList.map((e, index) => {
// 检查并调整 top 值,避免重叠 // 检查并调整 top 值,避免重叠
for (let i = 0; i < index; i++) { for (let i = 0; i < index; i++) {
if (e.top < data[i].top + margin && if (e.top < axisList[i].top + margin &&
e.top + margin > data[i].top) { e.top + margin > axisList[i].top) {
// 如果重叠,将当前元素的 top 设置为前一个元素的底部加上 margin // 如果重叠,将当前元素的 top 设置为前一个元素的底部加上 margin
e.top = data[i].top + margin; e.top = axisList[i].top + margin;
} }
} }
}) })
this.setData({ this.setData({
axisList: data axisList
}) })
}, this) }, this)
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!