Image.vue 4.3 KB
Newer Older
J
Jeff Wang 已提交
1
<template>
2 3 4 5 6 7 8 9 10
  <v-card
    hover
    class="visual-dl-image">
    <h3 class="visual-dl-image-title">{{ tagInfo.tag.displayName }}
      <span class="visual-dl-image-run-icon">{{ tagInfo.run }}</span>
    </h3>
    <p>
      <span>Step:</span>
      <span>{{ imgData.step }}</span>
J
Jeff Wang 已提交
11
      <span class="visual-del-image-time">{{ imgData.wallTime | formatTime }}</span>
12 13 14 15 16 17 18
    </p>
    <v-slider
      :max="steps"
      :min="slider.min"
      :step="1"
      v-model="currentIndex"
    />
J
Jeff Wang 已提交
19

20 21 22 23 24
    <img
      :width="imageWidth"
      :height="imageHeight"
      :src="imgData.imgSrc" >
  </v-card>
J
Jeff Wang 已提交
25 26 27 28 29 30 31 32 33 34
</template>
<script>
import {getPluginImagesImages} from '../../service';

const defaultImgWidth = 400;
const defaultImgHeight = 300;
// the time to refresh chart data
const intervalTime = 30;

export default {
J
Jeff Wang 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  props: {
    tagInfo: {
      type: Object,
      required: true,
    },
    runs: {
      type: Array,
      required: true,
    },
    running: {
      type: Boolean,
      required: true,
    },
    isActualImageSize: {
      type: Boolean,
      required: true,
    },
  },
J
Jeff Wang 已提交
53 54 55 56
  computed: {
    steps() {
      let data = this.data || [];
      return data.length - 1;
J
Jeff Wang 已提交
57
    },
J
Jeff Wang 已提交
58 59
    imageWidth() {
      return this.isActualImageSize ? this.imgData.width : defaultImgWidth;
J
Jeff Wang 已提交
60
    },
J
Jeff Wang 已提交
61 62
    imageHeight() {
      return this.isActualImageSize ? this.imgData.height : defaultImgHeight;
J
Jeff Wang 已提交
63
    },
J
Jeff Wang 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76
  },
  filters: {
    formatTime: function(value) {
      if (!value) {
        return;
      }
      // The value was made in seconds, must convert it to milliseconds
      let time = new Date(value * 1000);
      let options = {
        weekday: 'short', year: 'numeric', month: 'short',
        day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit',
      };
      return time.toLocaleDateString('en-US', options);
J
Jeff Wang 已提交
77
    },
J
Jeff Wang 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91
  },
  data() {
    return {
      currentIndex: 0,
      slider: {
        value: '0',
        label: '',
        min: 0,
        step: 1,
      },
      imgData: {},
      data: [],
      height: defaultImgHeight,
      weight: defaultImgWidth,
D
daminglu 已提交
92
      isDemo: process.env.NODE_ENV === 'demo',
J
Jeff Wang 已提交
93 94 95 96 97 98
    };
  },
  created() {
    this.getOriginChartsData();
  },
  mounted() {
D
daminglu 已提交
99
    if (this.running && !this.isDemo) {
J
Jeff Wang 已提交
100 101 102
      this.startInterval();
    }
  },
J
Jeff Wang 已提交
103

J
Jeff Wang 已提交
104 105 106
  beforeDestroy() {
    this.stopInterval();
  },
J
Jeff Wang 已提交
107

J
Jeff Wang 已提交
108 109
  watch: {
    running: function(val) {
D
daminglu 已提交
110
      (val && !this.isDemo) ? this.startInterval() : this.stopInterval();
J
Jeff Wang 已提交
111
    },
J
Jeff Wang 已提交
112 113 114 115
    currentIndex: function(index) {
      /* eslint-disable fecs-camelcase */
      if (this.data && this.data[index]) {
        let currentImgInfo = this.data ? this.data[index] : {};
J
Jeff Wang 已提交
116 117
        let {height, width, query, step, wallTime} = currentImgInfo;
        let url = '/data/plugin/images/individualImage?ts=' + wallTime;
J
Jeff Wang 已提交
118 119 120 121 122 123
        let imgSrc = [url, query].join('&');
        this.imgData = {
          imgSrc,
          height,
          width,
          step,
J
Jeff Wang 已提交
124
          wallTime,
J
Jeff Wang 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        };
      }
      /* eslint-enable fecs-camelcase */
    },
  },
  methods: {
    stopInterval() {
      clearInterval(this.getOringDataInterval);
    },
    // get origin data per {{intervalTime}} seconds
    startInterval() {
      this.getOringDataInterval = setInterval(() => {
        this.getOriginChartsData();
      }, intervalTime * 1000);
    },
    getOriginChartsData() {
      // let {run, tag} = this.tagInfo;
      let run = this.tagInfo.run;
      let tag = this.tagInfo.tag;
      let {displayName, samples} = tag;
      let params = {
        run,
        tag: displayName,
        samples,
      };
      getPluginImagesImages(params).then(({status, data}) => {
        if (status === 0) {
          this.data = data;
          this.currentIndex = data.length - 1;
        }
      });
156
    },
J
Jeff Wang 已提交
157
  },
J
Jeff Wang 已提交
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
};
</script>
<style lang="stylus">
    .visual-dl-image
        font-size 12px
        width 420px
        float left
        margin 20px 30px 10px 0
        background #fff
        padding 10px
        .visual-dl-image-title
            font-size 14px
            line-height 30px
            .visual-dl-image-run-icon
                background #e4e4e4
                float right
                margin-right 10px
                padding 0 10px
                border solid 1px #e4e4e4
                border-radius 6px
                line-height 20px
                margin-top 4px
180 181
        .visual-del-image-time
            float right
J
Jeff Wang 已提交
182 183
</style>