resource.vue 10.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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.
 */
<template>
  <m-popup :ok-text="$t('Submit')" :nameText="type.name + $t('Authorize')" @ok="_ok" ref="popup">
    <template slot="content">
20
      <div class="clearfix transfer-model" style="width: 660px">
21 22
        <div>
            <x-button-group v-model="checkedValue" size="small">
B
break60 已提交
23 24
                <x-button type="ghost" value="fileResource" @click="_ckFile">{{$t('File resources')}}</x-button>
                <x-button type="ghost" value="udfResource" @click="_ckUDf">{{$t('UDF resources')}}</x-button>
25 26
            </x-button-group>
        </div>
27
        <treeselect v-show="checkedValue=='fileResource'" v-model="selectFileSource" :multiple="true"  maxHeight="200" :options="fileList" :normalizer="normalizer" :value-consists-of="valueConsistsOf" :placeholder="$t('Please select resources')">
B
break60 已提交
28 29
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
30
        <treeselect v-show="checkedValue=='udfResource'" v-model="selectUdfSource" :multiple="true" maxHeight="200" :options="udfList" :normalizer="normalizer" :value-consists-of="valueConsistsOf" :placeholder="$t('Please select resources')">
B
break60 已提交
31 32 33
          <div slot="value-label" slot-scope="{ node }">{{ node.raw.fullName }}</div>
        </treeselect>
        <!-- <div class="select-list-box">
34 35 36 37 38 39
          <div class="tf-header">
            <div class="title">{{type.name}}{{$t('List')}}</div>
            <div class="count">{{cacheSourceList.length}}</div>
          </div>
          <div class="scrollbar tf-content">
            <ul>
40
              <li v-for="(item,$index) in sourceList" :key="$index" @click="_ckSource(item)">
41
                <span :title="item.name">{{item.name}}</span>
42 43 44 45 46 47 48 49 50 51 52 53 54
                <a href="javascript:"></a>
              </li>
            </ul>
          </div>
        </div>
        <div class="select-oper-box">&nbsp;</div>
        <div class="select-list-box">
          <div class="tf-header">
            <div class="title">{{$t('Selected')}}{{type.name}}</div>
            <div class="count">{{cacheTargetList.length}}</div>
          </div>
          <div class="scrollbar tf-content">
            <ul>
55
              <li v-for="(item,$index) in targetList" :key="$index" @click="_ckTarget(item)"><span :title="item.name">{{item.name}}</span></li>
56 57
            </ul>
          </div>
B
break60 已提交
58
        </div> -->
59 60 61 62 63 64 65 66
      </div>
    </template>
  </m-popup>
</template>
<script>
  import _ from 'lodash'
  import mPopup from '@/module/components/popup/popup'
  import mListBoxF from '@/module/components/listBoxF/listBoxF'
B
break60 已提交
67 68 69
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'

