pull/8/head
cwy 8 months ago
parent a929473bfa
commit bf8b710171

@ -1,27 +1,39 @@
<template>  <template>
<!-- 整体的应用容器 div -->
<div class="app-container"> <div class="app-container">
<!-- 操作区域的卡片容器设置了阴影效果为无 -->
<el-card shadow="never" class="operate-container"> <el-card shadow="never" class="operate-container">
<!-- 图标元素使用了 el-icon-tickets 图标 -->
<i class="el-icon-tickets"></i> <i class="el-icon-tickets"></i>
<!-- 文字提示显示数据列表字样 -->
<span>数据列表</span> <span>数据列表</span>
<!-- 添加按钮设置了按钮大小为 mini添加了自定义类名 btn-add点击时调用 handleAdd 方法 -->
<el-button size="mini" class="btn-add" @click="handleAdd()"></el-button> <el-button size="mini" class="btn-add" @click="handleAdd()"></el-button>
</el-card> </el-card>
<!-- 表格容器 div用于放置展示数据的表格 -->
<div class="table-container"> <div class="table-container">
<!-- el-table 组件用于展示数据列表设置了引用名绑定的数据表格宽度加载状态绑定以及边框等属性 -->
<el-table ref="resourceCategoryTable" <el-table ref="resourceCategoryTable"
: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>
<!-- 表格列标签为创建时间内容居中对齐通过插槽作用域展示对应行数据的 createTime 属性并使用 formatDateTime 过滤器对时间进行格式化展示 -->
<el-table-column label="创建时间" align="center"> <el-table-column label="创建时间" 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>
<!-- 表格列标签为排序内容居中对齐通过插槽作用域展示对应行数据的 sort 属性 -->
<el-table-column label="排序" align="center"> <el-table-column label="排序" align="center">
<template slot-scope="scope">{{scope.row.sort}}</template> <template slot-scope="scope">{{scope.row.sort}}</template>
</el-table-column> </el-table-column>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示编辑和删除按钮分别点击时调用 handleUpdate handleDelete 方法 -->
<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"
@ -36,20 +48,25 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<!-- el-dialog 对话框组件设置了标题为添加分类绑定了显示状态设置了宽度 -->
<el-dialog <el-dialog
title="添加分类" title="添加分类"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
width="40%"> width="40%">
<!-- 对话框内的表单绑定了 resourceCategory 数据对象设置了表单引用标签宽度和大小 -->
<el-form :model="resourceCategory" <el-form :model="resourceCategory"
ref="resourceCategoryForm" ref="resourceCategoryForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 表单项目标签为名称输入框双向绑定 resourceCategory.name并设置了宽度 -->
<el-form-item label="名称:"> <el-form-item label="名称:">
<el-input v-model="resourceCategory.name" style="width: 250px"></el-input> <el-input v-model="resourceCategory.name" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为排序输入框双向绑定 resourceCategory.sort并设置了宽度 -->
<el-form-item label="排序:"> <el-form-item label="排序:">
<el-input v-model="resourceCategory.sort" style="width: 250px"></el-input> <el-input v-model="resourceCategory.sort" style="width: 250px"></el-input>
</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>
@ -58,99 +75,128 @@
</div> </div>
</template> </template>
<script> <script>
import {listAllCate,createResourceCategory,updateResourceCategory,deleteResourceCategory} from '@/api/resourceCategory'; // @/api/resourceCategory API
import {formatDate} from '@/utils/date'; import {listAllCate,createResourceCategory,updateResourceCategory,deleteResourceCategory} from '@/api/resourceCategory';
const defaultResourceCategory={ // @/utils/date
name:null, import {formatDate} from '@/utils/date';
sort:0
}; // null 0
export default { const defaultResourceCategory={
name: 'resourceCategoryList', name:null,
data() { sort:0
return { };
list: null,
listLoading: false, export default {
dialogVisible:false, name: 'resourceCategoryList',
isEdit:false, data() {
resourceCategory:Object.assign({},defaultResourceCategory) return {
// null API
list: null,
// false
listLoading: false,
// / false
dialogVisible:false,
// false
isEdit:false,
// defaultResourceCategory
resourceCategory:Object.assign({},defaultResourceCategory)
}
},
created() {
//
this.getList();
},
filters: {
formatDateTime(time) {
// 'N/A'
if (time == null || time === '') {
return 'N/A';
} }
// Date 便
let date = new Date(time);
// 使 formatDate
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
}
},
methods: {
handleAdd() {
// /isEdit false resourceCategory
this.dialogVisible = true;
this.isEdit = false;
this.resourceCategory = Object.assign({},defaultResourceCategory);
}, },
created() { handleUpdate(index,row){
this.getList(); // /isEdit true resourceCategory
this.dialogVisible = true;
this.isEdit = true;
this.resourceCategory = Object.assign({},row);
}, },
filters:{ handleDelete(index,row){
formatDateTime(time) { //
if (time == null || time === '') { this.$confirm('是否要删除该分类?', '提示', {
return 'N/A'; confirmButtonText: '确定',
} cancelButtonText: '取消',
let date = new Date(time); type: 'warning'
return formatDate(date, 'yyyy-MM-dd hh:mm:ss') }).then(() => {
} // API id
//
deleteResourceCategory(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
}, },
methods: { handleDialogConfirm() {
handleAdd() { // /
this.dialogVisible = true; this.$confirm('是否要确认?', '提示', {
this.isEdit = false; confirmButtonText: '确定',
this.resourceCategory = Object.assign({},defaultResourceCategory); cancelButtonText: '取消',
}, type: 'warning'
handleUpdate(index,row){ }).then(() => {
this.dialogVisible = true; // isEdit true
this.isEdit = true; if (this.isEdit) {
this.resourceCategory = Object.assign({},row); // API id resourceCategory
}, //
handleDelete(index,row){ updateResourceCategory(this.resourceCategory.id,this.resourceCategory).then(response => {
this.$confirm('是否要删除该分类?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteResourceCategory(row.id).then(response => {
this.$message({ this.$message({
type: 'success', message: '修改成功!',
message: '删除成功!' type: 'success'
}); });
this.dialogVisible =false;
this.getList(); this.getList();
}); })
}); } else {
}, // API resourceCategory
handleDialogConfirm() { //
this.$confirm('是否要确认?', '提示', { createResourceCategory(this.resourceCategory).then(response => {
confirmButtonText: '确定', this.$message({
cancelButtonText: '取消', message: '添加成功!',
type: 'warning' type: 'success'
}).then(() => { });
if (this.isEdit) { this.dialogVisible =false;
updateResourceCategory(this.resourceCategory.id,this.resourceCategory).then(response => { this.getList();
this.$message({ })
message: '修改成功!', }
type: 'success' })
}); },
this.dialogVisible =false; getList() {
this.getList(); //
}) this.listLoading = true;
} else { // API API
createResourceCategory(this.resourceCategory).then(response => { listAllCate({}).then(response => {
this.$message({ //
message: '添加成功!', this.listLoading = false;
type: 'success' // list
}); this.list = response.data;
this.dialogVisible =false; });
this.getList();
})
}
})
},
getList() {
this.listLoading = true;
listAllCate({}).then(response => {
this.listLoading = false;
this.list = response.data;
});
}
} }
} }
}
</script> </script>
<style> <style>
/* CSS resourceCategoryList
例如设置表格样式对话框样式按钮样式以及整体布局相关的样式等来美化组件的外观显示效果 */
</style> </style>

Loading…
Cancel
Save