新增搜索及完善显示

This commit is contained in:
LittleBoy 2022-05-12 09:25:27 +08:00
parent 7d3e42f703
commit eedf17c7c1
4 changed files with 49 additions and 11 deletions

5
package-lock.json generated
View File

@ -465,6 +465,11 @@
"resolved": "https://registry.npmmirror.com/csstype/-/csstype-2.6.20.tgz", "resolved": "https://registry.npmmirror.com/csstype/-/csstype-2.6.20.tgz",
"integrity": "sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==" "integrity": "sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA=="
}, },
"dayjs": {
"version": "1.11.2",
"resolved": "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.2.tgz",
"integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz",

View File

@ -10,6 +10,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"dayjs": "^1.11.2",
"element-ui": "^2.15.8", "element-ui": "^2.15.8",
"express": "^4.18.1", "express": "^4.18.1",
"mysql": "^2.18.1", "mysql": "^2.18.1",

View File

@ -21,17 +21,30 @@
header { header {
background-color: black; background-color: black;
color: #fff; color: #fff;
padding: 10px; line-height: 60px;
height: 60px;
}
.logo {
font-size: 30px;
flex: 1;
} }
.site-nav { .site-nav {
flex: 1;
text-align: right; text-align: right;
} }
.site-nav a { .site-nav a {
color: #fff; color: #fff;
text-decoration: none; text-decoration: none;
display: inline-block;
padding: 0 20px;
font-size: 18px;
}
.site-nav a:hover {
color: #333;
background-color: aqua;
} }
.container { .container {
@ -80,6 +93,14 @@
color: #666; color: #666;
font-size: 12px; font-size: 12px;
} }
.search-input {
width: 200px;
}
.search-input .el-input__inner {
border-radius: 50px;
}
</style> </style>
</head> </head>
@ -88,6 +109,10 @@
<header> <header>
<div class="container show-flex"> <div class="container show-flex">
<div class="logo">我的博客</div> <div class="logo">我的博客</div>
<div class="search-input">
<el-input size="small" placeholder="请输入搜索关键字" prefix-icon="el-icon-search"
clearable v-model="search" @change="loadList" />
</div>
<nav class="site-nav"> <nav class="site-nav">
<a href="./">首页</a> <a href="./">首页</a>
<a href="./login.html">登录</a> <a href="./login.html">登录</a>
@ -103,14 +128,15 @@
<h3 class="title">{{a.title}}</h3> <h3 class="title">{{a.title}}</h3>
<p class="desc">{{a.description}}</p> <p class="desc">{{a.description}}</p>
<div class="ext"> <div class="ext">
<span>发布于:2022-5-11</span> <span>发布于:{{formatDate(a.publish_time)}}</span>
<span>阅读(20)</span> <span>阅读({{a.view_count}})</span>
<span>评论(10)</span> <span>评论({{a.comment_count}})</span>
</div> </div>
</div> </div>
</div> </div>
<div class="page" style="text-align: center;"> <div class="page" style="text-align: center;">
<el-pagination layout="prev, pager, next" @current-change="onPageChange" :page-size="size" :total="total"> <el-pagination layout="prev, pager, next" @current-change="onPageChange" :page-size="size"
:total="total">
</el-pagination> </el-pagination>
</div> </div>
</div> </div>
@ -118,6 +144,7 @@
<!-- 引入vue库 --> <!-- 引入vue库 -->
<script src="./vue/dist/vue.js"></script> <script src="./vue/dist/vue.js"></script>
<script src="./element-ui/lib/index.js"></script> <script src="./element-ui/lib/index.js"></script>
<script src="./modules/dayjs.min.js"></script>
<script type="module"> <script type="module">
// import Vue from './vue/dist/vue.esm-browser.js' // import Vue from './vue/dist/vue.esm-browser.js'
// vue 通过 Vue.createApp(选项)创建vue实例 // vue 通过 Vue.createApp(选项)创建vue实例
@ -130,24 +157,28 @@
articleArray: [], // 文章列表数组 articleArray: [], // 文章列表数组
total: 0, // 总的文章数量 total: 0, // 总的文章数量
size: 3, // 每页显示条数 size: 3, // 每页显示条数
currentPage: 1 currentPage: 1,
search: ''
} }
}, },
created() { created() {
this.loadList();//页面一加载就获取 this.loadList();//页面一加载就获取
}, },
methods: { methods: {
formatDate(time){
return dayjs(time).format('YYYY-MM-DD HH:mm')
},
loadList() { loadList() {
// 使用request方法请求数据 // 使用request方法请求数据
request('/api/article/web/list', { size: this.size, page: this.currentPage }).then(data => { request('/api/article/web/list', { size: this.size, page: this.currentPage,search:this.search }).then(data => {
this.articleArray = data.list this.articleArray = data.list
this.total = data.total; this.total = data.total;
this.size = data.size; this.size = data.size;
}) })
}, },
// 当页码发生变化 // 当页码发生变化
onPageChange(page){ onPageChange(page) {
this.currentPage = page; this.currentPage = page; // 设置当前页码
this.loadList(); this.loadList();
} }
} }

1
public/modules/dayjs.min.js vendored Normal file

File diff suppressed because one or more lines are too long