完成单页列表制作
This commit is contained in:
parent
f97bd549da
commit
996a41884f
7
frontend/components.d.ts
vendored
7
frontend/components.d.ts
vendored
@ -11,7 +11,14 @@ export {}
|
||||
/* prettier-ignore */
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
ElAvatar: typeof import('element-plus/es')['ElAvatar']
|
||||
ElButton: typeof import('element-plus/es')['ElButton']
|
||||
ElDropdown: typeof import('element-plus/es')['ElDropdown']
|
||||
ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem']
|
||||
ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu']
|
||||
ElIcon: typeof import('element-plus/es')['ElIcon']
|
||||
ElInput: typeof import('element-plus/es')['ElInput']
|
||||
ElPagination: typeof import('element-plus/es')['ElPagination']
|
||||
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
|
||||
10663
frontend/src/assets/css/all.css
Normal file
10663
frontend/src/assets/css/all.css
Normal file
File diff suppressed because it is too large
Load Diff
BIN
frontend/src/assets/webfonts/fa-brands-400.woff2
Normal file
BIN
frontend/src/assets/webfonts/fa-brands-400.woff2
Normal file
Binary file not shown.
BIN
frontend/src/assets/webfonts/fa-regular-400.woff2
Normal file
BIN
frontend/src/assets/webfonts/fa-regular-400.woff2
Normal file
Binary file not shown.
BIN
frontend/src/assets/webfonts/fa-solid-900.woff2
Normal file
BIN
frontend/src/assets/webfonts/fa-solid-900.woff2
Normal file
Binary file not shown.
BIN
frontend/src/assets/webfonts/fa-v4compatibility.woff2
Normal file
BIN
frontend/src/assets/webfonts/fa-v4compatibility.woff2
Normal file
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
import { createApp } from "vue";
|
||||
import "@/assets/less/global.less";
|
||||
import "@/assets/css/all.css"
|
||||
import App from "./App.vue";
|
||||
import router from "@/router";
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
@ -35,29 +35,26 @@
|
||||
:key="article.id"
|
||||
class="article-card"
|
||||
>
|
||||
<div class="article-image">
|
||||
<img :src="getImageUrl(article.image)" :alt="article.title">
|
||||
</div>
|
||||
<div class="card-header">
|
||||
<router-link :to="`/article/${article.id}`" class="article-title-link">
|
||||
<h3 class="article-title">{{ article.title }}</h3>
|
||||
<div class="article-meta">
|
||||
<span class="article-date">{{
|
||||
formatDate(article.created_at)
|
||||
}}</span>
|
||||
<span class="article-category">{{
|
||||
article.category_name
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="article-summary">
|
||||
{{
|
||||
article.summary ||
|
||||
article.content?.substring(0, 100) + "..."
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<router-link :to="`/article/${article.id}`" class="read-more">
|
||||
阅读更多
|
||||
</router-link>
|
||||
<div class="article-meta">
|
||||
<span class="article-view">
|
||||
<i class="fa-solid fa-eye"></i>
|
||||
{{ article.view || 0 }}
|
||||
</span>
|
||||
<span class="article-likes">
|
||||
<i class="fa-solid fa-heart"></i>
|
||||
{{ article.likes || 0 }}
|
||||
</span>
|
||||
<span class="article-date">{{
|
||||
formatDate(article.publishdate)
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -87,8 +84,7 @@ import { ElMessage } from "element-plus";
|
||||
import Header from "@/views/components/header.vue";
|
||||
import Footer from "@/views/components/footer.vue";
|
||||
import {
|
||||
siteInformation,
|
||||
getSiteInformationLists,
|
||||
siteInformation
|
||||
} from "@/api/siteInformation";
|
||||
|
||||
// 响应式数据
|
||||
@ -100,6 +96,12 @@ const currentPage = ref(1); // 当前页码
|
||||
const pageSize = ref(10); // 每页条数
|
||||
const total = ref(0); // 总条数
|
||||
|
||||
// 获取图片地址
|
||||
const getImageUrl = (imagePath: string) => {
|
||||
if (!imagePath) return '/src/assets/imgs/default.png';
|
||||
return import.meta.env.VITE_API_DOMAIN + imagePath;
|
||||
};
|
||||
|
||||
// 获取分类列表
|
||||
const fetchCategories = async () => {
|
||||
try {
|
||||
@ -133,8 +135,6 @@ const fetchArticles = async (page: number = currentPage.value) => {
|
||||
try {
|
||||
const response: any = await siteInformation.getSiteInformationLists(
|
||||
selectedCategory.value,
|
||||
page,
|
||||
pageSize.value
|
||||
);
|
||||
|
||||
const data = response.data?.data;
|
||||
@ -179,9 +179,12 @@ const handlePageSizeChange = (size: number) => {
|
||||
};
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (dateString: string) => {
|
||||
if (!dateString) return "";
|
||||
const date = new Date(dateString);
|
||||
const formatDate = (timestamp: string | number) => {
|
||||
if (!timestamp) return "";
|
||||
// 如果是字符串数字,转换为数字
|
||||
const numTimestamp = typeof timestamp === 'string' ? parseInt(timestamp) : timestamp;
|
||||
// 如果时间戳是秒格式(10位),转换为毫秒
|
||||
const date = new Date(numTimestamp < 1e10 ? numTimestamp * 1000 : numTimestamp);
|
||||
return date.toLocaleDateString("zh-CN", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
@ -199,7 +202,7 @@ onMounted(() => {
|
||||
.articles-page {
|
||||
padding-top: 100px;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
background: #f9fafc;
|
||||
|
||||
.top-content {
|
||||
background: linear-gradient(135deg, #1e9fff 0%, #0d8aff 100%);
|
||||
@ -227,19 +230,13 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
.main-content {
|
||||
max-width: 1200px;
|
||||
width: 1200px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
padding: 40px 0;
|
||||
align-items: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.left-menu {
|
||||
background-color: var(--white);
|
||||
padding: 20px;
|
||||
@ -248,10 +245,6 @@ onMounted(() => {
|
||||
flex-shrink: 0;
|
||||
align-self: flex-start;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
@ -320,46 +313,56 @@ onMounted(() => {
|
||||
|
||||
.articles-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 20px;
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.article-card {
|
||||
background: #fff;
|
||||
// min-width: 250px;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
box-shadow: 0 3px 15px rgba(0, 0, 0, 0.03);
|
||||
transition: all 0.3s ease;
|
||||
border: 1px solid #e8e8e8;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.article-image {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 140px;
|
||||
overflow: hidden;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.card-header {
|
||||
padding: 16px 16px 12px;
|
||||
|
||||
.article-title-link {
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
|
||||
&:hover .article-title {
|
||||
color: #007bff;
|
||||
}
|
||||
}
|
||||
|
||||
.article-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
height: 40px;
|
||||
color: #333;
|
||||
margin: 0 0 8px 0;
|
||||
line-height: 1.4;
|
||||
@ -367,6 +370,10 @@ onMounted(() => {
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: break-word;
|
||||
transition: color 0.3s ease;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.article-meta {
|
||||
@ -375,9 +382,12 @@ onMounted(() => {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
|
||||
.article-date,
|
||||
.article-category {
|
||||
flex: 1;
|
||||
.article-view,
|
||||
.article-likes,
|
||||
.article-date {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,59 +6,31 @@ import AutoImport from "unplugin-auto-import/vite";
|
||||
import Components from "unplugin-vue-components/vite";
|
||||
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
// 开发服务器配置(可选,解决跨域等问题)
|
||||
// server: {
|
||||
// host: "0.0.0.0", // 允许局域网访问
|
||||
// port: 5173, // 自定义端口
|
||||
// open: true, // 启动后自动打开浏览器
|
||||
// },
|
||||
plugins: [
|
||||
vue(),
|
||||
// 自动导入 Vue/VueRouter/Element Plus API
|
||||
AutoImport({
|
||||
imports: ["vue", "vue-router"],
|
||||
resolvers: [ElementPlusResolver({ importStyle: "css" })],
|
||||
dts: path.resolve(__dirname, "src/auto-imports.d.ts"),
|
||||
resolvers: [ElementPlusResolver()],
|
||||
dts: "src/auto-imports.d.ts",
|
||||
eslintrc: {
|
||||
enabled: true,
|
||||
filepath: path.resolve(__dirname, ".eslintrc-auto-import.json"),
|
||||
},
|
||||
}),
|
||||
// 自动导入 Element Plus 组件
|
||||
Components({
|
||||
dirs: ["src/components"],
|
||||
resolvers: [ElementPlusResolver({ importStyle: "css" })],
|
||||
dts: path.resolve(__dirname, "src/components.d.ts"),
|
||||
resolvers: [ElementPlusResolver()],
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "src"),
|
||||
},
|
||||
// 省略文件扩展名,导入时无需写 .vue/.scss/.js
|
||||
extensions: [
|
||||
".mjs",
|
||||
".js",
|
||||
".ts",
|
||||
".jsx",
|
||||
".tsx",
|
||||
".json",
|
||||
".vue",
|
||||
".less",
|
||||
],
|
||||
},
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
// 全局注入:用函数判断,避免给 global.less 自身注入导致循环导入
|
||||
additionalData: (content, filename) => {
|
||||
if (!filename.includes("global.less")) {
|
||||
return `@import "@/assets/less/global.less";${content}`;
|
||||
}
|
||||
return content;
|
||||
},
|
||||
charset: false,
|
||||
scss: {
|
||||
additionalData: '@import "./src/assets/scss/main.scss";',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user