admin-fe/src/views/users/index.vue

162 lines
4.2 KiB
Vue
Raw Normal View History

2019-02-22 18:06:48 +00:00
<template>
<div class="users-container">
2019-02-24 22:31:05 +00:00
<h1>Users</h1>
2019-03-06 19:52:18 +00:00
<div class="search-container">
2019-03-22 20:58:58 +00:00
<el-checkbox :value="showLocalUsersOnly" @change="handleLocalUsersCheckbox">Local users only</el-checkbox>
2019-03-06 19:44:37 +00:00
<el-input placeholder="Search" class="search" @input="handleDebounceSearchInput"/>
</div>
2019-03-01 17:32:03 +00:00
<el-table v-loading="loading" :data="users" style="width: 100%">
2019-03-06 19:52:18 +00:00
<el-table-column :min-width="width" prop="id" label="ID"/>
2019-03-01 17:32:03 +00:00
<el-table-column prop="nickname" label="Name"/>
2019-03-06 19:52:18 +00:00
<el-table-column :min-width="width" label="Status">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-03-06 19:52:18 +00:00
<el-tag :type="scope.row.deactivated ? 'danger' : 'success'">
<span v-if="isDesktop">{{ scope.row.deactivated ? 'deactivated' : 'active' }}</span>
<i v-else :class="activationIcon(scope.row.deactivated)"/>
</el-tag>
2019-02-26 19:50:25 +00:00
</template>
</el-table-column>
2019-03-01 17:32:03 +00:00
<el-table-column fixed="right" label="Actions">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-03-01 17:32:03 +00:00
<el-button
2019-03-03 20:01:00 +00:00
v-if="showDeactivatedButton(scope.row.id)"
2019-03-22 20:58:58 +00:00
class="toggle-activation"
2019-03-01 17:32:03 +00:00
type="text"
size="small"
@click="handleDeactivate(scope.row)"
2019-03-03 20:01:00 +00:00
>{{ scope.row.deactivated ? 'Activate' : 'Deactivate' }}</el-button>
2019-02-24 22:31:05 +00:00
</template>
</el-table-column>
</el-table>
2019-02-27 22:13:20 +00:00
<div v-if="!loading" class="pagination">
<el-pagination
:total="usersCount"
2019-03-03 20:46:14 +00:00
:current-page="currentPage"
:page-size="pageSize"
2019-02-27 22:13:20 +00:00
background
layout="prev, pager, next"
2019-03-01 17:32:03 +00:00
@current-change="handlePageChange"
/>
2019-02-27 22:13:20 +00:00
</div>
2019-02-22 18:06:48 +00:00
</div>
</template>
<script>
2019-03-01 17:32:03 +00:00
import debounce from 'lodash.debounce'
2019-02-23 21:40:26 +00:00
2019-02-22 18:06:48 +00:00
export default {
name: 'Users',
2019-02-24 22:31:05 +00:00
computed: {
loading() {
return this.$store.state.users.loading
},
users() {
return this.$store.state.users.fetchedUsers
2019-02-27 22:13:20 +00:00
},
usersCount() {
return this.$store.state.users.totalUsersCount
},
pageSize() {
return this.$store.state.users.pageSize
2019-03-03 20:46:14 +00:00
},
currentPage() {
return this.$store.state.users.currentPage
2019-03-06 19:44:37 +00:00
},
2019-03-22 20:58:58 +00:00
showLocalUsersOnly() {
return this.$store.state.users.showLocalUsersOnly
2019-03-06 19:52:18 +00:00
},
isDesktop() {
return this.$store.state.app.device === 'desktop'
},
isMobile() {
return this.$store.state.app.device === 'mobile'
},
width() {
return this.isMobile ? 60 : false
2019-03-22 20:58:58 +00:00
},
rowStyle(id) {
return {
'data-user-id': id
}
2019-02-22 18:06:48 +00:00
}
2019-02-23 21:40:26 +00:00
},
2019-03-01 17:32:03 +00:00
created() {
this.handleDebounceSearchInput = debounce((query) => {
this.$store.dispatch('SearchUsers', { query, page: 1 })
2019-03-01 17:32:03 +00:00
}, 500)
},
2019-02-23 21:40:26 +00:00
mounted: function() {
this.$store.dispatch('FetchUsers', { page: 1 })
2019-02-24 22:31:05 +00:00
},
methods: {
2019-02-26 19:50:25 +00:00
handleDeactivate({ nickname }) {
this.$store.dispatch('ToggleUserActivation', nickname)
2019-02-27 22:13:20 +00:00
},
handlePageChange(page) {
2019-03-03 20:01:00 +00:00
const searchQuery = this.$store.state.users.searchQuery
if (searchQuery === '') {
this.$store.dispatch('FetchUsers', { page })
2019-03-03 20:01:00 +00:00
} else {
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
2019-03-03 20:01:00 +00:00
}
},
showDeactivatedButton(id) {
return this.$store.state.user.id !== id
2019-03-06 19:44:37 +00:00
},
handleLocalUsersCheckbox(e) {
this.$store.dispatch('ToggleLocalUsersFilter', e)
2019-03-06 19:52:18 +00:00
},
activationIcon(status) {
return status ? 'el-icon-error' : 'el-icon-success'
2019-02-24 22:31:05 +00:00
}
2019-02-22 18:06:48 +00:00
}
}
</script>
2019-03-01 17:32:03 +00:00
<style rel='stylesheet/scss' lang='scss' scoped>
2019-02-24 22:31:05 +00:00
.users-container {
h1 {
margin-left: 15px;
}
2019-02-27 22:13:20 +00:00
.pagination {
2019-03-03 20:01:00 +00:00
margin: 25px 0;
2019-02-27 22:13:20 +00:00
text-align: center;
}
2019-02-24 22:31:05 +00:00
2019-03-01 17:32:03 +00:00
.search {
width: 300px;
margin-bottom: 21.5px;
margin-right: 15px;
float: right;
}
2019-03-06 19:52:18 +00:00
.search-container {
2019-03-06 19:44:37 +00:00
display: flex;
justify-content: space-between;
align-items: baseline;
margin-left: 15px;
}
2019-03-01 17:32:03 +00:00
}
2019-03-06 19:52:18 +00:00
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
.users-container {
h1 {
margin-left: 7px;
}
.search {
width: 50%;
margin-bottom: 21.5px;
margin-right: 7px;
float: right;
}
.search-container {
display: flex;
justify-content: space-between;
align-items: baseline;
margin-left: 7px;
}
}
}
2019-02-24 22:31:05 +00:00
</style>