zhaowei
6 天以前 48d85187a16a313c5244a830862db5e672e6997d
src/views/dashboard/WorkshopSectionSignage.vue
@@ -94,7 +94,12 @@
    },
    data() {
      return {
        firstEnterClientWidth: null,
        pieChartRadius: ['40%', '60%'],
        normalPieChartRadius: ['40%', '60%'],
        currentPageProductionId: null,
        runningStateChart: '',
        runningStateChartDataRequireFinished: false,
        runningStateData: [
          { value: '0', name: '关机' },
          { value: '0', name: '报警' },
@@ -102,12 +107,14 @@
          { value: '0', name: '运行' }
        ],
        techConditionChart: '',
        techConditionChartRequireFinished: false,
        techConditionData: [
          { value: '0', name: '合格' },
          { value: '0', name: '禁用' },
          { value: '0', name: '限用' }
        ],
        warrantyMalfunctionChart: '',
        warrantyMalfunctionChartRequireFinished: false,
        warrantyMalfunctionData: [
          { value: '0', name: '报修' },
          { value: '0', name: '停机' },
@@ -185,6 +192,7 @@
      }
    },
    mounted() {
      this.firstEnterClientWidth = document.body.clientWidth || document.documentElement.clientWidth
      window.addEventListener('resize', this.handleWindowResize)
      this.getChartDataByApi()
    },
@@ -222,8 +230,9 @@
                { value: res.result[0].disabledCount, name: '禁用', technologyStatus: 'disabled' },
                { value: res.result[0].limitedUseCount, name: '限用', technologyStatus: 'limitedUse' }
              ]
              this.techConditionChartRequireFinished = true
              this.drawTechConditionChart()
            }
            this.drawTechConditionChart()
          })
      },
@@ -244,8 +253,9 @@
                { value: res.result[0].stopCount, name: '停机', isStop: '2' },
                { value: res.result[0].noStopCount, name: '运行', isStop: '1' }
              ]
              this.warrantyMalfunctionChartRequireFinished = true
              this.drawWarrantyMalfunctionChart()
            }
            this.drawWarrantyMalfunctionChart()
          })
      },
@@ -280,8 +290,12 @@
        })
        signageApi.getEquipmentStatusStatisticsApi(this.productionCode)
          .then(res => {
            if (res.success) this.runningStateData = res.result.list
            this.drawRunningStateChart(res.result.productionId)
            if (res.success) {
              this.runningStateData = res.result.list
              this.currentPageProductionId = res.result.productionId
              this.runningStateChartDataRequireFinished = true
              this.drawRunningStateChart(res.result.productionId)
            }
          })
      },
@@ -296,8 +310,10 @@
        })
        signageApi.getEquipmentDayUtilizationStatisticsApi(this.productionCode)
          .then(res => {
            if (res.success) this.first7DaysEfficiencyData = res.result
            this.drawFirst7DaysEfficiencyDataChart()
            if (res.success) {
              this.first7DaysEfficiencyData = res.result
              this.drawFirst7DaysEfficiencyDataChart()
            }
          })
      },
@@ -349,15 +365,16 @@
        })
        signageApi.getEquipmentOEEMonthStatisticsApi(this.productionCode)
          .then(res => {
            if (res.success) {
            if (res.success && res.result && res.result.length > 0) {
              this.barChartData = res.result.map(item => {
                return {
                  name: item.equipmentId,
                  value: item.overallEquipmentEfficiency
                }
              })
              this.drawBarChart()
            }
            this.drawBarChart()
          })
      },
