log.vue 10.9 KB
Newer Older
K
khadgarmage 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
L
ligang 已提交
17 18 19 20 21 22 23 24 25 26 27 28
<template>
  <span class="log-model">
    <span  v-if="stateId && item.type !== 'SUB_PROCESS'">
      <slot name="history"></slot>
      <span @click="_ckLog">
        <slot name="log" ></slot>
      </span>
    </span>
    <transition name="fade">
      <div v-show="isLog || source === 'list'" class="log-pop">
        <div class="log-box" >
          <div class="title">
G
i18n  
gongzijian 已提交
29
            <span>{{$t('View log')}}</span>
L
ligang 已提交
30
            <div class="full-screen">
G
i18n  
gongzijian 已提交
31
              <a href="javascript:" @click="_downloadLog" data-container="body" data-toggle="tooltip" :title="$t('Download Log')">
32
                <i class="ans-icon-download" style="font-size: 20px"></i>
L
ligang 已提交
33
              </a>
G
i18n  
gongzijian 已提交
34
              <a href="javascript:" class="refresh-log" :class="loading ? 'active' :''" @click="!loading && _refreshLog()" data-container="body" data-toggle="tooltip" :title="$t('Refresh Log')">
35
                <i class="ans-icon-refresh"></i>
L
ligang 已提交
36
              </a>
G
i18n  
gongzijian 已提交
37
              <a href="javascript:" @click="_screenOpen" v-show="!isScreen" data-container="body" data-toggle="tooltip" :title="$t('Enter full screen')">
38
                <i class="ans-icon-max"></i>
L
ligang 已提交
39
              </a>
G
i18n  
gongzijian 已提交
40
              <a href="javascript:" @click="_screenClose" v-show="isScreen" data-container="body" data-toggle="tooltip" :title="$t('Cancel full screen')">
41
                <i class="ans-icon-min"></i>
L
ligang 已提交
42 43 44 45 46 47 48 49 50
              </a>
            </div>
          </div>
          <div class="content">
            <div class="content-log-box" >
              <textarea class="textarea-ft" id="textarea-log" style="width: 100%" spellcheck="false" ></textarea>
            </div>
          </div>
          <div class="operation">
G
i18n  
gongzijian 已提交
51
            <x-button type="primary" shape="circle" @click="close"> {{$t('Close')}} </x-button>
L
ligang 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
          </div>
        </div>
      </div>
    </transition>
  </span>
