Commit 0cbf369e by 李伟康

refactor(mobile): 优化报告卡片高度计算逻辑

- 提取 report-card 高度获取逻辑到独立函数
- 使用特定元素高度替代整个文档高度计算
- 统一多处高度计算逻辑调用新封装的函数
- 简化 iframe 高度调整的实现方式
1 parent a026e82b
......@@ -41,18 +41,20 @@ export default {
},
mounted () {
// 获取 report-card 元素的高度
const getReportCardHeight = () => {
const reportCard = document.querySelector('.report-card')
if (reportCard) {
return Math.max(reportCard.scrollHeight, 150)
}
return 150
}
window.addEventListener('message', function (event) {
if (event.data && event.data.type === 'GET_IFRAME_HEIGHT') {
// 获取文档高度
const height = Math.max(
document.documentElement.scrollHeight,
document.body.scrollHeight,
600
)
// 发送高度给父页面
// 发送 report-card 的高度给父页面
window.parent.postMessage(
{ type: 'RESIZE_IFRAME', height: height },
{ type: 'RESIZE_IFRAME', height: getReportCardHeight() },
'*'
)
}
......@@ -61,13 +63,8 @@ export default {
// 页面加载完成后自动发送一次高度
window.addEventListener('load', function () {
setTimeout(function () {
const height = Math.max(
document.documentElement.scrollHeight,
document.body.scrollHeight,
600
)
window.parent.postMessage(
{ type: 'RESIZE_IFRAME', height: height },
{ type: 'RESIZE_IFRAME', height: getReportCardHeight() },
'*'
)
}, 200)
......@@ -75,13 +72,8 @@ export default {
// 监听 DOM 变化,动态调整高度
const observer = new MutationObserver(function () {
const height = Math.max(
document.documentElement.scrollHeight,
document.body.scrollHeight,
600
)
window.parent.postMessage(
{ type: 'RESIZE_IFRAME', height: height },
{ type: 'RESIZE_IFRAME', height: getReportCardHeight() },
'*'
)
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!