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

@ -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,13 +25,17 @@
</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.nameKeyword设置了类名占位符以及可清空功能 -->
<el-form-item label="资源名称:"> <el-form-item label="资源名称:">
<el-input v-model="listQuery.nameKeyword" class="input-width" placeholder="资源名称" clearable></el-input> <el-input v-model="listQuery.nameKeyword" class="input-width" placeholder="资源名称" clearable></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为资源路径内部的输入框双向绑定 listQuery.urlKeyword设置了类名占位符以及可清空功能 -->
<el-form-item label="资源路径:"> <el-form-item label="资源路径:">
<el-input v-model="listQuery.urlKeyword" class="input-width" placeholder="资源路径" clearable></el-input> <el-input v-model="listQuery.urlKeyword" class="input-width" placeholder="资源路径" clearable></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为资源分类内部是一个下拉选择框双向绑定 listQuery.categoryId设置了占位符可清空以及类名通过循环渲染选项 -->
<el-form-item label="资源分类:"> <el-form-item label="资源分类:">
<el-select v-model="listQuery.categoryId" placeholder="全部" clearable class="input-width"> <el-select v-model="listQuery.categoryId" placeholder="全部" clearable class="input-width">
<el-option v-for="item in categoryOptions" <el-option v-for="item in categoryOptions"
@ -38,32 +48,45 @@
</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>
<!-- 资源分类按钮大小为 mini添加了自定义类名 btn-add点击时调用 handleShowCategory 方法用于跳转到资源分类页面 -->
<el-button size="mini" class="btn-add" @click="handleShowCategory()"></el-button> <el-button size="mini" class="btn-add" @click="handleShowCategory()"></el-button>
</el-card> </el-card>
<!-- 表格容器 div用于放置展示资源数据的表格 -->
<div class="table-container"> <div class="table-container">
<!-- el-table 组件用于展示资源数据列表设置了引用名绑定的数据表格宽度加载状态绑定以及边框等属性 -->
<el-table ref="resourceTable" <el-table ref="resourceTable"
: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>
<!-- 表格列标签为资源路径内容居中对齐通过插槽作用域展示对应行数据的 url 属性 -->
<el-table-column label="资源路径" align="center"> <el-table-column label="资源路径" align="center">
<template slot-scope="scope">{{scope.row.url}}</template> <template slot-scope="scope">{{scope.row.url}}</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>
<!-- 表格列标签为添加时间设置了宽度和内容居中对齐通过插槽作用域展示对应行数据的 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>
<!-- 表格列标签为操作设置了宽度和内容居中对齐通过插槽作用域展示编辑和删除按钮分别点击时调用 handleUpdate handleDelete 方法 -->
<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-button size="mini" <el-button size="mini"
@ -79,7 +102,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"
@ -91,19 +116,24 @@
: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%">
<!-- 对话框内的表单绑定了 resource 数据对象设置了表单引用标签宽度和大小 -->
<el-form :model="resource" <el-form :model="resource"
ref="resourceForm" ref="resourceForm"
label-width="150px" size="small"> label-width="150px" size="small">
<!-- 表单项目标签为资源名称输入框双向绑定 resource.name并设置了宽度 -->
<el-form-item label="资源名称:"> <el-form-item label="资源名称:">
<el-input v-model="resource.name" style="width: 250px"></el-input> <el-input v-model="resource.name" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为资源路径输入框双向绑定 resource.url并设置了宽度 -->
<el-form-item label="资源路径:"> <el-form-item label="资源路径:">
<el-input v-model="resource.url" style="width: 250px"></el-input> <el-input v-model="resource.url" style="width: 250px"></el-input>
</el-form-item> </el-form-item>
<!-- 表单项目标签为资源分类内部是一个下拉选择框双向绑定 resource.categoryId设置了占位符可清空以及宽度通过循环渲染选项 -->
<el-form-item label="资源分类:"> <el-form-item label="资源分类:">
<el-select v-model="resource.categoryId" placeholder="全部" clearable style="width: 250px"> <el-select v-model="resource.categoryId" placeholder="全部" clearable style="width: 250px">
<el-option v-for="item in categoryOptions" <el-option v-for="item in categoryOptions"
@ -113,6 +143,7 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- 表单项目标签为描述输入框双向绑定 resource.description设置了文本域类型和行数以及宽度 -->
<el-form-item label="描述:"> <el-form-item label="描述:">
<el-input v-model="resource.description" <el-input v-model="resource.description"
type="textarea" type="textarea"
@ -120,6 +151,7 @@
style="width: 250px"></el-input> 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>
@ -128,81 +160,108 @@
</div> </div>
</template> </template>
<script> <script>
import {fetchList,createResource,updateResource,deleteResource} from '@/api/resource'; // @/api/resource API
import {listAllCate} from '@/api/resourceCategory'; import {fetchList,createResource,updateResource,deleteResource} from '@/api/resource';
import {formatDate} from '@/utils/date'; // @/api/resourceCategory API
import {listAllCate} from '@/api/resourceCategory';
// @/utils/date
import {formatDate} from '@/utils/date';
const defaultListQuery = { // ID
const defaultListQuery = {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
nameKeyword: null, nameKeyword: null,
urlKeyword: null, urlKeyword: null,
categoryId:null categoryId:null
}; };
const defaultResource = { // id ID
const defaultResource = {
id: null, id: null,
name: null, name: null,
url: null, url: null,
categoryId: null, categoryId: null,
description:'' description:''
}; };
export default {
export default {
name: 'resourceList', name: 'resourceList',
data() { data() {
return { return {
// defaultListQuery
listQuery: Object.assign({}, defaultListQuery), listQuery: Object.assign({}, defaultListQuery),
// null API
list: null, list: null,
// null
total: null, total: null,
// false
listLoading: false, listLoading: false,
// / false
dialogVisible: false, dialogVisible: false,
// defaultResource
resource: Object.assign({}, defaultResource), resource: Object.assign({}, defaultResource),
// false
isEdit: false, isEdit: false,
categoryOptions:[], // label value
defaultCategoryId:null categoryOptions: [],
// ID null
defaultCategoryId: null
} }
}, },
created() { created() {
//
this.getList(); this.getList();
this.getCateList(); this.getCateList();
}, },
filters: { filters: {
formatDateTime(time) { formatDateTime(time) {
// 'N/A'
if (time == null || time === '') { if (time == null || time === '') {
return 'N/A'; return 'N/A';
} }
// Date 便
let date = new Date(time); let date = new Date(time);
// 使 formatDate
return formatDate(date, 'yyyy-MM-dd hh:mm:ss') return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
} }
}, },
methods: { methods: {
handleResetSearch() { handleResetSearch() {
//
this.listQuery = Object.assign({}, defaultListQuery); this.listQuery = Object.assign({}, defaultListQuery);
}, },
handleSearchList() { handleSearchList() {
// 1
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.getList(); this.getList();
}, },
handleSizeChange(val) { handleSizeChange(val) {
// 1
this.listQuery.pageNum = 1; this.listQuery.pageNum = 1;
this.listQuery.pageSize = val; this.listQuery.pageSize = val;
this.getList(); this.getList();
}, },
handleCurrentChange(val) { handleCurrentChange(val) {
//
this.listQuery.pageNum = val; this.listQuery.pageNum = val;
this.getList(); this.getList();
}, },
handleAdd() { handleAdd() {
// /isEdit false resource ID
this.dialogVisible = true; this.dialogVisible = true;
this.isEdit = false; this.isEdit = false;
this.resource = Object.assign({},defaultResource); this.resource = Object.assign({}, defaultResource);
this.resource.categoryId = this.defaultCategoryId; this.resource.categoryId = this.defaultCategoryId;
}, },
handleDelete(index, row) { handleDelete(index, row) {
//
this.$confirm('是否要删除该资源?', '提示', { this.$confirm('是否要删除该资源?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// API id
//
deleteResource(row.id).then(response => { deleteResource(row.id).then(response => {
this.$message({ this.$message({
type: 'success', type: 'success',
@ -213,40 +272,58 @@
}); });
}, },
handleUpdate(index, row) { handleUpdate(index, row) {
// /isEdit true resource
this.dialogVisible = true; this.dialogVisible = true;
this.isEdit = true; this.isEdit = true;
this.resource = Object.assign({},row); this.resource = Object.assign({}, row);
}, },
handleDialogConfirm() { handleDialogConfirm() {
// /
this.$confirm('是否要确认?', '提示', { this.$confirm('是否要确认?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
// isEdit true
if (this.isEdit) { if (this.isEdit) {
updateResource(this.resource.id,this.resource).then(response => { // API id resource
//
updateResource(this.resource.id, this.resource).then(response => {
this.$message({ this.$message({
message: '修改成功!', message: '修改成功!',
type: 'success' type: 'success'
}); });
this.dialogVisible =false; this.dialogVisible = false;
this.getList(); this.getList();
}) })
} else { } else {
// API resource
//
createResource(this.resource).then(response => { createResource(this.resource).then(response => {
this.$message({ this.$message({
message: '添加成功!', message: '添加成功!',
type: 'success' type: 'success'
}); });
this.dialogVisible =false; this.dialogVisible = false;
this.getList(); this.getList();
}) })
} }
}) })
}, },
handleShowCategory(){ //
// '/ums/resourceCategory'
//
handleShowCategory() {
this.$router.push({path: '/ums/resourceCategory'}) this.$router.push({path: '/ums/resourceCategory'})
}, },
//
// listLoading true
//
// fetchList API listQuery
// then listLoading false
// response list list
// total total
getList() { getList() {
this.listLoading = true; this.listLoading = true;
fetchList(this.listQuery).then(response => { fetchList(this.listQuery).then(response => {
@ -255,19 +332,33 @@
this.total = response.data.total; this.total = response.data.total;
}); });
}, },
getCateList(){
listAllCate().then(response=>{ //
// listAllCate API Promise then
getCateList() {
listAllCate().then(response => {
// cateList 便
let cateList = response.data; let cateList = response.data;
for(let i=0;i<cateList.length;i++){ //
for (let i = 0; i < cateList.length; i++) {
// cate 便
let cate = cateList[i]; let cate = cateList[i];
this.categoryOptions.push({label:cate.name,value:cate.id}); // label ID value categoryOptions
// categoryOptions UI 便
this.categoryOptions.push({label: cate.name, value: cate.id});
} }
this.defaultCategoryId=cateList[0].id; // ID defaultCategoryId
// ID 使使
this.defaultCategoryId = cateList[0].id;
}) })
} }
} }
} }
</script> </script>
<style></style> <style>
/* CSS resourceList
- 设置表格的样式如表头单元格的字体颜色边框样式等
- 对筛选区域操作按钮分页组件等元素的布局外观进行调整比如按钮的颜色大小间距等
- 定制对话框的样式像对话框的背景色边框按钮在对话框内的排版等
通过添加这些样式规则可以让页面的显示更加符合设计要求和美观性 */
</style>

Loading…
Cancel
Save