pull/8/head
cwy 7 months ago
parent bf8b710171
commit 0fd8d33c0e

@ -1,9 +1,14 @@
<template> 
<template>
<!-- 整体的应用容器 div用于包裹页面内的各个功能模块 -->
<div class="app-container">
<!-- 筛选搜索区域的卡片容器设置了阴影效果为无 -->
<el-card class="filter-container" shadow="never">
<div>
<!-- 搜索图标元素使用了 el-icon-search 图标 -->
<i class="el-icon-search"></i>
<!-- 筛选搜索的文字提示 -->
<span>筛选搜索</span>
<!-- 查询搜索按钮设置了样式为右浮动按钮类型为主要primary点击时调用 handleSearchList 方法按钮大小为 small -->
<el-button
style="float:right"
type="primary"
@ -11,6 +16,7 @@
size="small">
查询搜索
</el-button>
<!-- 重置按钮设置了样式为右浮动且距离右侧 15px点击时调用 handleResetSearch 方法按钮大小为 small -->
<el-button
style="float:right;margin-right: 15px"
@click="handleResetSearch()"
@ -19,13 +25,17 @@
</el-button>
</div>
<div style="margin-top: 15px">
<!-- 内联表单绑定了 listQuery 数据对象表单大小为 small标签宽度为 140px用于设置筛选条件 -->
<el-form :inline="true" :model="listQuery" size="small" label-width="140px">
<!-- 表单项目标签为资源名称内部的输入框双向绑定 listQuery.nameKeyword设置了类名占位符以及可清空功能 -->
<el-form-item label="资源名称:">
<el-input v-model="listQuery.nameKeyword" class="input-width" placeholder="资源名称" clearable></el-input>
</el-form-item>
<!-- 表单项目标签为资源路径内部的输入框双向绑定 listQuery.urlKeyword设置了类名占位符以及可清空功能 -->
<el-form-item label="资源路径:">
<el-input v-model="listQuery.urlKeyword" class="input-width" placeholder="资源路径" clearable></el-input>
</el-form-item>
<!-- 表单项目标签为资源分类内部是一个下拉选择框双向绑定 listQuery.categoryId设置了占位符可清空以及类名通过循环渲染选项 -->
<el-form-item label="资源分类:">
<el-select v-model="listQuery.categoryId" placeholder="全部" clearable class="input-width">
<el-option v-for="item in categoryOptions"
@ -38,32 +48,45 @@
</el-form>
</div>
</el-card>
<!-- 操作区域的卡片容器设置了阴影效果为无 -->
<el-card class="operate-container" shadow="never">
<!-- 图标元素使用了 el-icon-tickets 图标 -->
<i class="el-icon-tickets"></i>
<!-- 数据列表的文字提示 -->
<span>数据列表</span>
<!-- 添加按钮大小为 mini添加了自定义类名 btn-add点击时调用 handleAdd 方法设置了左侧外边距为 20px -->
<el-button size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">添加</el-button>
<!-- 资源分类按钮大小为 mini添加了自定义类名 btn-add点击时调用 handleShowCategory 方法用于跳转到资源分类页面 -->
<el-button size="mini" class="btn-add" @click="handleShowCategory()"></el-button>
</el-card>
<!-- 表格容器 div用于放置展示资源数据的表格 -->
<div class="table-container">
<!-- el-table 组件用于展示资源数据列表设置了引用名绑定的数据表格宽度加载状态绑定以及边框等属性 -->
<el-table ref="resourceTable"
:data="list"
style="width: 100%;"
v-loading="listLoading" border>
<!-- 表格列标签为编号设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 id 属性 -->
<el-table-column label="编号" width="100" align="center">
<template slot-scope="scope">{{scope.row.id}}</template>
</el-table-column>
<!-- 表格列标签为资源名称内容居中对齐通过插槽作用域展示对应行数据的 name 属性 -->
<el-table-column label="资源名称" align="center">
<template slot-scope="scope">{{scope.row.name}}</template>
</el-table-column>
<!-- 表格列标签为资源路径内容居中对齐通过插槽作用域展示对应行数据的 url 属性 -->
<el-table-column label="资源路径" align="center">
<template slot-scope="scope">{{scope.row.url}}</template>
</el-table-column>
<!-- 表格列标签为描述内容居中对齐通过插槽作用域展示对应行数据的 description 属性 -->
<el-table-column label="描述" align="center">
<template slot-scope="scope">{{scope.row.description}}</template>
</el-table-column>
<!-- 表格列标签为添加时间设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 createTime 属性并使用 formatDateTime 过滤器对时间进行格式化展示 -->
<el-table-column label="添加时间" width="160" align="center">
<template slot-scope="scope">{{scope.row.createTime | formatDateTime}}</template>
</el-table-column>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示编辑和删除按钮分别点击时调用 handleUpdate handleDelete 方法 -->
<el-table-column label="操作" width="140" align="center">
<template slot-scope="scope">
<el-button size="mini"
@ -79,7 +102,9 @@
</el-table-column>
</el-table>
</div>
<!-- 分页容器 div用于放置分页组件 -->
<div class="pagination-container">
<!-- el-pagination 分页组件设置了背景色相关页面切换事件绑定布局样式当前页每页数量可选每页数量数组以及总记录数等属性 -->
<el-pagination
background
@size-change="handleSizeChange"
@ -91,19 +116,24 @@
:total="total">
</el-pagination>
</div>
<!-- el-dialog 对话框组件根据 isEdit 变量动态设置标题为编辑资源添加资源绑定了显示状态设置了宽度 -->
<el-dialog
:title="isEdit?'编辑资源':'添加资源'"
:visible.sync="dialogVisible"
width="40%">
<!-- 对话框内的表单绑定了 resource 数据对象设置了表单引用标签宽度和大小 -->
<el-form :model="resource"
ref="resourceForm"
label-width="150px" size="small">
<!-- 表单项目标签为资源名称输入框双向绑定 resource.name并设置了宽度 -->
<el-form-item label="资源名称:">
<el-input v-model="resource.name" style="width: 250px"></el-input>
</el-form-item>
<!-- 表单项目标签为资源路径输入框双向绑定 resource.url并设置了宽度 -->
<el-form-item label="资源路径:">
<el-input v-model="resource.url" style="width: 250px"></el-input>
</el-form-item>
<!-- 表单项目标签为资源分类内部是一个下拉选择框双向绑定 resource.categoryId设置了占位符可清空以及宽度通过循环渲染选项 -->
<el-form-item label="资源分类:">
<el-select v-model="resource.categoryId" placeholder="全部" clearable style="width: 250px">
<el-option v-for="item in categoryOptions"
@ -113,6 +143,7 @@
</el-option>
</el-select>
</el-form-item>
<!-- 表单项目标签为描述输入框双向绑定 resource.description设置了文本域类型和行数以及宽度 -->
<el-form-item label="描述:">
<el-input v-model="resource.description"
type="textarea"
@ -120,6 +151,7 @@
style="width: 250px"></el-input>
</el-form-item>
</el-form>
<!-- 对话框底部的按钮区域通过插槽定义了取消和确定按钮分别绑定了对应的点击事件 -->
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false" size="small"> </el-button>
<el-button type="primary" @click="handleDialogConfirm()" size="small"> </el-button>
@ -128,146 +160,205 @@
</div>
</template>
<script>
import {fetchList,createResource,updateResource,deleteResource} from '@/api/resource';
import {listAllCate} from '@/api/resourceCategory';
import {formatDate} from '@/utils/date';
// @/api/resource API
import {fetchList,createResource,updateResource,deleteResource} from '@/api/resource';
// @/api/resourceCategory API
import {listAllCate} from '@/api/resourceCategory';
// @/utils/date
import {formatDate} from '@/utils/date';
const defaultListQuery = {
pageNum: 1,
pageSize: 10,
nameKeyword: null,
urlKeyword: null,
categoryId:null
};
const defaultResource = {
id: null,
name: null,
url: null,
categoryId: null,
description:''
};
export default {
name: 'resourceList',
data() {
return {
listQuery: Object.assign({}, defaultListQuery),
list: null,
total: null,
listLoading: false,
dialogVisible: false,
resource: Object.assign({}, defaultResource),
isEdit: false,
categoryOptions:[],
defaultCategoryId:null
// ID
const defaultListQuery = {
pageNum: 1,
pageSize: 10,
nameKeyword: null,
urlKeyword: null,
categoryId:null
};
// id ID
const defaultResource = {
id: null,
name: null,
url: null,
categoryId: null,
description:''
};
export default {
name: 'resourceList',
data() {
return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery),
// null API
list: null,
// null
total: null,
// false
listLoading: false,
// / false
dialogVisible: false,
// defaultResource
resource: Object.assign({}, defaultResource),
// false
isEdit: false,
// label value
categoryOptions: [],
// ID null
defaultCategoryId: null
}
},
created() {
//
this.getList();
this.getCateList();
},
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: {
handleResetSearch() {
//
this.listQuery = Object.assign({}, defaultListQuery);
},
created() {
handleSearchList() {
// 1
this.listQuery.pageNum = 1;
this.getList();
this.getCateList();
},
filters: {
formatDateTime(time) {
if (time == null || time === '') {
return 'N/A';
}
let date = new Date(time);
return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
}
handleSizeChange(val) {
// 1
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
//
this.listQuery.pageNum = val;
this.getList();
},
methods: {
handleResetSearch() {
this.listQuery = Object.assign({}, defaultListQuery);
},
handleSearchList() {
this.listQuery.pageNum = 1;
this.getList();
},
handleSizeChange(val) {
this.listQuery.pageNum = 1;
this.listQuery.pageSize = val;
this.getList();
},
handleCurrentChange(val) {
this.listQuery.pageNum = val;
this.getList();
},
handleAdd() {
this.dialogVisible = true;
this.isEdit = false;
this.resource = Object.assign({},defaultResource);
this.resource.categoryId = this.defaultCategoryId;
},
handleDelete(index, row) {
this.$confirm('是否要删除该资源?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteResource(row.id).then(response => {
handleAdd() {
// /isEdit false resource ID
this.dialogVisible = true;
this.isEdit = false;
this.resource = Object.assign({}, defaultResource);
this.resource.categoryId = this.defaultCategoryId;
},
handleDelete(index, row) {
//
this.$confirm('是否要删除该资源?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// API id
//
deleteResource(row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList();
});
});
},
handleUpdate(index, row) {
// /isEdit true resource
this.dialogVisible = true;
this.isEdit = true;
this.resource = Object.assign({}, row);
},
handleDialogConfirm() {
// /
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// isEdit true
if (this.isEdit) {
// API id resource
//
updateResource(this.resource.id, this.resource).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
message: '修改成功!',
type: 'success'
});
this.dialogVisible = false;
this.getList();
});
});
},
handleUpdate(index, row) {
this.dialogVisible = true;
this.isEdit = true;
this.resource = Object.assign({},row);
},
handleDialogConfirm() {
this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
if (this.isEdit) {
updateResource(this.resource.id,this.resource).then(response => {
this.$message({
message: '修改成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
} else {
createResource(this.resource).then(response => {
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible =false;
this.getList();
})
}
})
},
handleShowCategory(){
this.$router.push({path: '/ums/resourceCategory'})
},
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
},
getCateList(){
listAllCate().then(response=>{
let cateList = response.data;
for(let i=0;i<cateList.length;i++){
let cate = cateList[i];
this.categoryOptions.push({label:cate.name,value:cate.id});
}
this.defaultCategoryId=cateList[0].id;
})
}
})
} else {
// API resource
//
createResource(this.resource).then(response => {
this.$message({
message: '添加成功!',
type: 'success'
});
this.dialogVisible = false;
this.getList();
})
}
})
},
//
// '/ums/resourceCategory'
//
handleShowCategory() {
this.$router.push({path: '/ums/resourceCategory'})
},
//
// listLoading true
//
// fetchList API listQuery
// then listLoading false
// response list list
// total total
getList() {
this.listLoading = true;
fetchList(this.listQuery).then(response => {
this.listLoading = false;
this.list = response.data.list;
this.total = response.data.total;
});
},
//
// listAllCate API Promise then
getCateList() {
listAllCate().then(response => {
// cateList 便
let cateList = response.data;
//
for (let i = 0; i < cateList.length; i++) {
// cate 便
let cate = cateList[i];
// label ID value categoryOptions
// categoryOptions UI 便
this.categoryOptions.push({label: cate.name, value: cate.id});
}
// ID defaultCategoryId
// ID 使使
this.defaultCategoryId = cateList[0].id;
})
}
}
}
</script>
<style></style>
<style>
/* CSS resourceList
- 设置表格的样式如表头单元格的字体颜色边框样式等
- 对筛选区域操作按钮分页组件等元素的布局外观进行调整比如按钮的颜色大小间距等
- 定制对话框的样式像对话框的背景色边框按钮在对话框内的排版等
通过添加这些样式规则可以让页面的显示更加符合设计要求和美观性 */
</style>

Loading…
Cancel
Save