Commit a026e82b by 李伟康

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

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