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

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

Loading…
Cancel
Save