Newer
Older
xc-business-system / src / views / dataManagement / components / data / eqptDevice.vue
dutingting on 29 Nov 11 KB 临时提交
<!-- 受检智能模型分析  --数据看板 -->
<script name="EqptDeviceTrend" lang="ts" setup>
import dayjs from 'dayjs'
import draggable from 'vuedraggable'
import { colors } from '../environment/colors'
import { getRangeAllTime } from '@/utils/date'
const props = defineProps({
  lab: {
    type: String,
    default: '',
  },
})
// 日期查询条件
const dateRef = ref()
const current = ref('')
setTimeout(() => {
  current.value = '近7日'
})
const selectCurrentTime = ref()
const menu = ref(['当日', '近7日', '近14天', '自定义时间'])
// 时间筛选条件
const startTime = ref()
const calendarChange = (e: any) => {
  startTime.value = e[0].getTime()
}
const pickerOptions = (time: any) => {
  if (startTime.value) {
    const timeRange = 1 * 24 * 60 * 60 * 1000 // 1天时间戳
    const minTime = startTime.value - timeRange * 2
    const maxTime = startTime.value + timeRange * 15
    return time.getTime() <= minTime || time.getTime() >= maxTime || time.getTime() === startTime.value
  }
  else {
    return false
  }
}
// 点击自定义时间
const clickBtn = (event: any) => {
  const select = event.target.value
  if (select && select === '自定义时间') {
    dateRef.value.focus()
  }
  else if (select && select !== '自定义时间') {
    selectCurrentTime.value = []
    startTime.value = ''
  }
}
const timeDate = ref<string[]>([])
watch(() => current.value, (newVal) => {
  if (newVal) {
    if (newVal === '当日') {
      timeDate.value = [dayjs().format('YYYY-MM-DD')]
    }
    else if (newVal === '近7日') {
      timeDate.value = getRangeAllTime(dayjs().subtract(7, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD'))
    }
    else if (newVal === '近14天') {
      timeDate.value = getRangeAllTime(dayjs().subtract(14, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD'))
    }
    fetchData()
  }
})
watch(() => selectCurrentTime.value, (newVal) => {
  if (newVal.length === 2) {
    timeDate.value = getRangeAllTime(newVal[0], newVal[1])
    fetchData()
  }
})
watch(() => props.lab, (newVal) => {
  if (newVal) {
    fetchData()
  }
})
const showChart = ref<any[]>([
  {
    name: '任务单来源分析',
    type: 'pie',
    source: 'system',
    center: ['50%', '60%'],
    labelPosition: 'outside',
    radius: '70%',
    data: [],
  },
  {
    name: '受检智能模型来源排行榜',
    type: 'rank',
    source: 'system',
  },
  {
    name: '受检智能模型种类分析',
    type: 'pie',
    source: 'system',
    data: [],
  },
  {
    name: '受检智能模型数量趋势',
    type: 'line',
    source: 'system',
    xAxisData: [],
    data: [],
    smooth: false,
    gradient: false,
  },
  {
    name: '受检智能模型性能趋势',
    type: 'line',
    source: 'system',
    xAxisData: [],
    data: [],
    smooth: true,
    gradient: true,
  },
])
watch(() => showChart.value.length, () => {
  setTimeout(() => {
    const resize = new Event('resize')
    window.dispatchEvent(resize)
  })
})
// 模拟数据
const loading = ref(false)
function fetchData() {
  loading.value = true
  setTimeout(() => {
    // 任务单来源分析
    const name1 = ['西昌发射站/一连', '西昌发射站/二连', '文昌发射站/一连', '文昌发射站/二连', '文昌地面站/一连', '西昌地面站/一连']
    showChart.value.filter((item: any) => item.name === '任务单来源分析')[0].data = name1.map((item: string) => ({
      name: item,
      value: String(Math.floor(Math.random() * 100) + 1),
    }))
    // 受检智能模型种类分析
    const name2 = ['一般压力表', '精密压力表', '数字多用表', '频谱分析仪', '三线表', '铷钟', '数字计数器']
    showChart.value.filter((item: any) => item.name === '受检智能模型种类分析')[0].data = name2.map((item: string) => ({
      name: item,
      value: String(Math.floor(Math.random() * 100) + 1),
    }))
    // 受检智能模型数量趋势
    showChart.value.filter((item: any) => item.name === '受检智能模型数量趋势')[0].data = name2.slice(0, 4).map((item: string) => ({
      name: item,
      // symbol: 'emptyCircle',
      symbol: 'circle',
      data: timeDate.value.map(item => Math.floor(Math.random() * 100) + 1),
    }))
    showChart.value.filter((item: any) => item.name === '受检智能模型数量趋势')[0].xAxisData = timeDate.value
    // 受检智能模型性能趋势
    const name3 = ['禁用', '故障维修', '报废']
    showChart.value.filter((item: any) => item.name === '受检智能模型性能趋势')[0].data = name3.map((item: string) => ({
      name: item,
      symbol: 'emptyCircle',
      data: timeDate.value.map(item => Math.floor(Math.random() * 100) + 1),
    }))
    showChart.value.filter((item: any) => item.name === '受检智能模型性能趋势')[0].xAxisData = timeDate.value
    // 受检智能模型来源排行榜
    showChart.value.filter((item: any) => item.name === '受检智能模型来源排行榜')[0].data = name1.map(() => (Math.floor(Math.random() * 100) + 1)).sort((a: any, b: any) => b - a)
    showChart.value.filter((item: any) => item.name === '受检智能模型来源排行榜')[0].xAxisData = name1
    loading.value = false
  }, 3000)
}
setTimeout(() => {
  fetchData()
}, 100)
defineExpose({
  showChart,
})

// 拖拽结束
const onEnd = () => {
  console.log('拖拽结束')
  const resize = new Event('resize')
  window.dispatchEvent(resize)
}
</script>

<template>
  <div class="container">
    <!-- 查询条件 -->
    <div class="btns">
      <div />
      <div>
        <el-radio-group v-model="current" @click="clickBtn">
          <el-radio-button v-for="item in menu" :key="item" :label="item">
            {{ item }}
          </el-radio-button>
        </el-radio-group>
        <!-- 自定义时间选择  --移花接木 -->
        <el-date-picker
          ref="dateRef"
          v-model="selectCurrentTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          class="time-daterange"
          style="position: absolute;top: 0;left: 40px;z-index: -1;opacity: 0;"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          :disabled-date="pickerOptions" @calendar-change="calendarChange "
        />
      </div>
    </div>
    <!-- 展示内容 -->
    <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">
              69
            </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">
              2529
            </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">
              12654
            </div>
          </div>
        </div>
      </div>
      <!-- 图表区域 -->
      <!-- <div class="chart"> -->
      <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 === 6 ? '31%' : 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="{ }" />
              <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' }" />
              <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' }" />
              <scroll-table v-if="element.type === 'rank-table'" style="width: 100%;" :height="330" :data="element.data" :columns="element.columns" />
            </div>
          </div>
        </template>
      </draggable>
      <!-- </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; */
}

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

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

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

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

    .count-item {
      margin-left: 20px;
      width: 30%;
      height: 75px;
      display: flex;
      padding: 0 10px;

      .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>