feat: 初始化 yx-nav 网址导航项目
- 技术栈: Vue3+TS+Vite + Express+SQLite - 前台: 分类导航页、搜索、访问统计 - 后台: 仪表盘、网址CRUD、分类管理、站点配置 - 默认账号: admin / admin123
This commit is contained in:
@@ -0,0 +1,232 @@
|
||||
<template>
|
||||
<div class="home">
|
||||
<div class="header">
|
||||
<div class="header-content">
|
||||
<div class="brand">
|
||||
<span class="logo">{{ data.settings.site_name || '导航' }}</span>
|
||||
<p class="desc">{{ data.settings.site_description }}</p>
|
||||
</div>
|
||||
<el-input
|
||||
v-model="search"
|
||||
placeholder="搜索网址..."
|
||||
class="search-box"
|
||||
@input="filterLinks"
|
||||
>
|
||||
<template #prefix>
|
||||
<el-icon><Search /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div
|
||||
v-for="cat in filteredCategories"
|
||||
:key="cat.id"
|
||||
class="category-section"
|
||||
>
|
||||
<div class="category-header">
|
||||
<span class="icon">{{ cat.icon }}</span>
|
||||
<span class="name">{{ cat.name }}</span>
|
||||
<span class="count">{{ linksInCat(cat.id).length }}</span>
|
||||
</div>
|
||||
<div class="links-grid">
|
||||
<a
|
||||
v-for="link in linksInCat(cat.id)"
|
||||
:key="link.id"
|
||||
:href="link.url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="link-card"
|
||||
@click="handleVisit(link)"
|
||||
>
|
||||
<img
|
||||
v-if="link.iconUrl"
|
||||
:src="link.iconUrl"
|
||||
:alt="link.title"
|
||||
class="link-icon"
|
||||
@error="onIconError($event, link)"
|
||||
/>
|
||||
<div v-else class="link-icon default-icon">{{ link.title[0] }}</div>
|
||||
<div class="link-info">
|
||||
<div class="link-title">{{ link.title }}</div>
|
||||
<div class="link-desc">{{ link.description }}</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="footer">{{ data.settings.footer_text }}</footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { Search } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { siteApi } from '@/api'
|
||||
|
||||
const data = reactive({ settings: {} as any, links: [] as any[] })
|
||||
const search = ref('')
|
||||
const filteredLinks = ref<any[]>([])
|
||||
|
||||
const filteredCategories = computed(() => {
|
||||
return data.categories.filter((cat: any) =>
|
||||
linksInCat(cat.id).length > 0
|
||||
)
|
||||
})
|
||||
|
||||
function linksInCat(catId: number) {
|
||||
return filteredLinks.value.filter((l: any) => l.categoryId === catId)
|
||||
}
|
||||
|
||||
function filterLinks() {
|
||||
const q = search.value.trim()
|
||||
filteredLinks.value = q
|
||||
? data.links.filter((l: any) => l.title.toLowerCase().includes(q))
|
||||
: [...data.links]
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
const res = await siteApi.getIndex()
|
||||
const { categories, links, settings } = res.result.data
|
||||
data.categories = categories
|
||||
data.links = links
|
||||
data.settings = settings
|
||||
filteredLinks.value = links
|
||||
} catch {
|
||||
ElMessage.error('加载失败')
|
||||
}
|
||||
}
|
||||
|
||||
function handleVisit(link: any) {
|
||||
siteApi.addView(link.id)
|
||||
}
|
||||
|
||||
function onIconError(e: any, link: any) {
|
||||
e.target.style.display = 'none'
|
||||
link.iconUrl = ''
|
||||
}
|
||||
|
||||
loadData()
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.home {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #f5f7fa 0%, #e4e9f0 100%);
|
||||
}
|
||||
|
||||
.header {
|
||||
background: white;
|
||||
box-shadow: 0 2px 12px rgba(0,0,0,0.08);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
|
||||
.header-content {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 24px 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
.logo {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
background: linear-gradient(135deg, #6366f1, #818cf8);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
.desc { font-size: 14px; color: #888; margin-top: 4px; }
|
||||
}
|
||||
|
||||
.search-box { width: 320px; }
|
||||
}
|
||||
|
||||
.main-content {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.category-section { margin-bottom: 40px; }
|
||||
|
||||
.category-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 16px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 2px solid #e5e7eb;
|
||||
|
||||
.icon { font-size: 20px; }
|
||||
.name { font-size: 18px; font-weight: 600; }
|
||||
.count {
|
||||
font-size: 12px;
|
||||
color: #888;
|
||||
background: #f0f0f0;
|
||||
padding: 2px 10px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.links-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.link-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
background: white;
|
||||
padding: 16px;
|
||||
border-radius: 12px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
box-shadow: 0 1px 4px rgba(0,0,0,0.06);
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 16px rgba(99,102,241,0.15);
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 10px;
|
||||
object-fit: cover;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.default-icon {
|
||||
background: linear-gradient(135deg, #6366f1, #818cf8);
|
||||
color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-weight: 600;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.link-info { flex: 1; min-width: 0; }
|
||||
.link-title { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.link-desc { font-size: 12px; color: #888; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 24px;
|
||||
color: #aaa;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user