Newer
Older
xc-business-system / src / views / dataManagement / components / data / standardDevice.vue
<!-- 标准库分析  --数据看板 -->
<script name="standardDevice" lang="ts" setup>
import dayjs from 'dayjs'
import draggable from 'vuedraggable'
import { colors } from '../environment/colors'
import { getRangeAllMonth } from '@/utils/date'
import img1 from '@/assets/images/data/swiper/1.jpg'
import img2 from '@/assets/images/data/swiper/2.jpg'
const props = defineProps({
  lab: {
    type: String,
    default: '',
  },
})

watch(() => props.lab, (newVal) => {
  if (newVal) {
    fetchData()
  }
})
const showChart = ref<any[]>([
  {
    name: '近五年标准库复查趋势',
    type: 'line',
    source: 'system',
    smooth: false,
  },
  {
    name: '标准库状态分析',
    type: 'bar-horizontal',
    source: 'system',
  },
  {
    name: '近一年部门核查分析',
    type: 'bar-vertical',
    source: 'system',
  },
  {
    name: '当年标准库核查排行榜',
    type: 'rank-table',
    source: 'system',
    columns: [
      {
        text: '标准库名称',
        value: 'name',
        align: 'center',
      },
      {
        text: '本年度核查次数',
        value: 'count',
        align: 'center',
      },
      {
        text: '最近核查时间',
        value: 'time',
        align: 'center',
      },

    ],
    data: [],
  },
])
watch(() => showChart.value.length, () => {
  setTimeout(() => {
    const resize = new Event('resize')
    window.dispatchEvent(resize)
  })
})
// 模拟数据
const loading = ref(false)
function fetchData() {
  loading.value = true
  // 近五年标准库复查趋势
  const name1 = ['电学电源组', '热工压力组', '无线脉冲组']
  const name2 = [] as any[]
  for (let i = Number(dayjs().format('YYYY')); i > Number(dayjs().format('YYYY')) - 5; i--) {
    name2.push(i)
  }
  showChart.value.filter((item: any) => item.name === '近五年标准库复查趋势')[0].xAxisData = name2.map(item => String(item)).reverse()
  showChart.value.filter((item: any) => item.name === '近五年标准库复查趋势')[0].data = name1.map(item => ({
    name: item,
    data: name2.map(item => Math.floor(Math.random() * 100) + 1),
    symbol: 'emptyCircle',
  }))
  //  标准库状态分析
  const name3 = ['撤销', '更换', '建标']
  showChart.value.filter((item: any) => item.name === '标准库状态分析')[0].data = name1.map(item => ({
    name: item,
    data: name3.map(item => Math.floor(Math.random() * 100) + 1),
  }))
  showChart.value.filter((item: any) => item.name === '标准库状态分析')[0].xAxisData = name3
  // 近一年部门核查分析
  const name4 = getRangeAllMonth(dayjs().subtract(6, 'month').format('YYYY-MM'), dayjs().format('YYYY-MM'))
  showChart.value.filter((item: any) => item.name === '近一年部门核查分析')[0].data = name1.map(item => ({
    name: item,
    data: name4.map(item => Math.floor(Math.random() * 100) + 1),
  }))
  showChart.value.filter((item: any) => item.name === '近一年部门核查分析')[0].xAxisData = name4
  // 当年标准库核查排行榜
  const name5 = ['直流稳压电源', '多功能校准源', '多功能电气安全', '安全阀', '微波衰减', '信号发生器', '频谱分析仪', '频率短期稳定度', '失真度', '低频信号源', '0.02级活塞式压力计', 'E2等砝码']
  showChart.value.filter((item: any) => item.name === '当年标准库核查排行榜')[0].data = name5.map(item => ({
    name: item,
    count: Math.floor(Math.random() * 10) + 1,
    time: dayjs().subtract(Math.floor(Math.random() * 30) + 1, 'day').format('YYYY-MM-DD'),
  }))
  setTimeout(() => {
    loading.value = false
  }, 3000)
}
setTimeout(() => {
  fetchData()
}, 100)
defineExpose({
  showChart,
})

// 拖拽结束
const onEnd = () => {
  console.log('拖拽结束')
  const resize = new Event('resize')
  window.dispatchEvent(resize)
}
const imgList = ref([img1, img2])
</script>

