list.vue 5.5 KB
Newer Older
Davve's avatar
Davve committed
1 2 3
<template>
  <div class="app-container">
    <div class="filter-container">
Davve's avatar
Davve committed
4 5 6 7
      <el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 180px;" class="filter-item"
                @keyup.enter.native="handleFilter"/>
      <el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item"
                 style="width: 110px">
Davve's avatar
Davve committed
8 9 10
        <el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
Davve's avatar
Davve committed
11 12 13 14 15 16 17 18 19
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
                 @click="handleCreate">创建
      </el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
                 @click="handleOfflineOrOnline('offline')">下线
      </el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
                 @click="handleOfflineOrOnline('online')">上线
      </el-button>
Davve's avatar
Davve committed
20
    </div>
Davve's avatar
Davve committed
21 22 23 24
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%"
              ref="multipleTable" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center"></el-table-column>
      <el-table-column align="center" label="账号ID">
Davve's avatar
Davve committed
25
        <template slot-scope="scope">
Davve's avatar
Davve committed
26
          <router-link :to="'/account/edit/'+scope.row.id" class="link-type">
Davve's avatar
Davve committed
27 28
            <span>{{ scope.row.id }}</span>
          </router-link>
Davve's avatar
Davve committed
29 30 31
        </template>
      </el-table-column>

Davve's avatar
Davve committed
32
      <el-table-column align="center" label="用户名">
Davve's avatar
Davve committed
33 34 35 36 37
        <template slot-scope="scope">
          <span>{{ scope.row.username }}</span>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
38
      <el-table-column align="center" label="邮箱">
Davve's avatar
Davve committed
39
        <template slot-scope="scope">
Davve's avatar
Davve committed
40
          <span>{{ scope.row.email }}</span>
Davve's avatar
Davve committed
41 42 43
        </template>
      </el-table-column>

Davve's avatar
Davve committed
44
      <el-table-column align="center" label="是否在线">
Davve's avatar
Davve committed
45
        <template slot-scope="scope">
Davve's avatar
Davve committed
46
          <el-tag :type="scope.row.is_online | isOnlineFilter">{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag>
Davve's avatar
Davve committed
47 48 49
        </template>
      </el-table-column>

Davve's avatar
Davve committed
50 51 52 53 54
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button class="filter-item" type="primary" icon="el-icon-edit" @click="reset(scope.row)">重置密码</el-button>
        </template>
      </el-table-column>
Davve's avatar
Davve committed
55

Davve's avatar
Davve committed
56

Davve's avatar
Davve committed
57 58
    </el-table>

Davve's avatar
Davve committed
59
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
Davve's avatar
Davve committed
60
                style="margin-left: 250px;" @pagination="getList"/>
Davve's avatar
Davve committed
61 62 63 64 65

  </div>
</template>

<script>
Davve's avatar
Davve committed
66 67 68
  import {fetchList, OffLineOrOnLine, resetPassword} from '@/api/account'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  import waves from '@/directive/waves'
Davve's avatar
Davve committed
69

Davve's avatar
Davve committed
70 71 72 73 74 75 76 77 78 79 80
  export default {
    name: 'UserList',
    components: {Pagination},
    directives: {waves},
    filters: {
      isOnlineFilter(status) {
        const statusMap = {
          1: 'success',
          0: 'info',
        }
        return statusMap[status]
Davve's avatar
Davve committed
81
      }
Davve's avatar
Davve committed
82 83 84 85 86 87 88 89
    },
    data() {
      return {
        list: null,
        total: 0,
        listLoading: true,
        multipleSelection: [],
        del_list: [],
Davve's avatar
Davve committed
90

Davve's avatar
Davve committed
91 92 93 94 95 96 97 98
        listQuery: {
          page: 0,
          limit: 10,
          filter: {
            value: '',
            key: '',
            is_online: '',
          },
Davve's avatar
Davve committed
99
        },
Davve's avatar
Davve committed
100 101 102 103 104 105 106 107
        BooleanTypeOptions: [
          {'key': 1, 'display_name': '是'},
          {'key': 0, 'display_name': '否'}
        ],
        SearchTypeOptions: [
          {'key': 'user__username', 'display_name': '用户名'},
        ]
      }
Davve's avatar
Davve committed
108
    },
Davve's avatar
Davve committed
109
    created() {
Davve's avatar
Davve committed
110 111
      this.getList()
    },
Davve's avatar
Davve committed
112 113 114 115 116 117 118 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
    methods: {
      getList() {
        this.listLoading = true
        fetchList(this.listQuery).then(response => {
          this.list = response.data.data.data
          this.total = response.data.data.total
          this.listLoading = false
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      handleSizeChange(val) {
        this.listQuery.limit = val
        this.getList()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.getList()
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      handleCreate() {
        this.$router.push('/account/create')
      },
      handleOfflineOrOnline(val) {
        const length = this.multipleSelection.length;
        let str = '';
        this.del_list = this.del_list.concat(this.multipleSelection);
        for (let i = 0; i < length; i++) {
          if (val === 'offline') {
Davve's avatar
Davve committed
145
            this.multipleSelection[i].is_online = 0
Davve's avatar
Davve committed
146
          } else {
Davve's avatar
Davve committed
147 148 149
            this.multipleSelection[i].is_online = 1
          }
          str += this.multipleSelection[i].id + ' ';
Davve's avatar
Davve committed
150 151 152 153 154 155 156 157 158 159 160
        }
        OffLineOrOnLine({type: val, ids: str}).then(response => {
          this.multipleSelection = [];
          this.$message.success(response.data.data.message);
          this.$router.go(0)
        })
      },
      reset(data){
        resetPassword(data).then(response =>{
          this.$message.success('重置成功')
        })
Davve's avatar
Davve committed
161
      }
Davve's avatar
Davve committed
162
    }
Davve's avatar
Davve committed
163 164 165 166
  }
</script>

<style scoped>
Davve's avatar
Davve committed
167 168 169 170 171 172 173 174 175
  .edit-input {
    padding-right: 100px;
  }

  .cancel-btn {
    position: absolute;
    right: 15px;
    top: 10px;
  }
Davve's avatar
Davve committed
176
</style>