</template>
<script>
  import _ from 'lodash'
  import i18n from '@/module/i18n'
  import store from '@/conf/home/store'
  import router from '@/conf/home/router'
  import { downloadFile } from '@/module/download'

  /**
   * Calculate text size
   */
  const handerTextareaSize = (isH = 0) => {
    $('body').find('.tooltip.fade.top.in').remove()
    return $('.textarea-ft').css({ 'height': `${$('.content-log-box').height() - isH}px` })
  }

  let content = ''

  export default {
    name: 'log',
    data () {
      return {
        store,
        router,
        isLog: false,
        stateId: $(`#${this.item.id}`).attr('data-state-id') || null,
        isScreen: false,
        loadingIndex: 0,
        isData: true,
        loading: false
      }
    },
    props: {
      item: {
        type: Object,
        default: {}
      },
      source: {
        type: String,
        default: 'from'
      },
      logId: Number
    },
    methods: {
      _refreshLog () {
        this.loading = true
        this.store.dispatch('dag/getLog', this._rtParam).then(res => {
          setTimeout(() => {
            this.loading = false
            if (res.data) {
G
i18n  
gongzijian 已提交
107
              this.$message.success(`${i18n.$t('Update log success')}`)
L
ligang 已提交
108
            } else {
G
i18n  
gongzijian 已提交
109
              this.$message.warning(`${i18n.$t('No more logs')}`)
L
ligang 已提交
110 111 112
            }
          }, 1500)
          // Handling text field size
G
i18n  
gongzijian 已提交
113
          handerTextareaSize().html('').text(res.data || `${i18n.$t('No log')}`)
L
ligang 已提交
114 115 116 117 118 119 120 121 122 123 124 125
        }).catch(e => {
          this.$message.error(e.msg || '')
          this.loading = false
        })
      },
      _ckLog () {
        this.isLog = true
        this.store.dispatch('dag/getLog', this._rtParam).then(res => {
          this.$message.destroy()
          if (!res.data) {
            this.isData = false
            setTimeout(() => {
G
i18n  
gongzijian 已提交
126
              this.$message.warning(`${i18n.$t('No more logs')}`)
L
ligang 已提交
127 128
            }, 1000)
            // Handling text field size
G
i18n  
gongzijian 已提交
129
            handerTextareaSize().html('').text(content || `${i18n.$t('No log')}`)
L
ligang 已提交
130 131 132 133
          } else {
            this.isData = true
            content = res.data
            // Handling text field size
G
i18n  
gongzijian 已提交
134
            handerTextareaSize().html('').text(content || `${i18n.$t('No log')}`)
L
ligang 已提交
135 136 137 138 139 140 141

            setTimeout(() => {
              $('#textarea').scrollTop(2)
            }, 800)
          }
        }).catch(e => {
          this.$message.destroy()
G
gongzijian 已提交
142
          this.$message.error(e.msg || '')
L
ligang 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        })
      },
      _screenOpen () {
        this.isScreen = true
        let $logBox = $('.log-box')
        let winW = $(window).width() - 40
        let winH = $(window).height() - 40
        $logBox.css({
          width: winW,
          height: winH,
          marginLeft: `-${parseInt(winW / 2)}px`,
          marginTop: `-${parseInt(winH / 2)}px`
        })
        $logBox.find('.content').animate({ scrollTop: 0 }, 0)
        // Handling text field size
        handerTextareaSize().html('').text(content)
      },
      _screenClose () {
        this.isScreen = false
        let $logBox = $('.log-box')
        $logBox.attr('style', '')
        $logBox.find('.content').animate({ scrollTop: 0 }, 0)
        // Handling text field size
        handerTextareaSize().html('').text(content)
      },
      /**
       * Download log
       */
      _downloadLog () {
172
        downloadFile('/dolphinscheduler/log/download-log', {
L
ligang 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
          taskInstId: this.stateId || this.logId
        })
      },
      /**
       * up
       */
      _onUp: _.debounce(function () {
        this.loadingIndex = this.loadingIndex - 1
        this._ckLog()
      }, 1000, {
        'leading': false,
        'trailing': true
      }),
      /**
       * down
       */
      _onDown: _.debounce(function () {
        this.loadingIndex = this.loadingIndex + 1
        this._ckLog()
      }, 1000, {
        'leading': false,
        'trailing': true
      }),
      /**
       * Monitor scroll bar
       */
      _onTextareaScroll () {
        let self = this
        $('#textarea-log').scroll(function () {
          let $this = $(this)
          // Listen for scrollbar events
          if (($this.scrollTop() + $this.height()) === $this.height()) {
            if (self.loadingIndex > 0) {
              self.$message.loading({
G
i18n  
gongzijian 已提交
207
                content: `${i18n.$t('Loading Log...')}`,
L
ligang 已提交
208 209 210 211 212 213 214 215 216 217 218
                duration: 0,
                closable: false
              })
              self._onUp()
            }
          }
          // Listen for scrollbar events
          if ($this.get(0).scrollHeight === ($this.height() + $this.scrollTop())) {
            // No data is not requested
            if (self.isData) {
              self.$message.loading({
G
i18n  
gongzijian 已提交
219
                content: `${i18n.$t('Loading Log...')}`,
L
ligang 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
                duration: 0,
                closable: false
              })
              self._onDown()
            }
          }
        })
      },
      /**
       * close
       */
      close () {
        $('body').find('.tooltip.fade.top.in').remove()
        this.isScreen = false
        this.isLog = false
        content = ''
        this.$emit('close')
      }
    },
    watch: {},
    created () {
      // Source is a task instance
      if (this.source === 'list') {
        this.$message.loading({
G
i18n  
gongzijian 已提交
244
          content: `${i18n.$t('Loading Log...')}`,
L
ligang 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
          duration: 0,
          closable: false
        })
        this._ckLog()
      }
    },
    mounted () {
      this._onTextareaScroll()
    },
    updated () {
    },
    computed: {
      _rtParam () {
        return {
          taskInstId: this.stateId || this.logId,
          skipLineNum: parseInt(`${this.loadingIndex ? this.loadingIndex + '0000' : 0}`),
          limit: parseInt(`${this.loadingIndex ? this.loadingIndex + 1 : 1}0000`)
        }
      }
    },
    components: { }
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .log-pop {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.4);
    z-index: 10;
    .log-box {
      width: 660px;
      height: 520px;
      background: #fff;
      border-radius: 3px;
      position: absolute;
      left:50%;
      top: 50%;
      margin-left: -340px;
      margin-top: -250px;
      .title {
        height: 50px;
        border-bottom: 1px solid #dcdedc;
        span {
          font-size: 16px;
          color: #333;
          padding-left: 20px;
          display: inline-block;
          padding-top: 16px;
        }
        .full-screen {
          position: absolute;
          right: 20px;
          top: 12px;
          a{
            color: #0097e0;
            font-size: 12px;
            margin-left: 10px;
            i {
              vertical-align: middle;
            }
          }
          .clock {
            >i {
              font-size: 20px;
              vertical-align: middle;
              transform: scale(1);
            }
          }
          .refresh-log {
            >i {
              font-size: 24px;
              vertical-align: middle;
              transform: scale(1);
            }
            &.active {
              >i {
                -webkit-transition-property: -webkit-transform;
                -webkit-transition-duration: 1s;
                -moz-transition-property: -moz-transform;
                -moz-transition-duration: 1s;
                -webkit-animation: rotateloading .4s linear infinite;
                -moz-animation: rotateloading .4s linear infinite;
                -o-animation: rotateloading .4s linear infinite;
                animation: rotateloading .4s linear infinite;
                transform: scale(.4);
                color: #999;
              }
            }
          }
        }
      }
      .content {
        height: calc(100% - 100px);
        background: #002A35;
        padding:6px 2px;
        .content-log-box {
          width: 100%;
          height: 100%;
          word-break:break-all;
          textarea {
            background: none;
            color: #9CABAF;
            border: 0;
            font-family: 'Microsoft Yahei,Arial,Hiragino Sans GB,tahoma,SimSun,sans-serif';
            font-weight: bold;
            resize:none;
            line-height: 1.6;
            padding: 6px;
          }
        }
      }
      .operation {
        text-align: right;
        height: 50px;
        line-height: 44px;
        border-top: 1px solid #dcdedc;
        padding-right: 20px;
        background: #fff;
        position: relative;
      }
    }
  }

</style>