gongchunyi
2026-08-11 3ee27be7fadb2fd30bd42991ef810014f1e91a19
src/views/reportAnalysis/PSIDataAnalysis/index.vue
@@ -1,50 +1,66 @@
<template>
  <div class="scale-container">
    <div class="data-dashboard" :style="{ transform: `scale(${scaleRatio})` }">
    <!-- 全屏按钮 - 移动到左上角 -->
    <button class="fullscreen-btn" @click="toggleFullscreen" :title="isFullscreen ? '退出全屏' : '全屏显示'">
      <svg v-if="!isFullscreen" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/>
      </svg>
      <svg v-else width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/>
      </svg>
    </button>
    <!-- 顶部标题栏 -->
    <div class="dashboard-header">
      <div class="factory-name">PSI 数据分析</div>
    </div>
    <!-- 主要内容区域 -->
    <div class="dashboard-content">
      <!-- 左侧区域 -->
      <div class="left-panel">
        <LeftTop />
        <LeftBottom />
      </div>
      <!-- 中间区域 -->
      <div class="center-panel">
        <CenterTop />
        <CenterCenter/>
        <CenterBottom />
      </div>
      <!-- 右侧区域 -->
      <div class="right-panel">
        <RightBottom />
        <RightTop />
      </div>
    </div>
    </div>
  </div>
   <div class="scale-container">
      <div class="data-dashboard" :style="{ transform: `scale(${scaleRatio})` }">
         <!-- 全屏按钮 - 移动到左上角 -->
         <button class="fullscreen-btn" @click="toggleFullscreen" :title="isFullscreen ? '退出全屏' : '全屏显示'">
            <svg v-if="!isFullscreen" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
               <path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/>
            </svg>
            <svg v-else width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
               <path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/>
            </svg>
         </button>
         <!-- 顶部标题栏 -->
         <div class="dashboard-header">
            <div class="header-left"></div>
            <div class="factory-name">PSI 数据分析</div>
            <div class="header-right">
               <div class="date-picker-wrapper">
                  <el-date-picker
                     v-model="psiDateRange"
                     type="daterange"
                     range-separator="至"
                     start-placeholder="开始日期"
                     end-placeholder="结束日期"
                     value-format="YYYY-MM-DD"
                     :shortcuts="dateShortcuts"
                     @change="onDateRangeChange"
                  />
               </div>
            </div>
         </div>
         <!-- 主要内容区域 -->
         <div class="dashboard-content">
            <!-- 左侧区域 -->
            <div class="left-panel">
               <LeftTop />
               <LeftBottom />
            </div>
            <!-- 中间区域 -->
            <div class="center-panel">
               <CenterTop />
               <CenterCenter/>
               <CenterBottom />
            </div>
            <!-- 右侧区域 -->
            <div class="right-panel">
               <RightBottom />
               <RightTop />
            </div>
         </div>
      </div>
   </div>