<template>
  <div class="container">
    <!-- 展示内容 -->
    <div class="content-count">
      <!-- 统计数据 -->
      <div class="count">
        <div class="count-item">
          <div class="header-icon">
            <svg-icon name="icon-env-device-online" class="icon-button-icon" />
          </div>
          <div class="header-content">
            <div class="content-title">
              标准库总数
            </div>
            <div class="content-count">
              18
            </div>
          </div>
        </div>
        <div class="count-item">
          <div class="header-icon">
            <svg-icon name="icon-env-device-online" class="icon-button-icon" />
          </div>
          <div class="header-content">
            <div class="content-title">
              当年复查标准库总数
            </div>
            <div class="content-count">
              2
            </div>
          </div>
        </div>
        <div class="count-item">
          <div class="header-icon">
            <svg-icon name="icon-env-device-online" class="icon-button-icon" />
          </div>
          <div class="header-content">
            <div class="content-title">
              核查记录总数
            </div>
            <div class="content-count">
              1
            </div>
          </div>
        </div>
        <div class="count-item">
          <div class="header-icon">
            <svg-icon name="icon-env-device-online" class="icon-button-icon" />
          </div>
          <div class="header-content">
            <div class="content-title">
              核查记录总数(本年度)
            </div>
            <div class="content-count">
              1
            </div>
          </div>
        </div>
        <div class="count-item">
          <div class="header-icon">
            <svg-icon name="icon-env-device-online" class="icon-button-icon" />
          </div>
          <div class="header-content">
            <div class="content-title">
              核查记录总数(本季度)
            </div>
            <div class="content-count">
              1
            </div>
          </div>
        </div>
      </div>
      <!-- 图表区域 -->
      <div class="content">
        <draggable
          v-model="showChart" item-key="name" class="chart"
          animation="300"
          drag-class="dragClass"
          ghost-class="ghostClass"
          chosen-class="chosenClass"
          @end="onEnd"
        >
          <template #item="{ element, index }">
            <div :style="{ width: `${showChart.length === 4 ? '48%' : index === 0 || index === 1 ? '48%' : '31.5%'}` }" class="chart-item">
              <div class="chart-name">
                {{ element.name }}
              </div>
              <div v-loading="loading" class="chart-page">
                <pie-chart v-if="element.type === 'pie'" :title="element.title" :show-total="element.showTotal" :data="element.data" :colors="colors" :center="element.center" label-formatter="{style1|{c}}" :label-position="element.labelPosition" :radius="element.radius" :grid="{ top: 50, left: 15, right: 15, bottom: 10, containLabel: true }" :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', left: '0', top: '10' }" />
                <line-chart v-if="element.type === 'line'" :colors="colors" :gradient="element.gradient" :x-axis-data="element.xAxisData" :data="element.data" :smooth="element.smooth" :grid="{ top: 47, left: 5, right: 5, bottom: 10, containLabel: true }" :legend="{ itemWidth: 8, itemHeight: 2, type: 'scroll', orient: 'horizontal', icon: 'roundRect', left: '0', top: '5' }" />
                <bar-chart-horizontal-rank v-if="element.type === 'rank'" :colors="colors" label-position="" :x-axis-data="element.xAxisData" :data="element.data" font-color="#000" :grid="{ top: 10, left: 20, right: 20, bottom: 10, containLabel: true }" :legend="{ }" />
                <scroll-table v-if="element.type === 'rank-table'" style="width: 100%;" :height="330" :data="element.data" :columns="element.columns" />
                <bar-chart-horizontal v-if="element.type === 'bar-horizontal'" bar-width="10" :bar-coner="0" :data="element.data" :x-axis-data="element.xAxisData" :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', left: '0', top: '10' }" />
                <bar-chart-vertical v-if="element.type === 'bar-vertical'" :bar-coner="0" :data="element.data" :x-axis-data="element.xAxisData" :legend="{ itemWidth: 8, itemHeight: 8, type: 'scroll', orient: 'horizontal', icon: 'roundRect', left: '0', top: '10' }" />
              </div>
            </div>
          </template>
        </draggable>
        <div class="swiper">
          <el-carousel trigger="click" height="680px">
            <el-carousel-item v-for="item in imgList" :key="item">
              <!-- <img :src="item" style="width: 100%;height: 680px;"> -->
              <el-image style="width: 100%;height: 680px;" :src="item" />
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.dragClass {
  /* background-color: blueviolet !important; */
  opacity: 1 !important;
  box-shadow: none !important;
  outline: none !important;
  background-image: none !important;
  color: #6ff !important;
}

.ghostClass {
  /* background-color: blue !important; */
}

.chosenClass {
  color: #6ff !important;

  /* background-color: #ccc !important; */

  /* opacity: 1 !important; */

  /* width: 32.5% !important; */
}

.content {
  display: flex;

  .chart {
    width: 70%;
  }

  .swiper {
    width: 30%;
    padding-top: 55px;
    box-sizing: content-box;
  }
}

.icon-button-icon {
  width: 50px;
  height: 50px;
}

.container {
  position: relative;
  // height: 500px;

  .btns {
    width: 100%;
    position: absolute;
    top: -36px;
    right: 60%;
    // left: 50%;
    display: flex;
    justify-content: space-between;
    padding: 0 60px;
  }

  .count {
    display: flex;
    width: 66%;
    margin: 0 auto;
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);

    .count-item {
      // margin-left: 20px;
      width: 40%;
      height: 75px;
      display: flex;
      padding: 0 10px;
      justify-content: space-around;

      .header-icon {
        width: 20%;
        display: flex;
        flex-direction: column;
        justify-content: center;
      }

      .header-content {
        // width: 60%;
        padding: 10px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;

        .content-title {
          font-weight: 700;
        }

        .content-count {
          font-weight: 700;
          font-size: 24px;
          color: #1aaf8b;
        }
      }
    }
  }

  .chart {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    // margin-top: 15px;
    padding-top: 20px;

    .chart-item {
      width: 33%;
      height: 348px;
      // border: 1px solid red;
      margin-top: 10px;

      .chart-name {
        color: #3d6fb6;
        font-size: 18px;
        font-weight: 700;
      }

      .chart-page {
        height: 330px;
      }
    }
  }
}
</style>