70 71 72 73 74

  export default {
    name: 'transfer',
    data () {
      return {
B
break60 已提交
75
        valueConsistsOf: 'LEAF_PRIORITY',
76 77 78 79 80 81 82
        checkedValue: 'fileResource',
        sourceList: this.fileSourceList,
        targetList: this.fileTargetList,
        cacheSourceList: this.fileSourceList,
        cacheTargetList: this.fileTargetList,

        fileSource: this.fileSourceList,
B
break60 已提交
83 84 85 86
        fileList: [],
        udfList: [],
        selectFileSource: [],
        selectUdfSource: [],
87 88 89 90
        fileTarget: this.fileTargetList,
        udfSource: this.udfSourceList,
        udfTarget: this.udfTargetList,
        searchSourceVal: '',
B
break60 已提交
91 92 93 94 95 96 97 98
        searchTargetVal: '',
        // define default value
        value: null,
        normalizer(node) {
          return {
            label: node.name
          }
        },
99 100 101 102 103 104 105 106 107
      }
    },
    props: {
      type: Object,
      fileSourceList: Array,
      udfSourceList: Array,
      fileTargetList: Array,
      udfTargetList: Array,
    },
B
break60 已提交
108 109 110 111 112 113 114 115 116 117
    created() {
      let file = this.fileSourceList
      let udf = this.udfSourceList
      this.diGuiTree(file)
      this.diGuiTree(udf)
      this.fileList = file
      this.udfList = udf
      this.selectFileSource = this.fileTargetList
      this.selectUdfSource = this.udfTargetList
    },
118
    methods: {
B
break60 已提交
119 120 121 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
      /*
        getParent
      */
      getParent(data2, nodeId2) {
        var arrRes = [];
        if (data2.length == 0) {
            if (!!nodeId2) {
                arrRes.unshift(data2)
            }
            return arrRes;
        }
        let rev = (data, nodeId) => {
            for (var i = 0, length = data.length; i < length; i++) {
                let node = data[i];
                if (node.id == nodeId) {
                    arrRes.unshift(node)
                    rev(data2, node.pid);
                    break;
                }
                else {
                    if (!!node.children) {
                        rev(node.children, nodeId);
                    }
                }
            }
            return arrRes;
        };
        arrRes = rev(data2, nodeId2);
        return arrRes;
      },
149
      _ok () {
B
break60 已提交
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
        let fullPathId = []
        let pathId = []
        this.selectFileSource.forEach(v=>{
          this.fileList.forEach(v1=>{
            let arr = []
            arr[0] = v1
            if(this.getParent(arr, v).length>0) {
              fullPathId = this.getParent(arr, v).map(v2=>{
                return v2.id
              })
              pathId.push(fullPathId.join('-'))
            }
          })
        })
        let fullUdfPathId = []
        let pathUdfId = []
        this.selectUdfSource.forEach(v=>{
          this.udfList.forEach(v1=>{
            let arr = []
            arr[0] = v1
            if(this.getParent(arr, v).length>0) {
              fullUdfPathId = this.getParent(arr, v).map(v2=>{
                return v2.id
              })
              pathUdfId.push(fullUdfPathId.join('-'))
            }
          })
        })
        let selAllSource = pathId.concat(pathUdfId)
179 180 181
        this.$refs['popup'].spinnerLoading = true
        setTimeout(() => {
          this.$refs['popup'].spinnerLoading = false
B
break60 已提交
182
          this.$emit('onUpdate', _.map(selAllSource, v => v).join(','))
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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        }, 800)
      },
      _ckFile() {
        this.checkedValue = "fileResource"
        this.sourceList = this.fileSource
        this.targetList = this.fileTarget
        this.cacheSourceList = this.fileSource
        this.cacheTargetList = this.fileTarget
      },
      _ckUDf() {
        this.checkedValue = "udfResource"
        this.sourceList = this.udfSource
        this.targetList = this.udfTarget
        this.cacheSourceList = this.udfSource
        this.cacheTargetList = this.udfTarget
      },
      _sourceQuery () {
        this.sourceList = this.sourceList.filter(v => v.name.indexOf(this.searchSourceVal) > -1)
      },
      _targetQuery () {
        this.targetList = this.targetList.filter(v => v.name.indexOf(this.searchTargetVal) > -1)
      },
      _ckSource (item) {
        this.targetList = this.cacheTargetList
        this.targetList.unshift(item)
        this.searchTargetVal = ''
        let i1 = _.findIndex(this.sourceList, v => item.id === v.id)
        this.sourceList.splice(i1, 1)
        let i2 = _.findIndex(this.cacheSourceList, v => item.id === v.id)
        if (i2 !== -1) {
          this.cacheSourceList.splice(i2, 1)
        }
        if(this.checkedValue == "fileResource") {
            this.fileTarget = this.targetList
            this.fileSource = this.sourceList
        } else {
            this.udfTarget = this.targetList
            this.udfSource = this.sourceList
        }
      },
      _ckTarget (item) {
        this.sourceList = this.cacheSourceList
        this.sourceList.unshift(item)
        this.searchSourceVal = ''
        let i1 = _.findIndex(this.targetList, v => item.id === v.id)
        this.targetList.splice(i1, 1)
        let i2 = _.findIndex(this.cacheTargetList, v => item.id === v.id)
        if (i2 !== -1) {
          this.cacheTargetList.splice(i2, 1)
        }
        if(this.checkedValue == "fileResource") {
            this.fileSource = this.sourceList
            this.fileTarget = this.targetList
        } else {
            this.udfSource = this.sourceList
            this.udfTarget = this.targetList
        }
B
break60 已提交
240 241 242 243
      },
      diGuiTree(item) {  // Recursive convenience tree structure
        item.forEach(item => {
          item.children === '' || item.children === undefined || item.children === null || item.children.length === 0?        
B
break60 已提交
244
            this.operationTree(item): this.diGuiTree(item.children);
B
break60 已提交
245
        })
B
break60 已提交
246 247 248 249 250 251
      },
      operationTree(item) {
        if(item.dirctory) {
          item.isDisabled =true
        }
        delete item.children
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
      }
    },
    watch: {
      searchSourceVal (val) {
        if (!val) {
          this.sourceList = _.cloneDeep(this.cacheSourceList)
          return
        }
        this._sourceQuery()
      },
      searchTargetVal (val) {
        if (!val) {
          this.targetList = _.cloneDeep(this.cacheTargetList)
          return
        }
        this._targetQuery()
      }
    },
B
break60 已提交
270
    components: { mPopup, mListBoxF, Treeselect }
271 272 273 274 275 276 277
  }
</script>

<style lang="scss" rel="stylesheet/scss">
  .transfer-model {
    padding: 0 20px;
    .select-list-box {
278
      width: 300px;
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
      float: left;
      border: 1px solid #dcdee2;
      border-radius: 3px;
      .tf-header {
        height: 36px;
        line-height: 36px;
        background: #f9fafc;
        position: relative;
        border-bottom: 1px solid #dcdee2;
        margin-bottom: 8px;
        .title {
          position: absolute;
          left: 8px;
          top: 0;
        }
        .count {
          position: absolute;
          right: 8px;
          top: 0;
          font-size: 12px;
        }
      }
      .tf-search {
        background: #fff;
        padding: 8px;
        .fa-search {
          color: #999;
        }
      }
      .tf-content {
        height: 280px;
        ul {
          li {
            height: 28px;
            line-height: 28px;
            cursor: pointer;
            span {
              padding-left: 10px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
320
              width: 290px;
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
              display: inline-block;
            }
            &:hover {
              background: #f6faff;
            }
          }
        }
      }
    }
    .select-oper-box {
      width: 20px;
      float: left;
    }
  }
</style>