udfUpdate.vue 6.0 KB
Newer Older
K
khadgarmage 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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.
16
 */
L
ligang 已提交
17 18 19 20 21 22 23 24 25 26 27
<template>
  <div class="update-udf-model">
    <div class="update-udf-box">
      <ul>
        <li>
          <div class="update-pbx">
            <x-input
                    type="input"
                    size="small"
                    v-model="udfName"
                    :disabled="progress !== 0"
B
break60 已提交
28
                    style="width: 535px"
29
                    :placeholder="$t('Please enter resource name')"
L
ligang 已提交
30 31 32 33
                    autocomplete="off">
            </x-input>
            <div class="p1" style="position: absolute;">
              <input name="file" id="file" type="file" class="file-update" v-if="!progress">
G
i18n  
gongzijian 已提交
34
              <x-button type="dashed" size="small" :disabled="progress !== 0"> {{$t('Upload')}} </x-button>
L
ligang 已提交
35 36 37 38 39 40 41 42 43
            </div>
          </div>
        </li>
        <li>
          <x-input
                  type="textarea"
                  size="small"
                  v-model="udfDesc"
                  :disabled="progress !== 0"
G
i18n  
gongzijian 已提交
44
                  :placeholder="$t('Please enter description')"
L
ligang 已提交
45 46 47 48
                  autocomplete="off">
          </x-input>
        </li>
        <li style="margin-top: -4px;margin-bottom: 8px;">
G
i18n  
gongzijian 已提交
49
          <x-button type="success" size="xsmall" long @click="_ok" :loading="spinnerLoading">{{spinnerLoading ? `Loading... (${progress}%)` : $t('Upload UDF Resources')}}</x-button>
L
ligang 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import io from '@/module/io'
  import i18n from '@/module/i18n'
  import store from '@/conf/home/store'

  export default {
    name: 'udf-update',
    data () {
      return {
        store,
        udfName: '',
        udfDesc: '',
        file: '',
        progress: 0,
B
break60 已提交
69 70 71
        spinnerLoading: false,
        pid: null,
        currentDir: ''
L
ligang 已提交
72 73 74 75 76 77 78 79 80 81
      }
    },
    props: {

    },
    methods: {
      /**
       * validation
       */
      _validation () {
B
break60 已提交
82 83 84 85
        if (!this.currentDir) {
          this.$message.warning(`${i18n.$t('Please select UDF resources directory')}`)
          return false
        }
L
ligang 已提交
86
        if (!this.udfName) {
G
i18n  
gongzijian 已提交
87
          this.$message.warning(`${i18n.$t('Please enter file name')}`)
L
ligang 已提交
88 89 90
          return false
        }
        if (!this.file) {
G
i18n  
gongzijian 已提交
91
          this.$message.warning(`${i18n.$t('Please select the file to upload')}`)
L
ligang 已提交
92 93 94 95 96 97 98
          return false
        }
        return true
      },
      _verifyName () {
        return new Promise((resolve, reject) => {
          this.store.dispatch('resource/resourceVerifyName', {
99
            fullName: '/'+this.udfName,
L
ligang 已提交
100 101 102 103 104 105 106 107 108
            type: 'UDF'
          }).then(res => {
            resolve()
          }).catch(e => {
            this.$message.error(e.msg || '')
            reject(e)
          })
        })
      },
B
break60 已提交
109 110 111 112
      receivedValue(pid,name) {
        this.pid = pid
        this.currentDir = name
      },
L
ligang 已提交
113 114 115 116 117
      _formDataUpdate () {
        let self = this
        let formData = new FormData()
        formData.append('file', this.file)
        formData.append('type', 'UDF')
B
break60 已提交
118 119
        formData.append('pid', this.pid)
        formData.append('currentDir', this.currentDir)
L
ligang 已提交
120
        formData.append('name', this.udfName)
B
break60 已提交
121
        formData.append('description', this.udfDesc)
L
ligang 已提交
122 123 124 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 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 207 208 209 210 211 212
        this.spinnerLoading = true
        this.$emit('on-update-present', false)
        io.post(`resources/create`, res => {
          this.$message.success(res.msg)
          this.spinnerLoading = false
          this.progress = 0
          this.$emit('on-update', res.data)
        }, e => {
          this.spinnerLoading = false
          this.progress = 0
          this.$message.error(e.msg || '')
          this.$emit('on-update', e)
        }, {
          data: formData,
          emulateJSON: false,
          timeout: 99999999,
          onUploadProgress (progressEvent) {
            // Size has been uploaded
            let loaded = progressEvent.loaded
            // Total attachment size
            let total = progressEvent.total
            self.progress = Math.floor(100 * loaded / total)
          }
        })
      },
      _ok () {
        if (this._validation()) {
          this._verifyName().then(res => {
            this._formDataUpdate()
          })
        }
      }
    },
    watch: {},
    created () {
    },
    mounted () {
      $('#file').change(() => {
        let file = $('#file')[0].files[0]
        this.file = file
        this.udfName = file.name
      })
    },
    updated () {
    },
    beforeDestroy () {
    },
    destroyed () {
    },
    computed: {},
    components: {}
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .update-udf-model {
    min-height: 40px;
    border-radius: 3px;
    margin-top: -10px;
    margin-bottom: -10px;
    .update-udf-box {
      ul {
        li {
          margin-bottom: 8px;
          .v-input {
            textarea {
              min-height: 60px !important;
            }
          }
          .update-pbx {
            position: relative;
            .p1 {
              right: 0;
              top: 0;
              width: 82px;
              height: 28px;
              overflow: hidden;
              .file-update {
                position: absolute;
                left: 0;
                top: 0;
                opacity: 0;
                cursor: pointer;
              }
            }
          }
        }
      }
    }
  }
</style>