pull/2/head
cwy 3 months ago
parent 1ed3d12a51
commit 6f77f0cd3b

@ -1,9 +1,14 @@
<template>  <template>
<!-- 整体的应用容器 div -->
<div class="app-container"> <div class="app-container">
<!-- 筛选搜索区域的卡片容器设置了阴影效果为无 -->
<el-card class="filter-container" shadow="never"> <el-card class="filter-container" shadow="never">
<div> <div>
<!-- 搜索图标 -->
<i class="el-icon-search"></i> <i class="el-icon-search"></i>
<!-- 筛选搜索的文字提示 -->
<span>筛选搜索</span> <span>筛选搜索</span>
<!-- 查询搜索按钮设置了样式为右浮动按钮类型为主要primary点击时调用 handleSearchList 方法按钮大小为 small -->
<el-button <el-button
style="float:right" style="float:right"
type="primary" type="primary"
@ -11,6 +16,7 @@
size="small"> size="small">
查询搜索 查询搜索
</el-button> </el-button>
<!-- 重置按钮设置了样式为右浮动且距离右侧 15px点击时调用 handleResetSearch 方法按钮大小为 small -->
<el-button <el-button
style="float:right;margin-right: 15px" style="float:right;margin-right: 15px"
@click="handleResetSearch()" @click="handleResetSearch()"
@ -19,41 +25,57 @@
</el-button> </el-button>
</div> </div>
<div style="margin-top: 15px"> <div style="margin-top: 15px">
<!-- 内联表单绑定了 listQuery 数据对象表单大小为 small标签宽度为 140px -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px"> <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单项目标签为输入搜索 -->
<el-form-item label="输入搜索:"> <el-form-item label="输入搜索:">
<!-- 输入框双向绑定 listQuery.keyword设置了类名占位符以及可清空功能 -->
<el-input v-model="listQuery.keyword" class="input-width" placeholder="帐号/姓名" clearable></el-input> <el-input v-model="listQuery.keyword" class="input-width" placeholder="帐号/姓名" clearable></el-input>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
</el-card> </el-card>
<!-- 操作区域的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 数据列表的文字提示 -->
<span>数据列表</span> <span>数据列表</span>
<!-- 添加按钮大小为 mini设置了类名点击时调用 handleAdd 方法设置了左侧外边距为 20px -->
<el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加</el-button> <el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加</el-button>
</el-card> </el-card>
<!-- 表格容器 div -->
<div class="table-container"> <div class="table-container">
<!-- el-table 组件绑定了 list 数据用于展示表格内容设置了加载状态绑定宽度边框等属性 -->
<el-table ref="adminTable" <el-table ref="adminTable"
:data="list" :data="list"
style="width: 100%;" style="width: 100%;"
v-loading="listLoading" border> v-loading="listLoading" border>
<!-- 表格列标签为编号设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 id 属性 -->
<el-table-column label="编号" width="100" align="center"> <el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template> <template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为帐号内容居中对齐通过插槽作用域展示对应行数据的 username 属性 -->
<el-table-column label="帐号" align="center"> <el-table-column label="帐号" align="center">
<template slot-scope="scope">{{scope.row.username}}</template> <template slot-scope="scope">{{scope.row.username}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为姓名内容居中对齐通过插槽作用域展示对应行数据的 nickName 属性 -->
<el-table-column label="姓名" align="center"> <el-table-column label="姓名" align="center">
<template slot-scope="scope">{{scope.row.nickName}}</template> <template slot-scope="scope">{{scope.row.nickName}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为邮箱内容居中对齐通过插槽作用域展示对应行数据的 email 属性 -->
<el-table-column label="邮箱" align="center"> <el-table-column label="邮箱" align="center">
<template slot-scope="scope">{{scope.row.email}}</template> <template slot-scope="scope">{{scope.row.email}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为添加时间设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 createTime 属性并使用了 formatDateTime 过滤器进行格式化 -->
<el-table-column label="添加时间" width="160" align="center"> <el-table-column label="添加时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatDateTime}}</template> <template slot-scope="scope">{{scope.row.createTime | formatDateTime}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为最后登录设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 loginTime 属性并使用了 formatDateTime 过滤器进行格式化 -->
<el-table-column label="最后登录" width="160" align="center"> <el-table-column label="最后登录" width="160" align="center">
<template slot-scope="scope">{{scope.row.loginTime | formatDateTime}}</template> <template slot-scope="scope">{{scope.row.loginTime | formatDateTime}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为是否启用设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 status 属性并使用 el-switch 组件进行切换操作绑定了相关的事件和值 -->
<el-table-column label="是否启用" width="140" align="center"> <el-table-column label="是否启用" width="140" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -64,6 +86,7 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示操作按钮包括分配角色编辑删除按钮分别绑定了对应的点击事件方法 -->
<el-table-column label="操作" width="180" align="center"> <el-table-column label="操作" width="180" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button size="mini" <el-button size="mini"
@ -83,7 +106,9 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- 分页容器 div -->
<div class="pagination-container"> <div class="pagination-container">
<!-- el-pagination 分页组件设置了背景色相关页面切换事件绑定布局样式当前页每页数量可选每页数量数组以及总记录数等属性 -->
<el-pagination <el-pagination
background background
@size-change="handleSizeChange" @size-change="handleSizeChange"
@ -95,31 +120,39 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- 编辑/添加用户的对话框组件根据 isEdit 变量来动态设置标题绑定了显示状态设置了宽度 -->
<el-dialog <el-dialog
:title="isEdit?'编辑用户':'添加用户'" :title="isEdit?'编辑用户':'添加用户'"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
width="40%"> width="40%">
<!-- 对话框内的表单绑定了 admin 数据对象设置了表单引用标签宽度和大小 -->
<el-form :model="admin" <el-form :model="admin"
ref="adminForm" ref="adminForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 表单项目标签为帐号输入框双向绑定 admin.username -->
<el-form-item label="帐号:"> <el-form-item label="帐号:">
<el-input v-model="admin.username" style="width: 250px"></el-input> <el-input v-model="admin.username" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为姓名输入框双向绑定 admin.nickName -->
<el-form-item label="姓名:"> <el-form-item label="姓名:">
<el-input v-model="admin.nickName" style="width: 250px"></el-input> <el-input v-model="admin.nickName" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为邮箱输入框双向绑定 admin.email -->
<el-form-item label="邮箱:"> <el-form-item label="邮箱:">
<el-input v-model="admin.email" style="width: 250px"></el-input> <el-input v-model="admin.email" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为密码输入框双向绑定 admin.password设置了密码类型 -->
<el-form-item label="密码:"> <el-form-item label="密码:">
<el-input v-model="admin.password" type="password" style="width: 250px"></el-input> <el-input v-model="admin.password" type="password" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为备注输入框双向绑定 admin.note设置了文本域类型和行数 -->
<el-form-item label="备注:"> <el-form-item label="备注:">
<el-input v-model="admin.note" <el-input v-model="admin.note"
type="textarea" type="textarea"
:rows="5" :rows="5"
style="width: 250px"></el-input> style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为是否启用使用单选按钮组绑定 admin.status -->
<el-form-item label="是否启用:"> <el-form-item label="是否启用:">
<el-radio-group v-model="admin.status"> <el-radio-group v-model="admin.status">
<el-radio :label="1"></el-radio> <el-radio :label="1"></el-radio>
@ -127,15 +160,18 @@
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 对话框底部的按钮区域通过插槽定义了取消和确定按钮分别绑定了对应的点击事件 -->
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small"> </el-button> <el-button @click="dialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button> <el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<!-- 分配角色的对话框组件设置了标题绑定了显示状态和宽度 -->
<el-dialog <el-dialog
title="分配角色" title="分配角色"
:visible.sync="allocDialogVisible" :visible.sync="allocDialogVisible"
width="30%"> width="30%">
<!-- 多选的下拉选择框绑定了 allocRoleIds 数据设置了占位符大小和宽度通过循环渲染选项 -->
<el-select v-model="allocRoleIds" multiple placeholder="请选择" size="small" style="width: 80%"> <el-select v-model="allocRoleIds" multiple placeholder="请选择" size="small" style="width: 80%">
<el-option <el-option
v-for="item in allRoleList" v-for="item in allRoleList"
@ -144,6 +180,7 @@
:value="item.id"> :value="item.id">
</el-option> </el-option>
</el-select> </el-select>
<!-- 对话框底部的按钮区域通过插槽定义了取消和确定按钮分别绑定了对应的点击事件 -->
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="allocDialogVisible = false" size="small"> </el-button> <el-button @click="allocDialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleAllocDialogConfirm()" size="small"> </el-button> <el-button type="primary" @click="handleAllocDialogConfirm()" size="small"> </el-button>
@ -152,15 +189,20 @@
</div> </div>
</template> </template>
<script> <script>
// @/api/login API
import {fetchList,createAdmin,updateAdmin,updateStatus,deleteAdmin,getRoleByAdmin,allocRole} from '@/api/login'; import {fetchList,createAdmin,updateAdmin,updateStatus,deleteAdmin,getRoleByAdmin,allocRole} from '@/api/login';
// @/api/role API
import {fetchAllRoleList} from '@/api/role'; import {fetchAllRoleList} from '@/api/role';
// @/utils/date
import {formatDate} from '@/utils/date'; import {formatDate} from '@/utils/date';
//
const defaultListQuery = { const defaultListQuery = {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
keyword: null keyword: null
}; };
// id
const defaultAdmin = { const defaultAdmin = {
id: null, id: null,
username: null, username: null,
@ -170,64 +212,87 @@
note: null, note: null,
status: 1 status: 1
}; };
export default { export default {
name: 'adminList', name: 'adminList',
data() { data() {
return { return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery), listQuery: Object.assign({}, defaultListQuery),
//
list: null, list: null,
//
total: null, total: null,
//
listLoading: false, listLoading: false,
// /
dialogVisible: false, dialogVisible: false,
// defaultAdmin
admin: Object.assign({}, defaultAdmin), admin: Object.assign({}, defaultAdmin),
//
isEdit: false, isEdit: false,
//
allocDialogVisible: false, allocDialogVisible: false,
// ID ID
allocRoleIds:[], allocRoleIds:[],
//
allRoleList:[], allRoleList:[],
// ID
allocAdminId:null allocAdminId:null
} }
}, },
created() { created() {
//
this.getList(); this.getList();
this.getAllRoleList(); this.getAllRoleList();
}, },
filters: { filters: {
formatDateTime(time) { formatDateTime(time) {
// null 'N/A'
if (time == null || time === '') { if (time == null || time === '') {
return 'N/A'; return 'N/A';
} }
// Date
let date = new Date(time); let date = new Date(time);
// 使 formatDate
return formatDate(date, 'yyyy-MM-dd hh:mm:ss') return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
} }
}, },
methods: { methods: {
handleResetSearch() { handleResetSearch() {
//
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery = Object.assign({}, defaultListQuery);
}, },
handleSearchList() { handleSearchList() {
// 1
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
handleSizeChange(val) { handleSizeChange(val) {
// 1
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.listQuery.pageSize = val; this.listQuery.pageSize = val;
this.getList(); this.getList();
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
//
this.listQuery.pageNum = val; this.listQuery.pageNum = val;
this.getList(); this.getList();
}, },
handleAdd() { handleAdd() {
// /
this.dialogVisible = true; this.dialogVisible = true;
this.isEdit = false; this.isEdit = false;
this.admin = Object.assign({},defaultAdmin); this.admin = Object.assign({},defaultAdmin);
}, },
handleStatusChange(index, row) { handleStatusChange(index, row) {
//
this.$confirm('是否要修改该状态?', '提示', { this.$confirm('是否要修改该状态?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// API ID
updateStatus(row.id, {status: row.status}).then(response => { updateStatus(row.id, {status: row.status}).then(response => {
this.$message({ this.$message({
type: 'success', type: 'success',
@ -235,6 +300,7 @@
}); });
}); });
}).catch(() => { }).catch(() => {
//
this.$message({ this.$message({
type: 'info', type: 'info',
message: '取消修改' message: '取消修改'
@ -243,11 +309,13 @@
}); });
}, },
handleDelete(index, row) { handleDelete(index, row) {
//
this.$confirm('是否要删除该用户?', '提示', { this.$confirm('是否要删除该用户?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// API ID
deleteAdmin(row.id).then(response => { deleteAdmin(row.id).then(response => {
this.$message({ this.$message({
type: 'success', type: 'success',
@ -258,17 +326,22 @@
}); });
}, },
handleUpdate(index, row) { handleUpdate(index, row) {
// /
this.dialogVisible = true; this.dialogVisible = true;
this.isEdit = true; this.isEdit = true;
this.admin = Object.assign({},row); this.admin = Object.assign({},row);
}, },
handleDialogConfirm() { handleDialogConfirm() {
//
this.$confirm('是否要确认?', '提示', { this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
//
if (this.isEdit) { if (this.isEdit) {
// API ID
// /
updateAdmin(this.admin.id,this.admin).then(response => { updateAdmin(this.admin.id,this.admin).then(response => {
this.$message({ this.$message({
message: '修改成功!', message: '修改成功!',
@ -278,6 +351,8 @@
this.getList(); this.getList();
}) })
} else { } else {
// API
// /
createAdmin(this.admin).then(response => { createAdmin(this.admin).then(response => {
this.$message({ this.$message({
message: '添加成功!', message: '添加成功!',
@ -290,14 +365,20 @@
}) })
}, },
handleAllocDialogConfirm(){ handleAllocDialogConfirm(){
//
this.$confirm('是否要确认?', '提示', { this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// URLSearchParams
let params = new URLSearchParams(); let params = new URLSearchParams();
// ID
params.append("adminId", this.allocAdminId); params.append("adminId", this.allocAdminId);
// ID
params.append("roleIds", this.allocRoleIds); params.append("roleIds", this.allocRoleIds);
// API
//
allocRole(params).then(response => { allocRole(params).then(response => {
this.$message({ this.$message({
message: '分配成功!', message: '分配成功!',
@ -308,28 +389,43 @@
}) })
}, },
handleSelectRole(index,row){ handleSelectRole(index,row){
// ID
this.allocAdminId = row.id; this.allocAdminId = row.id;
//
this.allocDialogVisible = true; this.allocDialogVisible = true;
// ID
this.getRoleListByAdmin(row.id); this.getRoleListByAdmin(row.id);
}, },
getList() { getList() {
//
this.listLoading = true; this.listLoading = true;
// API
fetchList(this.listQuery).then(response => { fetchList(this.listQuery).then(response => {
//
this.listLoading = false; this.listLoading = false;
// list
this.list = response.data.list; this.list = response.data.list;
// total
this.total = response.data.total; this.total = response.data.total;
}); });
}, },
getAllRoleList() { getAllRoleList() {
// API
fetchAllRoleList().then(response => { fetchAllRoleList().then(response => {
// allRoleList 使
this.allRoleList = response.data; this.allRoleList = response.data;
}); });
}, },
getRoleListByAdmin(adminId) { getRoleListByAdmin(adminId) {
// API ID
getRoleByAdmin(adminId).then(response => { getRoleByAdmin(adminId).then(response => {
//
let allocRoleList = response.data; let allocRoleList = response.data;
// ID
this.allocRoleIds=[]; this.allocRoleIds=[];
//
if(allocRoleList!=null&&allocRoleList.length>0){ if(allocRoleList!=null&&allocRoleList.length>0){
// ID ID
for(let i=0;i<allocRoleList.length;i++){ for(let i=0;i<allocRoleList.length;i++){
this.allocRoleIds.push(allocRoleList[i].id); this.allocRoleIds.push(allocRoleList[i].id);
} }
@ -340,5 +436,3 @@
} }
</script> </script>
<style></style> <style></style>

Loading…
Cancel
Save