2020-08-11 14:43:53 +08:00
|
|
|
<template>
|
|
|
|
<el-row>
|
|
|
|
<el-col style="margin-bottom: 1rem;">
|
|
|
|
<el-breadcrumb separator-class="el-icon-arrow-right">
|
|
|
|
<el-breadcrumb-item :to="{ path: '/admin/dashboard' }">首页</el-breadcrumb-item>
|
|
|
|
<el-breadcrumb-item>用户管理</el-breadcrumb-item>
|
|
|
|
</el-breadcrumb>
|
|
|
|
</el-col>
|
|
|
|
<el-col>
|
|
|
|
<el-table
|
|
|
|
:data="users"
|
|
|
|
style="width: 100%">
|
|
|
|
<el-table-column
|
|
|
|
label="#"
|
|
|
|
width="40"
|
|
|
|
prop="idUser">
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column
|
|
|
|
label="头像"
|
|
|
|
width="60"
|
|
|
|
prop="avatarUrl">
|
|
|
|
<template slot-scope="scope">
|
|
|
|
<el-avatar v-if="scope.row.avatarUrl" size="medium" :src="scope.row.avatarUrl"></el-avatar>
|
|
|
|
<el-avatar v-else size="medium" src="https://rymcu.com/article/1578475481946.png"></el-avatar>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column
|
|
|
|
label="昵称"
|
|
|
|
width="180"
|
|
|
|
prop="nickname">
|
|
|
|
<template slot-scope="scope">
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" type="primary" @click="onRouter('user', scope.row.nickname)" :underline="false">{{
|
2020-08-11 14:43:53 +08:00
|
|
|
scope.row.nickname }}
|
|
|
|
</el-link>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column
|
|
|
|
label="账号"
|
|
|
|
width="180"
|
|
|
|
prop="account">
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column
|
|
|
|
label="注册时间"
|
|
|
|
width="180"
|
|
|
|
prop="createdTime">
|
|
|
|
</el-table-column>
|
2020-09-08 09:48:31 +08:00
|
|
|
<el-table-column
|
|
|
|
label="最后登录时间"
|
|
|
|
width="180"
|
|
|
|
prop="lastLoginTime">
|
|
|
|
</el-table-column>
|
2020-08-11 14:43:53 +08:00
|
|
|
<el-table-column
|
|
|
|
label="状态"
|
|
|
|
width="180"
|
|
|
|
prop="status">
|
|
|
|
<template slot-scope="scope">
|
|
|
|
<el-tag type="primary" disable-transitions>
|
|
|
|
{{scope.row.status === '0' ? '正常' : '禁用'}}
|
|
|
|
</el-tag>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
<el-table-column label="操作">
|
|
|
|
<template slot-scope="scope">
|
2020-09-28 00:37:14 +08:00
|
|
|
<el-button size="mini" @click="handleRole(scope.$index, scope.row)" plain>授权</el-button>
|
2020-08-11 14:43:53 +08:00
|
|
|
<el-button v-if="scope.row.status == 1" size="mini" type="primary"
|
2020-09-28 00:37:14 +08:00
|
|
|
@click="toggleStatus(scope.$index, scope.row)" plain>启用
|
2020-08-11 14:43:53 +08:00
|
|
|
</el-button>
|
2020-09-28 00:37:14 +08:00
|
|
|
<el-button v-else size="mini" type="danger" @click="toggleStatus(scope.$index, scope.row)" plain>禁用</el-button>
|
2020-08-11 14:43:53 +08:00
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
</el-col>
|
|
|
|
<el-col>
|
|
|
|
<el-pagination
|
2020-10-20 22:28:21 +08:00
|
|
|
:hide-on-single-page="true"
|
2020-08-11 14:43:53 +08:00
|
|
|
@size-change="handleSizeChange"
|
|
|
|
@current-change="handleCurrentChange"
|
|
|
|
:current-page="pagination.currentPage"
|
|
|
|
:page-sizes="[10, 20, 50, 100]"
|
|
|
|
:page-size="pagination.pageSize"
|
|
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
|
|
:total="pagination.total">
|
|
|
|
</el-pagination>
|
|
|
|
</el-col>
|
|
|
|
<el-col>
|
|
|
|
<el-dialog :visible.sync="dialogVisible">
|
|
|
|
<el-form>
|
|
|
|
<el-form-item>
|
|
|
|
<el-radio-group v-model="idRole">
|
|
|
|
<el-radio v-for="role in roles" :key="role.idRole" border :label="role.idRole">{{ role.name }}</el-radio>
|
|
|
|
</el-radio-group>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
|
<el-button type="primary" @click="updateRole">确 定</el-button>
|
|
|
|
</div>
|
|
|
|
</el-dialog>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {mapState} from 'vuex';
|
|
|
|
|
|
|
|
export default {
|
2020-09-08 08:00:32 +08:00
|
|
|
name: "users",
|
2020-08-11 14:43:53 +08:00
|
|
|
fetch({store, params, error}) {
|
|
|
|
return Promise.all([
|
|
|
|
store
|
|
|
|
.dispatch('admin/fetchUsers', params)
|
|
|
|
.catch(err => error({statusCode: 404})),
|
|
|
|
store.dispatch("admin/fetchRoles")
|
|
|
|
])
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState({
|
|
|
|
users: state => state.admin.user.users,
|
|
|
|
pagination: state => state.admin.user.pagination,
|
|
|
|
roles: state => state.admin.role.roles
|
|
|
|
})
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
order: 'desc',
|
|
|
|
idRole: 0,
|
|
|
|
idUser: 0,
|
|
|
|
dialogVisible: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onRouter(name, data) {
|
|
|
|
this.$router.push({
|
|
|
|
path: `/${name}/${data}`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
handleRole(index, user) {
|
|
|
|
let _ts = this;
|
2020-10-18 17:54:52 +08:00
|
|
|
_ts.$set(_ts, 'idUser', user.idUser);
|
|
|
|
_ts.$axios.$get('/api/admin/user/' + user.idUser + '/role')
|
2020-08-11 14:43:53 +08:00
|
|
|
.then(function (res) {
|
|
|
|
_ts.$set(_ts, 'dialogVisible', true);
|
|
|
|
_ts.$set(_ts, 'idRole', res[0].idRole);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
toggleStatus(index, user) {
|
|
|
|
let _ts = this;
|
|
|
|
let title, status;
|
2020-10-18 17:54:52 +08:00
|
|
|
if (user.status == 0) {
|
2020-08-11 14:43:53 +08:00
|
|
|
title = '禁用';
|
|
|
|
status = 1;
|
|
|
|
} else {
|
|
|
|
title = '启用';
|
|
|
|
status = 0;
|
|
|
|
}
|
2020-10-18 17:54:52 +08:00
|
|
|
_ts.$confirm('确定' + title + '用户' + user.nickname + '(' + user.account + ')?', '提示', {
|
2020-08-11 14:43:53 +08:00
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning'
|
|
|
|
}).then(() => {
|
|
|
|
_ts.$axios.$patch('/api/admin/user/update-status', {
|
2020-10-18 17:54:52 +08:00
|
|
|
idUser: user.idUser,
|
2020-08-11 14:43:53 +08:00
|
|
|
status: status
|
|
|
|
}).then(function (res) {
|
|
|
|
if (res && res.message) {
|
|
|
|
_ts.$message.error(res.message);
|
|
|
|
} else {
|
|
|
|
_ts.$message({
|
|
|
|
type: 'success',
|
|
|
|
message: title + '成功!'
|
|
|
|
});
|
|
|
|
_ts.handleCurrentChange(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).catch(() => {
|
|
|
|
_ts.$message({
|
|
|
|
type: 'info',
|
|
|
|
message: '已取消'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2020-09-15 22:15:02 +08:00
|
|
|
handleSizeChange(pageSize) {
|
2020-08-11 14:43:53 +08:00
|
|
|
let _ts = this;
|
|
|
|
_ts.$store.dispatch('admin/fetchUsers', {
|
2020-09-15 22:15:02 +08:00
|
|
|
page: _ts.pagination.currentPage,
|
|
|
|
rows: pageSize
|
2020-08-11 14:43:53 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
handleCurrentChange(page) {
|
|
|
|
let _ts = this;
|
|
|
|
_ts.$store.dispatch('admin/fetchUsers', {
|
2020-09-15 22:15:02 +08:00
|
|
|
page: page,
|
|
|
|
rows: _ts.pagination.pageSize
|
2020-08-11 14:43:53 +08:00
|
|
|
})
|
|
|
|
},
|
|
|
|
updateRole() {
|
|
|
|
let _ts = this;
|
|
|
|
let data = {
|
|
|
|
idUser: _ts.idUser,
|
|
|
|
idRole: _ts.idRole
|
|
|
|
};
|
|
|
|
_ts.$axios.$patch('/api/admin/user/update-role', data).then(function (res) {
|
|
|
|
if (res && res.message) {
|
|
|
|
_ts.$message.error(res.message);
|
|
|
|
} else {
|
|
|
|
_ts.$message({
|
|
|
|
message: '授权成功',
|
|
|
|
type: 'success'
|
|
|
|
});
|
|
|
|
_ts.$set(_ts, 'dialogVisible', false);
|
|
|
|
_ts.$set(_ts, 'idUser', 0);
|
|
|
|
_ts.$set(_ts, 'idRole', 0);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$store.commit("setActiveMenu", "admin-user");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|