list.vue 4.3 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.
 */
17 18 19 20 21 22
<template>
  <div class="list-model">
    <div class="table-box">
      <table>
        <tr>
          <th>
G
gongzijian 已提交
23
            <span>{{$t('#')}}</span>
24 25
          </th>
          <th>
G
gongzijian 已提交
26
            <span>{{$t('User')}}</span>
27 28 29 30 31
          </th>
          <th>
            <span>Token</span>
          </th>
          <th>
G
gongzijian 已提交
32
            <span>{{$t('Failure time')}}</span>
33 34
          </th>
          <th>
G
gongzijian 已提交
35
            <span>{{$t('Create Time')}}</span>
36 37
          </th>
          <th>
G
gongzijian 已提交
38
            <span>{{$t('Update Time')}}</span>
39
          </th>
40
          <th width="70">
41 42 43 44 45 46 47 48 49
            <span>{{$t('Operation')}}</span>
          </th>
        </tr>
        <tr v-for="(item, $index) in list" :key="$index">
          <td>
            <span>{{parseInt(pageNo === 1 ? ($index + 1) : (($index + 1) + (pageSize * (pageNo - 1))))}}</span>
          </td>
          <td>
            <span>
50
              {{item.userName}}
51 52 53 54
            </span>
          </td>
          <td><span>{{item.token}}</span></td>
          <td>
55 56 57 58 59 60 61 62 63 64
            <span v-if="item.expireTime">{{item.expireTime | formatDate}}</span>
            <span v-else>-</span>
          </td>
          <td>
            <span v-if="item.createTime">{{item.createTime | formatDate}}</span>
            <span v-else>-</span>
          </td>
          <td>
            <span v-if="item.updateTime">{{item.updateTime | formatDate}}</span>
            <span v-else>-</span>
65 66
          </td>
          <td>
67
            <x-button type="info" shape="circle" size="xsmall" data-toggle="tooltip" icon="ans-icon-edit" :title="$t('Edit')" @click="_edit(item)">
68 69 70 71 72 73 74 75 76 77 78
            </x-button>
            <x-poptip
                    :ref="'poptip-delete-' + $index"
                    placement="bottom-end"
                    width="90">
              <p>{{$t('Delete?')}}</p>
              <div style="text-align: right; margin: 0;padding-top: 4px;">
                <x-button type="text" size="xsmall" shape="circle" @click="_closeDelete($index)">{{$t('Cancel')}}</x-button>
                <x-button type="primary" size="xsmall" shape="circle" @click="_delete(item,$index)">{{$t('Confirm')}}</x-button>
              </div>
              <template slot="reference">
79
                <x-button type="error" shape="circle" size="xsmall" data-toggle="tooltip" icon="ans-icon-trash" :title="$t('delete')">
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                </x-button>
              </template>
            </x-poptip>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
  import { mapActions } from 'vuex'

  export default {
    name: 'token-list',
    data () {
      return {
        list: []
      }
    },
    props: {
      tokenList: Array,
      pageNo: Number,
      pageSize: Number
    },
    methods: {
      ...mapActions('user', ['deleteToken']),
      _closeDelete (i) {
        this.$refs[`poptip-delete-${i}`][0].doClose()
      },
      _delete (item, i) {
        this.deleteToken({
          id: item.id
        }).then(res => {
          this.$refs[`poptip-delete-${i}`][0].doClose()
          this.list.splice(i, 1)
          this.$message.success(res.msg)
        }).catch(e => {
          this.$refs[`poptip-delete-${i}`][0].doClose()
          this.$message.error(e.msg || '')
        })
      },
      _edit (item) {
G
gongzijian 已提交
122
        this.$emit('on-edit', item)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
      }
    },
    watch: {
      tokenList (a) {
        this.list = []
        setTimeout(() => {
          this.list = a
        })
      }
    },
    created () {
      this.list = this.tokenList
    },
    mounted () {
    },
    components: { }
  }
</script>