ソースを参照

fix: 修复首页bug

liujt 2 週間 前
コミット
3152a21228

+ 1 - 1
manifest.json

@@ -2,7 +2,7 @@
     "name" : "智慧工厂",
     "appid" : "__UNI__45B3907",
     "description" : "",
-    "versionName" : "V1.0.4.06",
+    "versionName" : "V1.0.4.07",
     "versionCode" : "100",
     "transformPx" : false,
     "h5" : {

+ 3 - 1
pages/home/home.vue

@@ -23,7 +23,7 @@
 			<sparePart v-if="roleId == 150" ref="sparePartRef"></sparePart>
 			<!--  -->
 			<view v-if="$isAuthorities('pda:home:manage')">
-				<homeNew></homeNew>
+				<homeNew ref="homeNewRef"></homeNew>
 			</view>
 
 			<view v-else>
@@ -208,6 +208,8 @@
 
 
 			this.init()
+			// tab 切换回来时刷新 manage 图表数据
+			this.$refs.homeNewRef?.refreshManage()
 			let _this = this
 			uni.$off('scancodedate') // 每次进来先 移除全局自定义事件监听器
 			uni.$on('scancodedate', function(data) {

+ 18 - 20
pages/home/homeNew.vue

@@ -78,14 +78,14 @@
 			<!-- 通知公告 -->
 			<view class="notice-bar" v-if="noticeList.length > 0">
 				<u-icon name="volume" size="30rpx" color="#ff9900"></u-icon>
-				<swiper class="notice-swiper" vertical autoplay circular :interval="3000">
-					<swiper-item v-for="(item, index) in noticeList" :key="index" @click="toNoticeDetail(item)">
-						<view class="notice-content">
-							<text class="notice-text">{{ item.title }}</text>
-							<text class="notice-date">{{ item.date }}</text>
-						</view>
-					</swiper-item>
-				</swiper>
+			<swiper class="notice-swiper" vertical autoplay circular :interval="3000">
+				<swiper-item v-for="(item, index) in noticeList" :key="index">
+					<view class="notice-content" @click.stop="toNoticeDetail(item)">
+						<text class="notice-text">{{ item.title }}</text>
+						<text class="notice-date">{{ item.date }}</text>
+					</view>
+				</swiper-item>
+			</swiper>
 			</view>
 
 			<manage ref="manageRef"></manage>
@@ -228,6 +228,10 @@
 
 
 		methods: {
+			// 刷新 manage 子组件数据(供父组件 tab 切换时调用)
+			refreshManage() {
+				this.$refs.manageRef?.refreshData()
+			},
 			toDeviceDetail() {
 				console.log('toDeviceDetail')
 				uni.navigateTo({
@@ -249,18 +253,12 @@
 					console.log(this.noticeList)
 				})
 			},
-			toNoticeDetail(item) {
-				console.log('toNoticeDetail', item)
-				this.$router.push({
-					path: '/pages/home/pages/manage/documentDetail',
-					query: {
-						id: item.id,
-					}
-				})
-				uni.navigateTo({
-					url: '/home/pages/manage/documentDetail?id=' + item.id
-				})
-			},
+		toNoticeDetail(item) {
+			console.log('toNoticeDetail', item)
+			uni.navigateTo({
+				url: '/pages/home/pages/manage/documentDetail?id=' + item.id
+			})
+		},
 			init() {
 				this.getStatistics()
 				this.$refs.navigationRef && this.$refs.navigationRef.getCount()

+ 111 - 33
pages/home/pages/manage/manage.vue

@@ -59,7 +59,7 @@
             <!-- <view class="data-divider"></view> -->
             <view class="data-row">
               <text class="data-label">生产总量</text>
-              <text class="data-value">{{ production.yearTotal }}<text class="data-unit">件</text></text>
+              <text class="data-value">{{ production.yearTotal }}</text>
             </view>
           </view>
           <view class="data-card orange">
@@ -71,7 +71,7 @@
             <!-- <view class="data-divider"></view> -->
             <view class="data-row">
               <text class="data-label">生产总量</text>
-              <text class="data-value">{{ production.monthTotal }}<text class="data-unit">件</text></text>
+              <text class="data-value">{{ production.monthTotal }}</text>
             </view>
           </view>
         </view>
@@ -239,7 +239,6 @@ export default {
       currentMonth: '',
       chartData: {
         marketingChart: {
-          categories: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
           // 混合图表:柱状图(订单量) + 折线图(订单金额)
           series: [
             { name: '月订单量', data: [], type: 'bar' },
@@ -249,7 +248,6 @@ export default {
           ]
         },
         productionChart: {
-          categories: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
           series: [
             { name: '生产工单', data: [], type: 'bar' },
             { name: '去年同期工单', data: [], type: 'bar' },
@@ -258,7 +256,6 @@ export default {
           ]
         },
         purchaseChart: {
-          categories: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
           series: [
             { name: '采购数量', data: [], type: 'bar' },
             { name: '去年同期数量', data: [], type: 'bar' },
@@ -267,7 +264,6 @@ export default {
           ]
         },
         materialChart: {
-          categories: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
           series: [
             { name: '采购入库', data: [], type: 'bar' },
             { name: '去年同期入库', data: [], type: 'bar' },
@@ -276,7 +272,6 @@ export default {
           ]
         },
         finishedChart: {
-          categories: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
           series: [
             { name: '生产入库', data: [], type: 'bar' },
             { name: '去年同期入库', data: [], type: 'bar' },
@@ -292,20 +287,8 @@ export default {
   mounted() {
     const now = new Date()
     this.currentYear = now.getFullYear()
-    this.currentMonth = String(now.getMonth() + 1).padStart(2, '0')
-    this.getMonthOutput()
-    this.getYearOutput()
-    this.getTendencyChart()
-    this.getPadStockStreamStatistics()
-    this.getPdaFindMaterialTrend()
-    this.getSaleOrderSummary()
-    this.getSaleOrderTrendSummary()
-    this.getPurchaseOrderSummary()
-    this.getPurchaseOrderTrendSummary()
-    // 作为备用:如果父组件没有调用 initCharts,这里兜底执行
-    this.$nextTick(() => {
-      this.initCharts()
-    })
+    this.currentMonth = String(now.getMonth() + 1)
+    this.refreshData()
   },
   beforeDestroy() {
     const chartIds = ['marketingChart', 'productionChart', 'purchaseChart', 'materialChart', 'finishedChart']
@@ -563,6 +546,22 @@ export default {
         url: '/pages/home/pages/manage/purchaseOrderDetail?type=' + type
       })
     },
+    // 刷新所有数据(供父组件在 tab 切换回来时调用)
+    refreshData() {
+      const now = new Date()
+      this.currentYear = now.getFullYear()
+      this.currentMonth = String(now.getMonth() + 1)
+      this.getMonthOutput()
+      this.getYearOutput()
+      this.getTendencyChart()
+      this.getPadStockStreamStatistics()
+      this.getPdaFindMaterialTrend()
+      this.getSaleOrderSummary()
+      this.getSaleOrderTrendSummary()
+      this.getPurchaseOrderSummary()
+      this.getPurchaseOrderTrendSummary()
+      // 图表初始化在数据回来后由各方法内部 $nextTick 刷新
+    },
     initCharts() {
       console.log('initCharts')
       Object.keys(this.chartData).forEach(chartId => {
@@ -574,31 +573,104 @@ export default {
         const ref = this.$refs[domId]
         if (!ref) return
 
+        // 当前月份,categories 和 data 只显示到当月
+        const currentMonthNum = new Date().getMonth() + 1
+        const months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
+        const categories = months.slice(0, currentMonthNum)
+
+        // 判断是否需要双Y轴(含金额/数量分离的图表:营销/采购/生产)
+        const needDualYAxis = ['marketingChart', 'purchaseChart', 'productionChart'].includes(domId)
+
+        const barColors = ['#f5a529', '#0da323', '#f5a529', '#0da323']
+        const lineColors = ['#f5a529', '#0da323', '#f5a529', '#0da323']
+
         const option = {
           grid: {
-            left: '14%',
-            right: '6%',
+            left: needDualYAxis ? '6%' : '6%',
+            right: needDualYAxis ? '6%' : '6%',
             top: '12%',
-            bottom: '10%'
+            bottom: '10%',
+            containLabel: true
           },
           tooltip: {
             trigger: 'axis',
             confine: true,
-            backgroundColor: 'rgba(50, 50, 50, 0.9)',
-            borderColor: '#333',
+            backgroundColor: '#f5a529',
+            borderColor: '#f5a529',
+            borderRadius: 6,
+            padding: [8, 12],
             textStyle: {
               color: '#fff',
               fontSize: 12
-            }
+            },
+            formatter: (function(chartId) {
+              var isAmountChart = chartId === 'marketingChart' || chartId === 'purchaseChart'
+              return function(params) {
+                if (!params || !params.length) return ''
+                var date = params[0].axisValue
+                var thisYear = []
+                var lastYear = []
+                for (var i = 0; i < params.length; i++) {
+                  var item = params[i]
+                  if (item.seriesName.indexOf('去年') !== -1) {
+                    lastYear.push(item)
+                  } else {
+                    thisYear.push(item)
+                  }
+                }
+                var result = date
+                if (thisYear.length) {
+                  result += '\n今年:\n'
+                  for (var j = 0; j < thisYear.length; j++) {
+                    var unit = (isAmountChart && thisYear[j].seriesName.indexOf('金额') !== -1) ? '万元' : ''
+                    result += ' ' + thisYear[j].seriesName + '  ' + thisYear[j].value + unit + '\n'
+                  }
+                }
+                if (lastYear.length) {
+                  result += '去年:\n'
+                  for (var k = 0; k < lastYear.length; k++) {
+                    var unit2 = (isAmountChart && lastYear[k].seriesName.indexOf('金额') !== -1) ? '万元' : ''
+                    result += ' ' + lastYear[k].seriesName + '  ' + lastYear[k].value + unit2 + '\n'
+                  }
+                }
+                return result
+              }
+            })(domId)
+          },
+          legend: {
+            show: false
           },
           xAxis: {
             type: 'category',
-            data: data.categories,
+            data: categories,
             axisLine: { lineStyle: { color: '#e5e5e5' } },
             axisLabel: { fontSize: 12, color: '#666' },
             axisTick: { show: false }
           },
-          yAxis: {
+          yAxis: needDualYAxis ? [
+            {
+              type: 'value',
+              name: domId === 'productionChart' ? '工单' : '数量',
+              min: 0,
+              splitNumber: 4,
+              axisLine: { show: false },
+              axisTick: { show: false },
+              splitLine: {
+                lineStyle: { color: '#e5e5e5', type: 'dashed' }
+              },
+              axisLabel: { fontSize: 12, color: '#666' }
+            },
+            {
+              type: 'value',
+              name: domId === 'productionChart' ? '总量' : '金额(万元)',
+              min: 0,
+              splitNumber: 4,
+              axisLine: { show: false },
+              axisTick: { show: false },
+              splitLine: { show: false },
+              axisLabel: { fontSize: 12, color: '#666' }
+            }
+          ] : {
             type: 'value',
             min: 0,
             splitNumber: 4,
@@ -611,23 +683,29 @@ export default {
           },
           series: data.series.map((item, index) => {
             const chartType = item.type || 'line'
-            const barColors = ['#f5a529', '#0da323', '#f5a529', '#0da323']
-            const lineColors = ['#f5a529', '#0da323', '#f5a529', '#0da323']
+
+            // 裁剪 data 到当前月份
+            const slicedData = (item.data || []).slice(0, currentMonthNum)
+
+            // 双Y轴:bar 用左轴(yAxisIndex:0),line 用右轴(yAxisIndex:1)
+            const yAxisIndex = needDualYAxis ? (chartType === 'bar' ? 0 : 1) : 0
 
             if (chartType === 'bar') {
               return {
                 name: item.name,
                 type: 'bar',
+                yAxisIndex,
                 barWidth: 10,
                 itemStyle: {
                   color: barColors[index % barColors.length]
                 },
-                data: item.data
+                data: slicedData
               }
             } else {
               return {
                 name: item.name,
                 type: 'line',
+                yAxisIndex,
                 smooth: true,
                 symbol: 'circle',
                 symbolSize: 4,
@@ -638,7 +716,7 @@ export default {
                 itemStyle: {
                   color: lineColors[index % lineColors.length]
                 },
-                data: item.data
+                data: slicedData
               }
             }
           })

+ 1 - 7
pages/home/pages/manage/purchaseOrderDetail.vue

@@ -185,13 +185,7 @@
 			},
 			//筛选
 			getData() {
-				let par = {
-					createTimeStart: '',
-					createTimeEnd: '',
-					sourceType: '',
-					progress: '',
-					orderStatus: ''
-				}
+				let par = JSON.parse(JSON.stringify(this.form))
 				par.pageNum = this.page
 				par.size = this.size
 				// par = this.URLSearchParams(par)