pull/8/head
cwy 3 months ago
parent 12b1a5a49c
commit 9311154b5e

@ -1,8 +1,13 @@
<template> <template>
<!-- 整体的应用容器 div -->
<div class="app-container"> <div class="app-container">
<!-- 操作区域的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never"> <el-card class="operate-container" shadow="never">
<!-- el-icon-tickets 图标设置了顶部外边距为 5px -->
<i class="el-icon-tickets" style="margin-top: 5px"></i> <i class="el-icon-tickets" style="margin-top: 5px"></i>
<!-- 数据列表文字提示设置了顶部外边距为 5px -->
<span style="margin-top: 5px">数据列表</span> <span style="margin-top: 5px">数据列表</span>
<!-- 添加按钮设置了类名点击时调用 handleAddMenu 方法按钮大小为 mini -->
<el-button <el-button
class="btn-add" class="btn-add"
@click="handleAddMenu()" @click="handleAddMenu()"
@ -10,26 +15,34 @@
添加 添加
</el-button> </el-button>
</el-card> </el-card>
<!-- 表格容器 div -->
<div class="table-container"> <div class="table-container">
<!-- el-table 组件用于展示数据表格设置了引用名宽度绑定的数据列表加载状态绑定以及边框等属性 -->
<el-table ref="menuTable" <el-table ref="menuTable"
style="width: 100%" style="width: 100%"
:data="list" :data="list"
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>
<!-- 表格列标签为菜单名称内容居中对齐通过插槽作用域展示对应行数据的 title 属性 -->
<el-table-column label="菜单名称" align="center"> <el-table-column label="菜单名称" align="center">
<template slot-scope="scope">{{scope.row.title}}</template> <template slot-scope="scope">{{scope.row.title}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为菜单级数设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 level 属性并使用 levelFilter 过滤器对数据进行格式化转换 -->
<el-table-column label="菜单级数" width="100" align="center"> <el-table-column label="菜单级数" width="100" align="center">
<template slot-scope="scope">{{scope.row.level | levelFilter}}</template> <template slot-scope="scope">{{scope.row.level | levelFilter}}</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>
<!-- 表格列标签为前端图标设置了宽度和内容居中对齐通过插槽作用域使用 svg-icon 组件展示对应行数据的 icon 属性对应的图标 -->
<el-table-column label="前端图标" width="100" align="center"> <el-table-column label="前端图标" width="100" align="center">
<template slot-scope="scope"><svg-icon :icon-class="scope.row.icon"></svg-icon></template> <template slot-scope="scope"><svg-icon :icon-class="scope.row.icon"></svg-icon></template>
</el-table-column> </el-table-column>
<!-- 表格列标签为是否显示设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 hidden 属性并使用 el-switch 组件进行切换操作绑定了相关的事件和值 -->
<el-table-column label="是否显示" width="100" align="center"> <el-table-column label="是否显示" width="100" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
@ -40,9 +53,11 @@
</el-switch> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为排序设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 sort 属性 -->
<el-table-column label="排序" width="100" align="center"> <el-table-column label="排序" width="100" align="center">
<template slot-scope="scope">{{scope.row.sort }}</template> <template slot-scope="scope">{{scope.row.sort }}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为设置设置了宽度和内容居中对齐通过插槽作用域展示查看下级按钮按钮根据条件判断是否禁用通过 disableNextLevel 过滤器点击时调用 handleShowNextLevel 方法 -->
<el-table-column label="设置" width="120" align="center"> <el-table-column label="设置" width="120" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
@ -53,6 +68,7 @@
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示编辑和删除按钮分别点击时调用 handleUpdate handleDelete 方法 -->
<el-table-column label="操作" width="200" align="center"> <el-table-column label="操作" width="200" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
@ -69,7 +85,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"
@ -83,114 +101,144 @@
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import {fetchList,deleteMenu,updateMenu,updateHidden} from '@/api/menu' // @/api/menu API
import {fetchList,deleteMenu,updateMenu,updateHidden} from '@/api/menu';
export default { export default {
name: "menuList", name: "menuList",
data() { data() {
return { return {
list: null, //
total: null, list: null,
listLoading: true, //
listQuery: { total: null,
pageNum: 1, // true
pageSize: 5 listLoading: true,
}, //
parentId: 0 listQuery: {
pageNum: 1,
pageSize: 5
},
// ID 0
parentId: 0
}
},
created() {
// ID
this.resetParentId();
this.getList();
},
watch: {
$route(route) {
// ID
//
this.resetParentId();
this.getList();
}
},
methods: {
resetParentId(){
// 1 parentId
this.listQuery.pageNum = 1;
if (this.$route.query.parentId!= null) {
// ID parentId
this.parentId = this.$route.query.parentId;
} else {
// ID 0
this.parentId = 0;
} }
}, },
created() { handleAddMenu() {
this.resetParentId(); // /ums/addMenu
this.$router.push('/ums/addMenu');
},
getList() {
//
this.listLoading = true;
// API ID
fetchList(this.parentId, this.listQuery).then(response => {
//
this.listLoading = false;
// list
this.list = response.data.list;
// total
this.total = response.data.total;
});
},
handleSizeChange(val) {
// 1
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList(); this.getList();
}, },
watch: { handleCurrentChange(val) {
$route(route) { //
this.resetParentId(); this.listQuery.pageNum = val;
this.getList(); this.getList();
}
}, },
methods: { handleHiddenChange(index, row) {
resetParentId(){ // el-switch API ID
this.listQuery.pageNum = 1; // 1000
if (this.$route.query.parentId != null) { updateHidden(row.id,{hidden:row.hidden}).then(response=>{
this.parentId = this.$route.query.parentId; this.$message({
} else { message: '修改成功',
this.parentId = 0; type: 'success',
} duration: 1000
},
handleAddMenu() {
this.$router.push('/ums/addMenu');
},
getList() {
this.listLoading = true;
fetchList(this.parentId, this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
}); });
}, });
handleSizeChange(val) { },
this.listQuery.pageNum = 1; handleShowNextLevel(index, row) {
this.listQuery.pageSize = val; // /ums/menu ID parentId
this.getList(); //
}, this.$router.push({path: '/ums/menu', query: {parentId: row.id}})
handleCurrentChange(val) { },
this.listQuery.pageNum = val; handleUpdate(index, row) {
this.getList(); // /ums/updateMenu ID id
}, //
handleHiddenChange(index, row) { this.$router.push({path:'/ums/updateMenu',query:{id:row.id}});
updateHidden(row.id,{hidden:row.hidden}).then(response=>{ },
handleDelete(index, row) {
//
this.$confirm('是否要删除该菜单', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// API ID
// 1000
deleteMenu(row.id).then(response => {
this.$message({ this.$message({
message: '修改成功', message: '删除成功',
type: 'success', type: 'success',
duration: 1000 duration: 1000
}); });
this.getList();
}); });
}, });
handleShowNextLevel(index, row) { }
this.$router.push({path: '/ums/menu', query: {parentId: row.id}}) },
}, filters: {
handleUpdate(index, row) { levelFilter(value) {
this.$router.push({path:'/ums/updateMenu',query:{id:row.id}}); // value 0 1
}, if (value === 0) {
handleDelete(index, row) { return '一级';
this.$confirm('是否要删除该菜单', '提示', { } else if (value === 1) {
confirmButtonText: '确定', return '二级';
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteMenu(row.id).then(response => {
this.$message({
message: '删除成功',
type: 'success',
duration: 1000
});
this.getList();
});
});
} }
}, },
filters: { disableNextLevel(value) {
levelFilter(value) { // value 0 false true
if (value === 0) { if (value === 0) {
return '一级'; return false;
} else if (value === 1) { } else {
return '二级'; return true;
}
},
disableNextLevel(value) {
if (value === 0) {
return false;
} else {
return true;
}
} }
} }
} }
}
</script> </script>
<style scoped> <style scoped>
/*
scoped 属性表示样式仅作用于当前组件内的元素避免样式冲突 */
</style> </style>

Loading…
Cancel
Save