Commit a026e82b by 李伟康

feat(report): 优化报表组件支持周报和自适应高度

- 新增周报数据格式兼容,支持本月/本周数据切换
- 添加 iframe 自适应高度功能,支持动态调整容器大小
- 修复雪碧图图标顺序问题,确保样式正常显示
- 添加 corpId 参数传递,完善分享链接功能
- 优化移动端报表卡片样式,新增卡片模式显示
- 配置开发端口为 8081,便于本地调试使用
1 parent a6fad41e
.sprite-icon { background-image: url(../images/sprite.png);background-size: 110px 102px;}
.icon-logo { width: 80px; height: 80px; background-position: 0px 0px;}
.icon-down { width: 12px; height: 12px; background-position: -90px -56px;}
.icon-stable { width: 12px; height: 12px; background-position: 0px -90px;}
.icon-up { width: 12px; height: 12px; background-position: -22px -90px;}
.icon-logo { width: 80px; height: 80px; background-position: 0px 0px;}
.icon-refresh { width: 16px; height: 16px; background-position: -90px -30px;}
.icon-share { width: 20px; height: 20px; background-position: -90px 0px;}
.icon-refresh { width: 16px; height: 16px; background-position: -90px -30px;}
\ No newline at end of file
.icon-stable { width: 12px; height: 12px; background-position: 0px -90px;}
.icon-up { width: 12px; height: 12px; background-position: -22px -90px;}
\ No newline at end of file
......@@ -21,21 +21,26 @@ export default {
},
},
methods: {
refreshReport(){
refreshReport () {
this.getReportList(1)
this.getReportList(2)
this.getReportList(3)
},
convertMetricsFormat (data) {
if (!data || !data['本月数据'] || !data['上月数据'] || !data['环比变化']) {
if (!data) {
return []
}
const currentMonth = data['本月数据']
const lastMonth = data['上月数据']
// 兼容月报和周报两种数据格式
const currentMonth = data['本月数据'] || data['本周数据']
const lastMonth = data['上月数据'] || data['上周数据']
const change = data['环比变化']
// 动态获取所有指标名称(从本月数据中获取 key)
if (!currentMonth || !lastMonth || !change) {
return []
}
// 动态获取所有指标名称(从当前周期数据中获取 key)
const metricNames = Object.keys(currentMonth)
return metricNames.map(name => {
......@@ -83,44 +88,50 @@ export default {
reportType,
periodStart: `${reportStartDate} 00:00:00`,
periodEnd: `${reportEndDate} 23:59:59`
}).then(({code, data}) => {
}).then(({ code, data }) => {
if (code == 0 && data) {
let metchantListData = []
data.businessList?.forEach(m => {
if (m.summaryPayload) metchantListData.push(JSON.parse(m.summaryPayload))
})
data.brandList?.forEach(b => {
console.log(JSON.parse(b.metricPayload))
if (b.metricPayload) b.businessListData = this.convertMetricsFormat(JSON.parse(b.metricPayload))
})
this.$set(this.reportList, businessType - 1, {
...data,
reportType,
metchantListData,
businessType,
reportStartDate,
reportEndDate
})
// console.log(this.reportList)
this.dataComplete = true
console.log('更新后的 reportList:', this.reportList)
}
}).catch(err => {
console.error(`getReportList(${businessType}) 错误:`, err)
})
},
shareReport () {
const { reportStartDate, reportEndDate, reportType } = this.query
utils.setClipboardData(`${window.location.origin}/#/mobile/report?reportStartDate=${reportStartDate}&reportEndDate=${reportEndDate}&reportType=${reportType}`, '链接复制成功,快去粘贴吧~')
const { reportStartDate, reportEndDate, reportType, corpId } = this.query
utils.setClipboardData(`${window.location.origin}/#/mobile/report?reportStartDate=${reportStartDate}&reportEndDate=${reportEndDate}&reportType=${reportType}&corpId=${corpId}`, '链接复制成功,快去粘贴吧~')
window.parent.postMessage(
{ type: 'COPY_SUCCESS' },
'*'
)
},
},
created () {
},
mounted () {
const { reportStartDate, reportEndDate, reportType } = this.$route.query
const { reportStartDate, reportEndDate, reportType, corpId } = this.$route.query
this.query = {
reportType,
periodKey: utils.getPeriodKey(reportStartDate, reportEndDate, reportType),
reportStartDate,
reportEndDate
reportEndDate,
corpId
}
this.getReportList(1)
this.getReportList(2)
......
<template>
<div class="report-component">
<div class="report-component " :class="{ 'is-card': isCard }">
<template v-if="reportIndex == 1">
<div class="date">统计周期:{{dayjs(reportItem.reportStartDate).format('YYYY年M月')}} ({{ reportItem.reportStartDate }}至{{ reportItem.reportEndDate }})</div>
</template>
......@@ -41,8 +41,8 @@
<thead>
<tr>
<th>指标</th>
<th>本月数据</th>
<th>上月数据</th>
<th>{{reportItem.reportType == 2 ? '本月' : '本周'}}数据</th>
<th>{{reportItem.reportType == 2 ? '上月' : '上周'}}数据</th>
<th>环比变化</th>
</tr>
</thead>
......@@ -113,6 +113,10 @@ export default {
type: Number,
default: 1
},
isCard: {
type: Boolean,
default: false
},
},
data () {
return {
......@@ -321,4 +325,11 @@ export default {
margin-bottom: 8px;
}
}
.is-card{
.content-text,.section-title{
font-size: 15.31px;
}
}
</style>
\ No newline at end of file
......@@ -7,6 +7,7 @@
:report-item="item"
:key="item.id || index"
:report-index="index + 1"
is-card
>
</report-component>
<div
......@@ -40,7 +41,56 @@ export default {
},
mounted () {
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
)
// 发送高度给父页面
window.parent.postMessage(
{ type: 'RESIZE_IFRAME', height: height },
'*'
)
}
})
// 页面加载完成后自动发送一次高度
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 },
'*'
)
}, 200)
})
// 监听 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 },
'*'
)
})
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
})
},
methods: {
......@@ -69,7 +119,7 @@ export default {
border-radius: 0 0 16px 16px;
border: 1px solid #fff;
border-top: none;
background: linear-gradient(180deg, #edf5ff 0%, #fff 19.65%, #fff 100%);
background: linear-gradient(180deg, #edf5ff 44px, #fff 19.65%, #fff 100%);
padding: 0 12px 12px;
box-sizing: border-box;
}
......
......@@ -35,7 +35,7 @@ module.exports = {
productionSourceMap: false, // 如果不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
devServer: {
disableHostCheck: true,
// port: 9527, // 端口 dj-scrm-wx-work-lwk
port: 8081, // 端口 dj-scrm-wx-work-lwk
// port: 9528, // 端口 dj-scrm-wx-work-main-lwk
open: false, // 启动后打开浏览器.
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!