@@ -406,7 +423,7 @@
            {
              type: 'pie',
              // selectedMode: "single",
              radius: ['40%', '60%'],
              radius: this.pieChartRadius,
              center: ['50%', '50%'],
              color: [
                '#0FC61A',
@@ -494,7 +511,7 @@
            {
              type: 'pie',
              // selectedMode: "single",
              radius: ['40%', '60%'],
              radius: this.pieChartRadius,
              center: ['50%', '50%'],
              color: [
                '#24F2F5',
@@ -583,7 +600,7 @@
              type: 'pie',
              roseType: 'angle', // 玫瑰图
              // selectedMode: "single",
              radius: ['35%', '55%'],
              radius: this.pieChartRadius,
              center: ['50%', '50%'],
              color: [
                '#8B8B8B',
@@ -643,7 +660,7 @@
          xAxis: equipmentIdList,
          yAxis: [
            {
              name: '利用率',
              name: 'TEEP',
              value: this.first7DaysEfficiencyData.dataList.map(item => item.utilizationRate)
            },
            {
@@ -655,11 +672,11 @@
              value: this.first7DaysEfficiencyData.dataList.map(item => item.openRate)
            }
          ],
          yAxisName: '前7天利用率(%)'
          yAxisName: '前7天TEEP(%)'
        }
        let legendData = []
        let seriesData = []
        let colorArr = ['#09F39E', '#A5F10D', '#09B3F6']
        let colorArr = ['#A7F0C1', '#FAE893', '#66DFE2']
        legendData = newData.yAxis.map((item) => item.name)
        seriesData = newData.yAxis.map((item1, index1) => {
          return {
@@ -668,7 +685,8 @@
            symbol: 'circle',
            symbolSize: 8,
            itemStyle: {
              color: colorArr[index1]
              color: colorArr[index1],
              barBorderRadius: 100
            },
            lineStyle: {
              width: 2
@@ -720,7 +738,7 @@
            axisLabel: {
              interval: 0,
              show: true,
              fontSize: 12,
              fontSize: 14,
              color: '#fff'
              // rotate: -30,
            },
@@ -769,7 +787,8 @@
              max: 100,
              axisLabel: {
                show: true,
                color: '#fff'
                color: '#fff',
                fontSize: 14
              },
              axisLine: {
                show: true,
@@ -934,8 +953,8 @@
            }
          })
          .finally(() => {
            option.title.text = moment().subtract(1, 'days').format('M月D日') + `利用率`
            option.series[0].name = '利用率'
            option.title.text = moment().subtract(1, 'days').format('M月D日') + `TEEP`
            option.series[0].name = 'TEEP'
            option.series[0].data = [this.gaugeChartData.utilizationRate]
            this.gaugeChart1.setOption(option, true)
            this.gaugeChart1.hideLoading()
@@ -1057,6 +1076,14 @@
      /* 绘制单柱图 */
      drawBarChart() {
        const defaultData = []
        const colorArray = ['#79CEAA', '#F589A2', '#6FBF9D', '#66DFE2', '#A7F0C1', '#FAE893', '#F7B7A0']
        const dataMax = +this.barChartData.sort((x, y) => +y.value - +x.value)[0].value
        let yAxisMax
        if (dataMax === 0) yAxisMax = 1 // 若数据中最大值为0,则将背景默认值设置为1
        else yAxisMax = Math.ceil(dataMax / 5) * 5 // 设置柱图背景阴影默认值,思路为数据最大值最接近的能被5整除的数字
        const yAxisInterval = yAxisMax / 5 // 同时将刻度值分成5份
        this.barChartData.forEach(item => defaultData.push(yAxisMax))
        const xAisData = this.barChartData.map(item => item.name)
        const option = {
          height: 260,
@@ -1077,11 +1104,11 @@
            axisPointer: {
              type: 'shadow'
            },
            // backgroundColor: 'rgba(9, 24, 48, 0.5)',
            borderColor: 'rgba(75, 253, 238, 0.4)',
            textStyle: {
              // color: '#CFE3FC'
            formatter: function(params) {
              return '<span style="font-weight:bolder;">' + params[0].name + '</span><br/>' +
                '<span style="display:inline-block; width:10px; height:10px; border-radius:100px; margin-right:5px; background:' + params[0].color + '"></span>' + ' OEE: ' + params[0].value + '%'
            },
            borderColor: 'rgba(75, 253, 238, 0.4)',
            borderWidth: 1
          },
          grid: {
@@ -1106,7 +1133,8 @@
                interval: 0, // 坐标轴刻度标签的显示间隔,在类目轴中有效;默认会采用标签不重叠的策略间隔显示标签;可以设置成0强制显示所有标签;如果设置为1,表示『隔一个标签显示一个标签』,如果值为2,表示隔两个标签显示一个标签,以此类推。
                // rotate: this.barChartData.length >= 5 ? -30 : 0, // 刻度标签旋转的角度,在类目轴的类目标签显示不下的时候可以通过旋转防止标签之间重叠;旋转的角度从-90度到90度
                inside: false, // 刻度标签是否朝内,默认朝外
                margin: 6 // 刻度标签与轴线之间的距离
                margin: 6, // 刻度标签与轴线之间的距离
                fontSize: 14
              },
              axisTick: {
                show: true,
@@ -1116,12 +1144,14 @@
          yAxis: [
            {
              name: '%',
              // nameLocation: 'middle',
              // nameGap: 30, // x轴name与横坐标轴线的间距
              min: 0,
              max: yAxisMax,
              interval: yAxisInterval,
              position: 'left',
              axisLabel: {
                formatter: '{value}',
                color: '#fff'
                color: '#fff',
                fontSize: 14
              },
              axisTick: {
                show: true
@@ -1152,10 +1182,13 @@
          series: [{
            type: 'bar',
            data: this.barChartData,
            barWidth: '25%',
            barWidth: this.barChartData.length > 5 ? '40%' : 30,
            itemStyle: {
              color: '#17C1F0',
              barBorderRadius: [10, 10, 10, 10]
              color: function(params) {
                let num = colorArray.length
                return colorArray[params.dataIndex % num]
              },
              barBorderRadius: 100
            },
            label: {
              show: false,
@@ -1169,8 +1202,20 @@
                color: '#fff',
                fontSize: 18
              }
            }
          }],
            },
            zlevel: 1
          },
            {
              name: '背景',
              type: 'bar',
              barWidth: this.barChartData.length > 5 ? '40%' : 30,
              barGap: '-100%',
              data: defaultData,
              itemStyle: {
                color: '#11294d',
                barBorderRadius: 100
              }
            }],
          dataZoom: {
            show: false,
            startValue: 0, // 从头开始。
@@ -1194,6 +1239,7 @@
        this.barChartCarouselTime = setInterval(() => {
          this.barChartData.push(this.barChartData.shift())
          xAisData.push(xAisData.shift())
          colorArray.push(colorArray.shift())
          this.$nextTick(() => {
            this.barChart.setOption(option, true)
          })
@@ -1232,18 +1278,35 @@
        this.modalVisible = true
      },
      re_drawPieChart() {
        const clientWidth = document.body.clientWidth || document.documentElement.clientWidth
        if (this.firstEnterClientWidth != 1920) {
          this.pieChartRadius = this.normalPieChartRadius.map(item => item = (+item.slice(0, -1) * (clientWidth / 1920)) + '%')
        } else {
          this.pieChartRadius = this.normalPieChartRadius.map(item => item = (+item.slice(0, -1) * (clientWidth / this.firstEnterClientWidth)) + '%')
        }
        console.log('pieChartRadius', this.pieChartRadius)
        this.$nextTick(() => {
          // 数据未加载完成无需重绘图表,不然无法区分接口返回正常与否
          if (this.runningStateChartDataRequireFinished) this.drawRunningStateChart(this.currentPageProductionId)
          if (this.techConditionChartRequireFinished) this.drawTechConditionChart()
          if (this.warrantyMalfunctionChartRequireFinished) this.drawWarrantyMalfunctionChart()
        })
      },
      /**
       * 窗口尺寸变化时触发
       * 调整图表尺寸以适应分辨率
       */
      handleWindowResize() {
        this.re_drawPieChart()
        if (this.runningStateChart) this.runningStateChart.resize()
        if (this.efficiencyChart) this.efficiencyChart.resize()
        if (this.techConditionChart) this.techConditionChart.resize()
        if (this.warrantyMalfunctionChart) this.warrantyMalfunctionChart.resize()
        if (this.first7DaysEfficiencyChart) this.first7DaysEfficiencyChart.resize()
        if (this.gaugeChart1) this.gaugeChart1.resize()
        if (this.gaugeChart2) this.gaugeChart2.resize()
        if (this.gaugeChart3) this.gaugeChart3.resize()
        if (this.gaugeChart4) this.gaugeChart4.resize()
        if (this.barChart) this.barChart.resize()
        if (this.doubleBarChart) this.doubleBarChart.resize()
      }
    }
  }