完善页面7
This commit is contained in:
@@ -5,24 +5,20 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="card-content">
|
<view class="card-content">
|
||||||
<!-- 左侧自定义图例列 - 复刻 CRMEB 竖排样式 -->
|
<!-- 上部/左部图例区 - 复刻新图样式 (stacked) -->
|
||||||
<view class="legend-col">
|
<view class="legend-col">
|
||||||
<view class="legend-item" v-for="(item, index) in genderData" :key="index">
|
<view class="legend-item" v-for="(item, index) in (genderData as UTSJSONObject[])" :key="index">
|
||||||
<view class="legend-dot" :style="{ backgroundColor: item.itemStyle.color }"></view>
|
<view class="legend-dot" :style="{ backgroundColor: (item['itemStyle'] as UTSJSONObject)['color'] as string }"></view>
|
||||||
<text class="legend-label">{{ item.name }}</text>
|
<text class="legend-label">{{ item['name'] }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!--
|
<!-- 下部图表区 - 核心容器 -->
|
||||||
右侧图表列 - 核心容器
|
|
||||||
1. 使用 ResizeObserver 监听此处尺寸
|
|
||||||
2. 中心文字通过 CSS 绝对居中
|
|
||||||
-->
|
|
||||||
<view class="chart-col" ref="chartWrapRef">
|
<view class="chart-col" ref="chartWrapRef">
|
||||||
<!-- 图表组件 -->
|
<!-- 图表组件 -->
|
||||||
<EChartsView :option="chartOption" class="donut-chart" />
|
<EChartsView :option="chartOption" class="donut-chart" />
|
||||||
|
|
||||||
<!-- 中心文字:绝对居中,与 ECharts center:['50%','50%'] 严格同步 -->
|
<!-- 中心文字:绝对居中 -->
|
||||||
<view class="center-text">
|
<view class="center-text">
|
||||||
<text class="total-label">总用户数</text>
|
<text class="total-label">总用户数</text>
|
||||||
<text class="total-value">{{ totalUsers }}</text>
|
<text class="total-value">{{ totalUsers }}</text>
|
||||||
@@ -46,11 +42,11 @@ export default {
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
totalUsers: 525,
|
totalUsers: 789,
|
||||||
genderData: [
|
genderData: [
|
||||||
{ value: 450, name: '未知', itemStyle: { color: '#919eab' } },
|
{ value: 400, name: '男', itemStyle: { color: '#1890ff' } },
|
||||||
{ value: 50, name: '男', itemStyle: { color: '#1890ff' } },
|
{ value: 300, name: '女', itemStyle: { color: '#febc2c' } },
|
||||||
{ value: 25, name: '女', itemStyle: { color: '#febc2c' } }
|
{ value: 89, name: '未知', itemStyle: { color: '#919eab' } }
|
||||||
],
|
],
|
||||||
chartOption: {} as any,
|
chartOption: {} as any,
|
||||||
resizeObserver: null as any | null
|
resizeObserver: null as any | null
|
||||||
@@ -68,8 +64,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initChart()
|
|
||||||
this.setupResizeSystem()
|
this.setupResizeSystem()
|
||||||
|
|
||||||
|
// 📌 参考 AnalyticsPieChart 的延迟初始化策略,解决 H5 渲染 0 宽高问题
|
||||||
|
setTimeout(() => {
|
||||||
|
this.initChart()
|
||||||
|
}, 300)
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
if (this.resizeObserver != null) {
|
if (this.resizeObserver != null) {
|
||||||
@@ -84,7 +84,16 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initChart() {
|
initChart() {
|
||||||
// Step 4: 修复 option 自适应,使用百分比 radius 和 center
|
// 📌 参考 AnalyticsPieChart 的数据映射和 PlainObject 处理
|
||||||
|
const plainData = (this.genderData as Array<any>).map((it) => {
|
||||||
|
const itemStyle = it['itemStyle'] ? this.toPlainObject(it['itemStyle']) : {} as any
|
||||||
|
return {
|
||||||
|
name: String(it['name']),
|
||||||
|
value: Number(it['value']),
|
||||||
|
itemStyle: itemStyle
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const option = {
|
const option = {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'item',
|
trigger: 'item',
|
||||||
@@ -94,15 +103,12 @@ export default {
|
|||||||
textStyle: { color: '#333' },
|
textStyle: { color: '#333' },
|
||||||
extraCssText: 'box-shadow: 0 2px 8px rgba(0,0,0,0.15); border-radius: 4px;'
|
extraCssText: 'box-shadow: 0 2px 8px rgba(0,0,0,0.15); border-radius: 4px;'
|
||||||
},
|
},
|
||||||
// 关闭 ECharts 的普通图例,使用外部自定义图例
|
|
||||||
legend: { show: false },
|
legend: { show: false },
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
name: '性别比例',
|
name: '性别比例',
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
// 百分比定义半径,防止裁切
|
radius: ['58%', '75%'],
|
||||||
radius: ['60%', '78%'],
|
|
||||||
// 图表在容器内绝对居中
|
|
||||||
center: ['50%', '50%'],
|
center: ['50%', '50%'],
|
||||||
avoidLabelOverlap: false,
|
avoidLabelOverlap: false,
|
||||||
label: { show: false },
|
label: { show: false },
|
||||||
@@ -111,7 +117,7 @@ export default {
|
|||||||
scaleSize: 10,
|
scaleSize: 10,
|
||||||
label: { show: false }
|
label: { show: false }
|
||||||
},
|
},
|
||||||
data: this.genderData
|
data: plainData
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -163,13 +169,29 @@ export default {
|
|||||||
toPlainObject(obj: any): any {
|
toPlainObject(obj: any): any {
|
||||||
if (obj == null) return null
|
if (obj == null) return null
|
||||||
if (typeof obj !== 'object') return obj
|
if (typeof obj !== 'object') return obj
|
||||||
if (Array.isArray(obj)) return obj.map((item : any) : any => this.toPlainObject(item))
|
if (Array.isArray(obj)) {
|
||||||
|
return obj.map((item: any): any => this.toPlainObject(item))
|
||||||
|
}
|
||||||
const plain: any = {}
|
const plain: any = {}
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
const value = obj[key]
|
const value = obj[key]
|
||||||
if (typeof value === 'function' || key.startsWith('_') || key === 'toJSON') continue
|
if (typeof value === 'function' || key.startsWith('_') || key === 'toJSON') {
|
||||||
plain[key] = (value != null && typeof value === 'object' && !Array.isArray(value)) ? this.toPlainObject(value) : value
|
continue
|
||||||
|
}
|
||||||
|
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
||||||
|
// 📌 参考 AnalyticsPieChart 的优化逻辑,处理普通对象拷贝
|
||||||
|
let isSimple = true
|
||||||
|
for (const k in value) {
|
||||||
|
if (typeof value[k] === 'object' && value[k] !== null) {
|
||||||
|
isSimple = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plain[key] = isSimple ? { ...value } : this.toPlainObject(value)
|
||||||
|
} else {
|
||||||
|
plain[key] = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return plain
|
return plain
|
||||||
@@ -182,22 +204,22 @@ export default {
|
|||||||
.gender-card {
|
.gender-card {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
padding: 20px;
|
padding: 24px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
|
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.03);
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-header {
|
.card-header {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 24px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: 700;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,16 +227,19 @@ export default {
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 图例区 (横向排列) 对齐图片 */
|
||||||
.legend-col {
|
.legend-col {
|
||||||
width: 80px;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: row;
|
||||||
gap: 16px;
|
align-items: center;
|
||||||
flex-shrink: 0;
|
flex-wrap: wrap;
|
||||||
|
gap: 24px;
|
||||||
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend-item {
|
.legend-item {
|
||||||
@@ -226,34 +251,33 @@ export default {
|
|||||||
|
|
||||||
.legend-dot {
|
.legend-dot {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 10px;
|
height: 12px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend-label {
|
.legend-label {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #666;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 核心图表列 (centered) */
|
||||||
.chart-col {
|
.chart-col {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
/**
|
height: 300px;
|
||||||
* 确定高度策略 - 响应式复刻 CRMEB
|
overflow: visible !important;
|
||||||
* >=1200px (两列) 时保持紧凑高度
|
display: flex;
|
||||||
*/
|
justify-content: center;
|
||||||
height: clamp(320px, 35vh, 400px);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 响应式断点:<1200px 切换为单列,图表需要更大空间 */
|
/* 响应式断点 - 维持垂直布局并增加空间 */
|
||||||
@media (max-width: 1199.98px) {
|
@media (max-width: 1199.98px) {
|
||||||
.chart-col {
|
.chart-col {
|
||||||
height: clamp(480px, 50vh, 600px);
|
height: 350px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 强制覆盖 EChartsView 内部样式,确保绝对定位生效 */
|
/* 强制覆盖 EChartsView 样式 (确保完整铺满并通过 ECharts 配置居中) */
|
||||||
:deep(.donut-chart) {
|
:deep(.donut-chart) {
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
@@ -262,7 +286,7 @@ export default {
|
|||||||
position: relative !important;
|
position: relative !important;
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
height: 100% !important;
|
height: 100% !important;
|
||||||
overflow: hidden !important;
|
overflow: visible !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ec-canvas {
|
.ec-canvas {
|
||||||
@@ -273,6 +297,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 图表中心文字 (必须绝对居中于容器,微调位置垂直视觉居中) */
|
||||||
.center-text {
|
.center-text {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
@@ -287,15 +312,16 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.total-label {
|
.total-label {
|
||||||
font-size: 13px;
|
font-size: 15px;
|
||||||
color: #999;
|
color: #666;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 0;
|
||||||
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.total-value {
|
.total-value {
|
||||||
font-size: 32px;
|
font-size: 48px;
|
||||||
font-weight: bold;
|
font-weight: 700;
|
||||||
color: #333;
|
color: #333;
|
||||||
line-height: 1;
|
line-height: 1.1;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user