From b0c3dbefea78b106b7c680597361ea37930eaa0d Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 30 一月 2026 16:12:27 +0800
Subject: [PATCH] Merge branch 'dev_New' of http://114.132.189.42:9002/r/product-inventory-management into dev_New

---
 src/views/reportAnalysis/dataDashboard/components/basic/left-top.vue |   59 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/src/views/reportAnalysis/dataDashboard/components/basic/left-top.vue b/src/views/reportAnalysis/dataDashboard/components/basic/left-top.vue
index 67e0217..5b7e29e 100644
--- a/src/views/reportAnalysis/dataDashboard/components/basic/left-top.vue
+++ b/src/views/reportAnalysis/dataDashboard/components/basic/left-top.vue
@@ -2,8 +2,8 @@
   <div>
     <PanelHeader title="浜у搧澶х被" />
     <div class="panel-item-customers">
-      <div class="pie-chart-wrapper">
-        <div class="pie-background"></div>
+      <div class="pie-chart-wrapper" ref="pieWrapperRef">
+        <div class="pie-background" ref="pieBackgroundRef"></div>
         <Echarts
           ref="chart"
           :chartStyle="chartStyle"
@@ -21,10 +21,15 @@
 </template>
 
 <script setup>
-import { ref, onMounted } from 'vue'
+import { ref, onMounted, onBeforeUnmount } from 'vue'
 import Echarts from '@/components/Echarts/echarts.vue'
 import PanelHeader from '../PanelHeader.vue'
 import { productCategoryDistribution } from '@/api/viewIndex.js'
+import { useChartBackground } from '@/hooks/useChartBackground.js'
+
+const pieWrapperRef = ref(null)
+const pieBackgroundRef = ref(null)
+const chart = ref(null)
 
 // 鏁版嵁鍒楄〃锛堟潵鑷帴鍙o級
 const dataList = ref([])
@@ -83,17 +88,20 @@
 
 // 鎻愮ず妗�
 const landTooltip = {
-  triggerOn: 'click',
+  // triggerOn: 'hover',
   alwaysShowContent: true,
   position: function (pt) {
     return [pt[0], 130]
+  },
+  formatter: function (params) {
+    return `${params.name} (${params.value}绫�)`
   },
 }
 
 // 鍙屽眰鐜舰楗煎浘
 const landSeries = ref([
   {
-    name: '澶栧湀',
+    name: '浜у搧澶х被',
     type: 'pie',
     radius: ['35%', '55%'],
     center: ['50%', '50%'],
@@ -105,21 +113,22 @@
       lineHeight: 18,
       rich: {
         ...dotRich,
-        parent: { fontSize: 14, fontWeight: 600, color: '#fff', lineHeight: 20 },
+        parent: { fontSize: 14, fontWeight: 600, color: '#fff', lineHeight: 20, overflow: 'break' },
         child: { fontSize: 12, color: '#fff', lineHeight: 18 },
       },
       formatter: function (params) {
         const children = params?.data?.children || []
         const parentName = params?.data?.name || ''
-        const parentValue = params?.data?.value ?? 0
+        const rawVal = params?.data?.value
+        const parentValue = typeof rawVal === 'number' && !Number.isNaN(rawVal) ? rawVal : (Number(rawVal) || 0)
         const dotKey = `dot${(params?.dataIndex || 0) % landColors.length}`
         const dot = `{${dotKey}|} `
-        if (!children.length) return `${dot}{parent|${parentName} ${parentValue}}`
-        // 灏忓渾鐐� + 鐖剁骇 name + 鐖剁骇 value锛屾崲琛屽睍绀� children 鐨� name + value
-        return [
-          `${dot}{parent|${parentName}}`,
-          ...children.map((c) => `{child|${c.name}}`),
-        ].join('\n')
+        const parentLine = `${dot}{parent|${parentName} (${parentValue}绫�)}`
+        if (!children.length) return parentLine
+        // 鐖剁骇鍏ㄩ儴鏄剧ず锛涘瓙绾ф渶澶� 5 涓紝瓒呭嚭鏄剧ず鐪佺暐鍙�
+        const displayed = children.slice(0, 5).map((c) => `{child|${c.name}}`)
+        if (children.length > 5) displayed.push('{child|鈥')
+        return [parentLine, ...displayed].join('\n')
       },
     },
     labelLine: {
@@ -166,6 +175,15 @@
   textStyle: { color: '#B8C8E0' },
 }
 
+// 浣跨敤灏佽鐨勮儗鏅綅缃皟鏁存柟娉曪紝鍙嚜瀹氫箟鍋忕Щ鍊�
+const { adjustBackgroundPosition, init: initBackground, cleanup: cleanupBackground } = useChartBackground({
+  wrapperRef: pieWrapperRef,
+  backgroundRef: pieBackgroundRef,
+  offsetX: '-51.5%', // X 杞村亸绉伙紝鍙姩鎬佽皟鏁�
+  offsetY: '-39%',   // Y 杞村亸绉伙紝鍙姩鎬佽皟鏁�
+  watchData: dataList // 鐩戝惉鏁版嵁鍙樺寲锛岃嚜鍔ㄨ皟鏁翠綅缃�
+})
+
 const loadData = async () => {
   try {
     const res = await productCategoryDistribution()
@@ -178,6 +196,8 @@
     }))
     landLegend.data = dataList.value.map((d) => d.name)
     landSeries.value[0].data = dataList.value
+    // 鏁版嵁鍔犺浇瀹屾垚鍚庤皟鏁磋儗鏅綅缃�
+    adjustBackgroundPosition()
   } catch (e) {
     console.error('鑾峰彇浜у搧澶х被鍒嗗竷澶辫触:', e)
     dataList.value = []
@@ -186,8 +206,14 @@
   }
 }
 
+
 onMounted(() => {
   loadData()
+  initBackground()
+})
+
+onBeforeUnmount(() => {
+  cleanupBackground()
 })
 </script>
 
@@ -208,9 +234,6 @@
 
 .pie-background {
   position: absolute;
-  left: 50%;
-  top: 50%;
-  transform: translate(-51.5%, -39%);
   width: 360px;
   height: 360px;
   background-image: url('@/assets/BI/鐜懓鍥捐竟妗�.png');
@@ -219,5 +242,9 @@
   background-repeat: no-repeat;
   z-index: 1;
   pointer-events: none;
+  /* 榛樿灞呬腑锛屼細鍦� JS 涓姩鎬佽皟鏁� */
+  left: 50%;
+  top: 50%;
+  transform: translate(-51.5%, -39%);
 }
 </style>

--
Gitblit v1.9.3