pull/8/head
cwy 7 months ago
parent fa3736d39b
commit d47e960b34

@ -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>
<!-- 搜索图标元素使用了 el-icon-search 图标 -->
<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,38 +25,52 @@
</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">
<!-- 表单项目标签为输入搜索内部的输入框双向绑定 listQuery.keyword设置了类名占位符以及可清空功能 -->
<el-form-item label="输入搜索:"> <el-form-item label="输入搜索:">
<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">
<!-- 图标元素使用了 el-icon-tickets 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 数据列表的文字提示 -->
<span>数据列表</span> <span>数据列表</span>
<!-- 添加按钮大小为 mini添加了自定义类名 btn-add点击时调用 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 组件用于展示角色数据列表设置了引用名绑定的数据表格宽度加载状态绑定以及边框等属性 -->
<el-table ref="roleTable" <el-table ref="roleTable"
: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>
<!-- 表格列标签为角色名称内容居中对齐通过插槽作用域展示对应行数据的 name 属性 -->
<el-table-column label="角色名称" align="center"> <el-table-column label="角色名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template> <template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为描述内容居中对齐通过插槽作用域展示对应行数据的 description 属性 -->
<el-table-column label="描述" align="center"> <el-table-column label="描述" align="center">
<template slot-scope="scope">{{scope.row.description}}</template> <template slot-scope="scope">{{scope.row.description}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为用户数设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 adminCount 属性 -->
<el-table-column label="用户数" width="100" align="center"> <el-table-column label="用户数" width="100" align="center">
<template slot-scope="scope">{{scope.row.adminCount}}</template> <template slot-scope="scope">{{scope.row.adminCount}}</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>
<!-- 表格列标签为是否启用设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 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
@ -61,6 +81,7 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示多个操作按钮包括分配菜单分配资源编辑和删除按钮分别绑定了对应的点击事件 -->
<el-table-column label="操作" width="160" align="center"> <el-table-column label="操作" width="160" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-row> <el-row>
@ -74,21 +95,23 @@
</el-button> </el-button>
</el-row> </el-row>
<el-row> <el-row>
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleUpdate(scope.$index, scope.row)"> @click="handleUpdate(scope.$index, scope.row)">
编辑 编辑
</el-button> </el-button>
<el-button size="mini" <el-button size="mini"
type="text" type="text"
@click="handleDelete(scope.$index, scope.row)">删除 @click="handleDelete(scope.$index, scope.row)">删除
</el-button> </el-button>
</el-row> </el-row>
</template> </template>
</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"
@ -100,22 +123,27 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
</div> </div>
<!-- el-dialog 对话框组件根据 isEdit 变量动态设置标题为编辑角色添加角色绑定了显示状态设置了宽度 -->
<el-dialog <el-dialog
:title="isEdit?'编辑角色':'添加角色'" :title="isEdit?'编辑角色':'添加角色'"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
width="40%"> width="40%">
<!-- 对话框内的表单绑定了 role 数据对象设置了表单引用标签宽度和大小 -->
<el-form :model="role" <el-form :model="role"
ref="roleForm" ref="roleForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 表单项目标签为角色名称输入框双向绑定 role.name并设置了宽度 -->
<el-form-item label="角色名称:"> <el-form-item label="角色名称:">
<el-input v-model="role.name" style="width: 250px"></el-input> <el-input v-model="role.name" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为描述输入框双向绑定 role.description设置了文本域类型和行数以及宽度 -->
<el-form-item label="描述:"> <el-form-item label="描述:">
<el-input v-model="role.description" <el-input v-model="role.description"
type="textarea" type="textarea"
:rows="5" :rows="5"
style="width: 250px"></el-input> style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为是否启用内部是一个单选按钮组双向绑定 role.status用于选择角色是否启用的状态 -->
<el-form-item label="是否启用:"> <el-form-item label="是否启用:">
<el-radio-group v-model="role.status"> <el-radio-group v-model="role.status">
<el-radio :label="1"></el-radio> <el-radio :label="1"></el-radio>
@ -123,6 +151,7 @@
</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>
@ -131,156 +160,194 @@
</div> </div>
</template> </template>
<script> <script>
import {fetchList,createRole,updateRole,updateStatus,deleteRole} from '@/api/role'; // '@/api/role'API
import {formatDate} from '@/utils/date'; import {fetchList, createRole, updateRole, updateStatus, deleteRole} from '@/api/role';
// '@/utils/date'formatDate
import {formatDate} from '@/utils/date';
// 15null
const defaultListQuery = {
pageNum: 1,
pageSize: 5,
keyword: null
};
// IDIDnull01
const defaultRole = {
id: null,
name: null,
description: null,
adminCount: 0,
status: 1
};
const defaultListQuery = { export default {
pageNum: 1, name: 'roleList',
pageSize: 5, data() {
keyword: null return {
}; // Object.assigndefaultListQuery
const defaultRole = { listQuery: Object.assign({}, defaultListQuery),
id: null, // nullAPI
name: null, list: null,
description: null, // nullAPI
adminCount: 0, total: null,
status: 1 // truefalsefalse
}; listLoading: false,
export default { // truefalsefalse
name: 'roleList', dialogVisible: false,
data() { // defaultRole
return { role: Object.assign({}, defaultRole),
listQuery: Object.assign({}, defaultListQuery), // truefalsefalse
list: null, isEdit: false
total: null, }
listLoading: false, },
dialogVisible: false, //
role: Object.assign({}, defaultRole), created() {
isEdit: false this.getList();
},
filters: {
// time
formatDateTime(time) {
// null'N/A'
if (time == null || time === '') {
return 'N/A';
} }
// JavaScriptDate
let date = new Date(time);
// formatDate'yyyy-MM-dd hh:mm:ss'
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
}
},
methods: {
//
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
}, },
created() { // 1
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
filters: { // 1val
formatDateTime(time) { handleSizeChange(val) {
if (time == null || time === '') { this.listQuery.pageNum = 1;
return 'N/A'; this.listQuery.pageSize = val;
} this.getList();
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
}
}, },
methods: { // val
handleResetSearch() { handleCurrentChange(val) {
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery.pageNum = val;
}, this.getList();
handleSearchList() { },
this.listQuery.pageNum = 1; //
this.getList(); handleAdd() {
}, this.dialogVisible = true;
handleSizeChange(val) { this.isEdit = false;
this.listQuery.pageNum = 1; this.role = Object.assign({}, defaultRole);
this.listQuery.pageSize = val; },
this.getList(); //
}, handleStatusChange(index, row) {
handleCurrentChange(val) { this.$confirm('是否要修改该状态?', '提示', {
this.listQuery.pageNum = val; confirmButtonText: '确定',
this.getList(); cancelButtonText: '取消',
}, type: 'warning'
handleAdd() { }).then(() => {
this.dialogVisible = true; // updateStatusID
this.isEdit = false; updateStatus(row.id, {status: row.status}).then(response => {
this.role = Object.assign({},defaultRole); this.$message({
}, type: 'success',
handleStatusChange(index, row) { message: '修改成功!'
this.$confirm('是否要修改该状态?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
updateStatus(row.id, {status: row.status}).then(response => {
this.$message({
type: 'success',
message: '修改成功!'
});
}); });
}).catch(() => { });
}).catch(() => {
//
this.$message({
type: 'info',
message: '取消修改'
});
this.getList();
});
},
//
handleDelete(index, row) {
this.$confirm('是否要删除该角色?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let ids = [];
// ID
ids.push(row.id);
let params = new URLSearchParams();
// IDURLSearchParamsAPI
params.append("ids", ids);
// deleteRole
deleteRole(params).then(response => {
this.$message({ this.$message({
type: 'info', type: 'success',
message: '取消修改' message: '删除成功!'
}); });
this.getList(); this.getList();
}); });
}, });
handleDelete(index, row) { },
this.$confirm('是否要删除该角色?', '提示', { //
confirmButtonText: '确定', handleUpdate(index, row) {
cancelButtonText: '取消', this.dialogVisible = true;
type: 'warning' this.isEdit = true;
}).then(() => { this.role = Object.assign({}, row);
let ids = []; },
ids.push(row.id); //
let params=new URLSearchParams(); handleDialogConfirm() {
params.append("ids",ids); this.$confirm('是否要确认?', '提示', '提示', {
deleteRole(params).then(response => { confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// updateRoleID
if (this.isEdit) {
updateRole(this.role.id, this.role).then(response => {
this.$message({ this.$message({
type: 'success', message: '修改成功!',
message: '删除成功!' type: 'success'
}); });
this.dialogVisible = false;
this.getList(); this.getList();
}); })
}); } else {
}, // createRole
handleUpdate(index, row) { createRole(this.role).then(response => {
this.dialogVisible = true; this.$message({
this.isEdit = true; message: '添加成功!',
this.role = Object.assign({},row); type: 'success'
}, });
handleDialogConfirm() { this.dialogVisible = false;
this.$confirm('是否要确认?', '提示', { this.getList();
confirmButtonText: '确定', })
cancelButtonText: '取消', }
type: 'warning' })
}).then(() => { },
if (this.isEdit) { // '/ums/allocMenu'ID
updateRole(this.role.id,this.role).then(response => { handleSelectMenu(index, row) {
this.$message({ this.$router.push({path: '/ums/allocMenu', query: {roleId: row.id}})
message: '修改成功!', },
type: 'success' // '/ums/allocResource'ID
}); handleSelectResource(index, row) {
this.dialogVisible =false; this.$router.push({path: '/ums/allocResource', query: {roleId: row.id}})
this.getList(); },
}) // fetchList
} else { getList() {
createRole(this.role).then(response => { this.listLoading = true;
this.$message({ fetchList(this.listQuery).then(response => {
message: '添加成功!', this.listLoading = false;
type: 'success' this.list = response.data.list;
}); this.total = response.data.total;
this.dialogVisible =false; });
this.getList();
})
}
})
},
handleSelectMenu(index,row){
this.$router.push({path:'/ums/allocMenu',query:{roleId:row.id}})
},
handleSelectResource(index,row){
this.$router.push({path:'/ums/allocResource',query:{roleId:row.id}})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
}
} }
} }
}
</script> </script>
<style></style> <style>
/* CSS updateMenu
来对组件的外观进行定制化显示 */
</style>

Loading…
Cancel
Save