</template>
<script setup>
import { ref, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { ref, onMounted, onBeforeUnmount, nextTick, provide, reactive } from 'vue'
import autofit from 'autofit.js'
import dayjs from 'dayjs'
import LeftBottom from './components/left-bottom.vue'
import CenterCenter from './components/center-center.vue'
import RightTop from '../dataDashboard/components/basic/right-top.vue'
@@ -66,226 +82,282 @@
// 用户store
const userStore = useUserStore()
// 日期范围筛选
const psiDateRange = ref([])
const psiDateRangeParams = ref({})
const dateShortcuts = [
   { text: '本月', value: () => { const start = dayjs().startOf('month').format('YYYY-MM-DD'); const end = dayjs().format('YYYY-MM-DD'); return [start, end] } },
   { text: '近7天', value: () => { const start = dayjs().subtract(6, 'day').format('YYYY-MM-DD'); const end = dayjs().format('YYYY-MM-DD'); return [start, end] } },
   { text: '近30天', value: () => { const start = dayjs().subtract(29, 'day').format('YYYY-MM-DD'); const end = dayjs().format('YYYY-MM-DD'); return [start, end] } },
   { text: '近90天', value: () => { const start = dayjs().subtract(89, 'day').format('YYYY-MM-DD'); const end = dayjs().format('YYYY-MM-DD'); return [start, end] } },
]
const onDateRangeChange = (val) => {
   if (val && val.length === 2) {
      psiDateRangeParams.value = { startDate: val[0], endDate: val[1] }
   } else {
      psiDateRangeParams.value = {}
   }
   dataDashboardRefreshTick.value++
}
provide('psiDateRange', psiDateRangeParams)
/** 与 dataDashboard 共用注入名,子组件(含复用的 right-top/right-bottom)每分钟刷新 */
const DASHBOARD_REFRESH_MS = 60 * 1000
const dataDashboardRefreshTick = ref(0)
provide('dataDashboardRefreshTick', dataDashboardRefreshTick)
let dashboardPollTimer = null
// 计算缩放比例
const calculateScale = () => {
  const container = document.querySelector('.scale-container')
  if (!container) return
  // 获取容器的实际尺寸
  const rect = container.getBoundingClientRect?.()
  const containerWidth = container.clientWidth || rect?.width || window.innerWidth
  const containerHeight = container.clientHeight || rect?.height || window.innerHeight
  // 计算宽高缩放比例,取较小值以保证内容完整显示(等比缩放)
  const scaleX = containerWidth / designWidth
  const scaleY = containerHeight / designHeight
  scaleRatio.value = Math.min(scaleX, scaleY)
   const container = document.querySelector('.scale-container')
   if (!container) return
   // 获取容器的实际尺寸
   const rect = container.getBoundingClientRect?.()
   const containerWidth = container.clientWidth || rect?.width || window.innerWidth
   const containerHeight = container.clientHeight || rect?.height || window.innerHeight
   // 计算宽高缩放比例,取较小值以保证内容完整显示(等比缩放)
   const scaleX = containerWidth / designWidth
   const scaleY = containerHeight / designHeight
   scaleRatio.value = Math.min(scaleX, scaleY)
}
// 窗口大小变化处理
const handleResize = () => {
  // 延迟执行,确保DOM更新完成
  setTimeout(() => {
    calculateScale()
  }, 100)
   // 延迟执行,确保DOM更新完成
   setTimeout(() => {
      calculateScale()
   }, 100)
}
// 全屏功能实现 - 针对scale-container元素
const toggleFullscreen = () => {
  const element = document.querySelector('.scale-container')
  if (!element) return
  if (!isFullscreen.value) {
    if (element.requestFullscreen) {
      element.requestFullscreen()
    } else if (element.webkitRequestFullscreen) {
      element.webkitRequestFullscreen()
    } else if (element.msRequestFullscreen) {
      element.msRequestFullscreen()
    }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen()
    } else if (document.webkitExitFullscreen) {
      document.webkitExitFullscreen()
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen()
    }
  }
   const element = document.querySelector('.scale-container')
   if (!element) return
   if (!isFullscreen.value) {
      if (element.requestFullscreen) {
         element.requestFullscreen()
      } else if (element.webkitRequestFullscreen) {
         element.webkitRequestFullscreen()
      } else if (element.msRequestFullscreen) {
         element.msRequestFullscreen()
      }
   } else {
      if (document.exitFullscreen) {
         document.exitFullscreen()
      } else if (document.webkitExitFullscreen) {
         document.webkitExitFullscreen()
      } else if (document.msExitFullscreen) {
         document.msExitFullscreen()
      }
   }
}
// 监听全屏变化事件
const handleFullscreenChange = () => {
  const fullscreenElement = document.fullscreenElement ||
                           document.webkitFullscreenElement ||
                           document.msFullscreenElement
  isFullscreen.value = fullscreenElement && fullscreenElement.classList.contains('scale-container')
  // 全屏状态变化时,延迟重新计算缩放比例(确保DOM更新完成)
  setTimeout(() => {
    calculateScale()
  }, 200)
   const fullscreenElement = document.fullscreenElement ||
      document.webkitFullscreenElement ||
      document.msFullscreenElement
   isFullscreen.value = fullscreenElement && fullscreenElement.classList.contains('scale-container')
   // 全屏状态变化时,延迟重新计算缩放比例(确保DOM更新完成)
   setTimeout(() => {
      calculateScale()
   }, 200)
}
// 生命周期钩子
onMounted(() => {
  // 使用nextTick确保DOM完全渲染后再初始化
  nextTick(() => {
    // 计算初始缩放比例
    calculateScale()
  })
  window.addEventListener('resize', handleResize)
  window.addEventListener('fullscreenchange', handleFullscreenChange)
  window.addEventListener('webkitfullscreenchange', handleFullscreenChange)
  window.addEventListener('MSFullscreenChange', handleFullscreenChange)
   // 使用nextTick确保DOM完全渲染后再初始化
   nextTick(() => {
      // 计算初始缩放比例
      calculateScale()
   })
   window.addEventListener('resize', handleResize)
   window.addEventListener('fullscreenchange', handleFullscreenChange)
   window.addEventListener('webkitfullscreenchange', handleFullscreenChange)
   window.addEventListener('MSFullscreenChange', handleFullscreenChange)
   dashboardPollTimer = setInterval(() => {
      dataDashboardRefreshTick.value++
   }, DASHBOARD_REFRESH_MS)
})
onBeforeUnmount(() => {
  window.removeEventListener('resize', handleResize)
  window.removeEventListener('fullscreenchange', handleFullscreenChange)
  window.removeEventListener('webkitfullscreenchange', handleFullscreenChange)
  window.removeEventListener('MSFullscreenChange', handleFullscreenChange)
  // 移除我们添加的autofit动态调整监听器
  if (window._autofitUpdateHandler) {
    window.removeEventListener('resize', window._autofitUpdateHandler)
    delete window._autofitUpdateHandler
  }
  // 关闭autofit
  autofit.off()
   if (dashboardPollTimer) {
      clearInterval(dashboardPollTimer)
      dashboardPollTimer = null
   }
   window.removeEventListener('resize', handleResize)
   window.removeEventListener('fullscreenchange', handleFullscreenChange)
   window.removeEventListener('webkitfullscreenchange', handleFullscreenChange)
   window.removeEventListener('MSFullscreenChange', handleFullscreenChange)
   // 移除我们添加的autofit动态调整监听器
   if (window._autofitUpdateHandler) {
      window.removeEventListener('resize', window._autofitUpdateHandler)
      delete window._autofitUpdateHandler
   }
   // 关闭autofit
   autofit.off()
})
</script>
<style scoped>
/* 外部缩放容器 - 占据整个视口 */
.scale-container {
position: relative;
width: 100%;
/* 页面在常规布局下(有顶栏)默认减去 84px,避免内容被裁切 */
height: calc(100vh - 84px);
display: flex;
align-items: center;
justify-content: center;
background-color: #000;
overflow: hidden;
   position: relative;
   width: 100%;
   /* 页面在常规布局下(有顶栏)默认减去 84px,避免内容被裁切 */
   height: calc(100vh - 84px);
   display: flex;
   align-items: center;
   justify-content: center;
   background-color: #000;
   overflow: hidden;
}
/* 内部内容区域 - 固定设计尺寸 */
.data-dashboard {
position: relative;
width: 1920px;
height: 1080px;
background-image: url("@/assets/BI/backImage@2x.png");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
transform-origin: center center;
   position: relative;
   width: 1920px;
   height: 1080px;
   background-image: url("@/assets/BI/backImage@2x.png");
   background-size: cover;
   background-position: center;
   background-repeat: no-repeat;
   transform-origin: center center;
}
/* 全屏状态的样式 - 作用于scale-container */
.scale-container:fullscreen {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: #000;
z-index: 9999;
   width: 100vw;
   height: 100vh;
   margin: 0;
   padding: 0;
   background-color: #000;
   z-index: 9999;
}
/* Webkit浏览器前缀 */
.scale-container:-webkit-full-screen {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: #000;
z-index: 9999;
   width: 100vw;
   height: 100vh;
   margin: 0;
   padding: 0;
   background-color: #000;
   z-index: 9999;
}
/* MS浏览器前缀 */
.scale-container:-ms-fullscreen {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
background-color: #000;
z-index: 9999;
   width: 100vw;
   height: 100vh;
   margin: 0;
   padding: 0;
   background-color: #000;
   z-index: 9999;
}
.dashboard-header {
position: relative;
z-index: 1;
height: 86px;
background-image: url("@/assets/BI/biaoti.png");
background-size: cover;
background-repeat: no-repeat;
display: flex;
align-items: center;
justify-content: center;
   position: relative;
   z-index: 1;
   height: 86px;
   background-image: url("@/assets/BI/biaoti.png");
   background-size: cover;
   background-repeat: no-repeat;
   display: flex;
   align-items: center;
   justify-content: space-between;
}
.header-left {
   width: 300px;
   padding-left: 20px;
   display: flex;
   align-items: center;
}
.header-right {
   width: 300px;
   display: flex;
   align-items: center;
   justify-content: flex-end;
   padding-right: 20px;
}
.date-picker-wrapper {
   /* 日期选择器在大屏上的样式 */
   --el-fill-color-blank: rgba(0, 20, 60, 0.8);
   --el-border-color: rgba(0, 212, 255, 0.3);
   --el-text-color-regular: #00d4ff;
   --el-color-primary: #00d4ff;
}
.factory-name {
font-weight: 600;
font-size: 52px;
color: #FFFFFF;
top: 16px;
position: absolute;
   font-weight: 600;
   font-size: 52px;
   color: #FFFFFF;
}
.fullscreen-btn {
position: absolute;
top: 10px;
left: 20px;
width: 40px;
height: 40px;
background: rgba(0, 20, 60, 0.8);
border: 1px solid rgba(0, 212, 255, 0.3);
border-radius: 6px;
color: #00d4ff;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s;
z-index: 10000;
   position: absolute;
   top: 10px;
   left: 20px;
   width: 40px;
   height: 40px;
   background: rgba(0, 20, 60, 0.8);
   border: 1px solid rgba(0, 212, 255, 0.3);
   border-radius: 6px;
   color: #00d4ff;
   cursor: pointer;
   display: flex;
   align-items: center;
   justify-content: center;
   transition: all 0.3s;
   z-index: 10000;
}
.fullscreen-btn:hover {
background: rgba(0, 30, 90, 0.9);
border-color: rgba(0, 212, 255, 0.5);
   background: rgba(0, 30, 90, 0.9);
   border-color: rgba(0, 212, 255, 0.5);
}
.dashboard-content {
position: relative;
z-index: 1;
display: flex;
gap: 30px;
padding: 0 30px;
height: calc(100% - 86px);
overflow: hidden;
   position: relative;
   z-index: 1;
   display: flex;
   gap: 30px;
   padding: 0 30px;
   height: calc(100% - 86px);
   overflow: hidden;
}
/* 确保各面板能够正确显示 */
.left-panel, .center-panel, .right-panel {
overflow: hidden;
   overflow: hidden;
}
.left-panel,
.right-panel {
flex: 1;
display: flex;
flex-direction: column;
gap: 24px;
width: 520px;
   flex: 1;
   display: flex;
   flex-direction: column;
   gap: 24px;
   width: 520px;
}
.center-panel {
flex: 1.5;
display: flex;
flex-direction: column;
gap: 20px;
   flex: 1.5;
   display: flex;
   flex-direction: column;
   gap: 20px;
}
</style>