feat: 初始化 yx-nav 网址导航项目
- 技术栈: Vue3+TS+Vite + Express+SQLite - 前台: 分类导航页、搜索、访问统计 - 后台: 仪表盘、网址CRUD、分类管理、站点配置 - 默认账号: admin / admin123
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts"></script>
|
||||
@@ -0,0 +1,56 @@
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
export const request = axios.create({ baseURL: '/api', timeout: 10000 })
|
||||
|
||||
request.interceptors.request.use(config => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) config.headers.Authorization = `Bearer ${token}`
|
||||
return config
|
||||
})
|
||||
|
||||
request.interceptors.response.use(
|
||||
res => {
|
||||
const data = res.data
|
||||
if (data.status !== 200) {
|
||||
ElMessage.error(data.message || '请求失败')
|
||||
return Promise.reject(new Error(data.message))
|
||||
}
|
||||
return data
|
||||
},
|
||||
err => {
|
||||
if (err.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
ElMessage.error('登录已过期')
|
||||
}
|
||||
return Promise.reject(err)
|
||||
}
|
||||
)
|
||||
|
||||
// 前端站点 API
|
||||
export const siteApi = {
|
||||
getIndex: () => request.get('/site'),
|
||||
addView: (id: number) => request.post(`/links/${id}/view`),
|
||||
}
|
||||
|
||||
// 后台管理 API
|
||||
export const adminApi = {
|
||||
profile: () => request.get('/admin/profile'),
|
||||
updateProfile: (data: any) => request.put('/admin/profile', data),
|
||||
getCategories: () => request.get('/admin/categories'),
|
||||
addCategory: (data: any) => request.post('/admin/categories', data),
|
||||
updateCategory: (id: number, data: any) => request.put(`/admin/categories/${id}`, data),
|
||||
deleteCategory: (id: number) => request.delete(`/admin/categories/${id}`),
|
||||
getLinks: (params?: any) => request.get('/admin/links', { params }),
|
||||
addLink: (data: any) => request.post('/admin/links', data),
|
||||
updateLink: (id: number, data: any) => request.put(`/admin/links/${id}`, data),
|
||||
deleteLink: (id: number) => request.delete(`/admin/links/${id}`),
|
||||
updateSorts: (sorts: any[]) => request.put('/admin/links/sort', { sorts }),
|
||||
getSettings: () => request.get('/admin/settings'),
|
||||
updateSettings: (data: any) => request.put('/admin/settings', data),
|
||||
}
|
||||
|
||||
// 认证 API
|
||||
export const authApi = {
|
||||
login: (data: any) => axios.post('/api/auth/login', data),
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
html, body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #f0f2f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
#app { min-height: 100vh; }
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import './assets/styles/index.scss'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,40 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import Home from '@/views/Home.vue'
|
||||
import AdminLayout from '@/views/admin/AdminLayout.vue'
|
||||
import AdminDashboard from '@/views/admin/Dashboard.vue'
|
||||
import AdminLinks from '@/views/admin/Links.vue'
|
||||
import AdminCategories from '@/views/admin/Categories.vue'
|
||||
import AdminSettings from '@/views/admin/Settings.vue'
|
||||
import AdminLogin from '@/views/admin/Login.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: '/', name: 'home', component: Home },
|
||||
{ path: '/admin/login', name: 'login', component: AdminLogin },
|
||||
{
|
||||
path: '/admin',
|
||||
component: AdminLayout,
|
||||
redirect: '/admin/dashboard',
|
||||
children: [
|
||||
{ path: 'dashboard', name: 'dashboard', component: AdminDashboard },
|
||||
{ path: 'links', name: 'links', component: AdminLinks },
|
||||
{ path: 'categories', name: 'categories', component: AdminCategories },
|
||||
{ path: 'settings', name: 'settings', component: AdminSettings },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (to.path.startsWith('/admin') && to.name !== 'login' && !token) {
|
||||
next('/admin/login')
|
||||
} else if (to.name === 'login' && token) {
|
||||
next('/admin/dashboard')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,33 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { adminApi } from '@/api'
|
||||
import router from '@/router'
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const user = ref<any>(null)
|
||||
const token = ref(localStorage.getItem('token') || '')
|
||||
|
||||
function setToken(t: string) {
|
||||
token.value = t
|
||||
localStorage.setItem('token', t)
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = ''
|
||||
user.value = null
|
||||
localStorage.removeItem('token')
|
||||
router.push('/admin/login')
|
||||
}
|
||||
|
||||
async function fetchProfile() {
|
||||
if (!token.value) return
|
||||
try {
|
||||
const res = await adminApi.profile()
|
||||
user.value = res.result.data
|
||||
} catch {
|
||||
logout()
|
||||
}
|
||||
}
|
||||
|
||||
return { user, token, setToken, logout, fetchProfile }
|
||||
})
|
||||
@@ -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>
|
||||
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<div class="admin-layout">
|
||||
<el-aside width="200px">
|
||||
<div class="sidebar-logo">言逍导航</div>
|
||||
<el-menu router :default-active="$route.path">
|
||||
<el-menu-item index="/admin/dashboard">
|
||||
<el-icon><DataBoard /></el-icon>
|
||||
<span>仪表盘</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/admin/links">
|
||||
<el-icon><Link /></el-icon>
|
||||
<span>网址管理</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/admin/categories">
|
||||
<el-icon><Folder /></el-icon>
|
||||
<span>分类管理</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/admin/settings">
|
||||
<el-icon><Setting /></el-icon>
|
||||
<span>站点配置</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
<el-main>
|
||||
<div class="admin-header">
|
||||
<el-breadcrumb separator="/">
|
||||
<el-breadcrumb-item>后台管理</el-breadcrumb-item>
|
||||
<el-breadcrumb-item>{{ pageTitle }}</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
<div class="user-area">
|
||||
<span class="nickname">{{ store.user?.nickname || '管理员' }}</span>
|
||||
<el-button text @click="handleLogout">退出</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<router-view />
|
||||
</el-main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { DataBoard, Link, Folder, Setting } from '@element-plus/icons-vue'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import router from '@/router'
|
||||
|
||||
const route = useRoute()
|
||||
const store = useUserStore()
|
||||
|
||||
const titleMap: Record<string, string> = {
|
||||
'/admin/dashboard': '仪表盘',
|
||||
'/admin/links': '网址管理',
|
||||
'/admin/categories': '分类管理',
|
||||
'/admin/settings': '站点配置',
|
||||
}
|
||||
const pageTitle = computed(() => titleMap[route.path] || '管理')
|
||||
|
||||
function handleLogout() {
|
||||
store.logout()
|
||||
router.push('/admin/login')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-layout { height: 100vh; }
|
||||
.el-aside {
|
||||
background: #1e293b;
|
||||
color: white;
|
||||
}
|
||||
.sidebar-logo {
|
||||
padding: 24px;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.1);
|
||||
}
|
||||
.el-menu {
|
||||
background: transparent;
|
||||
border-right: none;
|
||||
}
|
||||
.el-menu .el-menu-item { color: rgba(255,255,255,0.7); }
|
||||
.el-menu .el-menu-item:hover { background: rgba(255,255,255,0.08); }
|
||||
.el-menu .el-menu-item.is-active { background: rgba(99,102,241,0.3); color: white; }
|
||||
.admin-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
.user-area { display: flex; align-items: center; gap: 16px; }
|
||||
.nickname { color: #555; font-weight: 500; }
|
||||
.el-main { background: #f5f7fa; padding: 24px; overflow-y: auto; }
|
||||
</style>
|
||||
@@ -0,0 +1,90 @@
|
||||
<template>
|
||||
<div class="cats-page">
|
||||
<div class="page-header">
|
||||
<h2>分类管理</h2>
|
||||
<el-button type="primary" @click="openDialog">
|
||||
<el-icon><Plus /></el-icon> 新增分类
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-table :data="categories">
|
||||
<el-table-column prop="icon" label="图标" width="80" align="center" />
|
||||
<el-table-column prop="name" label="名称" />
|
||||
<el-table-column prop="sort" label="排序" width="80" align="center" />
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button size="small" @click="openDialog(scope.row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<el-dialog v-model="dialogVisible" :title="editId ? '编辑分类' : '新增分类'" width="420px">
|
||||
<el-form :model="form" label-width="60px">
|
||||
<el-form-item label="图标">
|
||||
<el-input v-model="form.icon" placeholder="如:🌟" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="form.name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<el-input-number v-model="form.sort" :min="0" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="save">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { adminApi } from '@/api'
|
||||
|
||||
const categories = ref([])
|
||||
const dialogVisible = ref(false)
|
||||
const editId = ref(null)
|
||||
const form = ref({ icon: '🔗', name: '', sort: 0 })
|
||||
|
||||
async function load() {
|
||||
categories.value = (await adminApi.getCategories()).result.data
|
||||
}
|
||||
|
||||
function openDialog(row?: any) {
|
||||
editId.value = row?.id || null
|
||||
form.value = row || { icon: '🔗', name: '', sort: 0 }
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (editId.value) {
|
||||
await adminApi.updateCategory(editId.value, form.value)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await adminApi.addCategory(form.value)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await load()
|
||||
}
|
||||
|
||||
async function del(row: any) {
|
||||
await ElMessageBox.confirm('确定删除此分类?')
|
||||
await adminApi.deleteCategory(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
await load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
|
||||
.page-header h2 { font-size: 20px; font-weight: 600; }
|
||||
</style>
|
||||
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<div class="dashboard">
|
||||
<el-row :gutter="20" class="stat-cards">
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<span class="num">{{ stats.linkCount }}</span>
|
||||
<span class="label">网址总数</span>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<span class="num">{{ stats.catCount }}</span>
|
||||
<span class="label">分类数</span>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<span class="num">{{ stats.totalViews }}</span>
|
||||
<span class="label">总访问</span>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-card shadow="hover">
|
||||
<div class="stat-item">
|
||||
<span class="num">{{ settings.site_name }}</span>
|
||||
<span class="label">站点名称</span>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card style="margin-top:24px">
|
||||
<template #header>
|
||||
<span>快捷操作</span>
|
||||
</template>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="6">
|
||||
<el-button type="primary" block @click="$router.push('/admin/links')">
|
||||
<el-icon><Plus /></el-icon> 管理网址
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button type="success" block @click="$router.push('/admin/categories')">
|
||||
<el-icon><FolderAdd /></el-icon> 管理分类
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button type="warning" block @click="$router.push('/admin/settings')">
|
||||
<el-icon><Setting /></el-icon> 站点配置
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-button block @click="() => window.open('/', '_blank')">
|
||||
<el-icon><View /></el-icon> 预览前台
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-card>
|
||||
|
||||
<el-card style="margin-top:24px">
|
||||
<template #header><span>分类概览</span></template>
|
||||
<el-table :data="categories" style="width:100%">
|
||||
<el-table-column prop="name" label="分类" />
|
||||
<el-table-column prop="linkCount" label="网址数" width="100" />
|
||||
<el-table-column prop="icon" label="图标" width="80" />
|
||||
</el-table>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { Plus, FolderAdd, Setting, View } from '@element-plus/icons-vue'
|
||||
import { adminApi } from '@/api'
|
||||
|
||||
const stats = ref({ linkCount: 0, catCount: 0, totalViews: 0 })
|
||||
const settings = ref({})
|
||||
const categories = ref([])
|
||||
|
||||
onMounted(async () => {
|
||||
const [statsRes, setRes] = await Promise.all([
|
||||
adminApi.getCategories(),
|
||||
adminApi.getSettings()
|
||||
])
|
||||
categories.value = statsRes.result.data
|
||||
settings.value = setRes.result.data
|
||||
stats.value = {
|
||||
catCount: categories.value.length,
|
||||
linkCount: categories.value.reduce((s: number, c: any) => s + (c.linkCount || 0), 0),
|
||||
totalViews: 0,
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.stat-cards { margin-bottom: 8px; }
|
||||
.stat-item { text-align: center; }
|
||||
.stat-item .num { display: block; font-size: 36px; font-weight: 700; color: #6366f1; margin-bottom: 8px; }
|
||||
.stat-item .label { color: #888; font-size: 14px; }
|
||||
</style>
|
||||
@@ -0,0 +1,130 @@
|
||||
<template>
|
||||
<div class="links-page">
|
||||
<div class="page-header">
|
||||
<h2>网址管理</h2>
|
||||
<el-button type="primary" @click="openDialog()">
|
||||
<el-icon><Plus /></el-icon> 新增网址
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-card>
|
||||
<el-row :gutter="16" style="margin-bottom:16px">
|
||||
<el-col :span="6">
|
||||
<el-input v-model="keyword" placeholder="搜索标题" @input="loadLinks" />
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-select v-model="catFilter" placeholder="选择分类" @change="loadLinks" clearable>
|
||||
<el-option v-for="c in categories" :key="c.id" :label="c.name" :value="c.id" />
|
||||
</el-select>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table :data="links">
|
||||
<el-table-column prop="title" label="标题" />
|
||||
<el-table-column prop="categoryName" label="分类" width="120" />
|
||||
<el-table-column prop="url" label="网址" />
|
||||
<el-table-column prop="isShow" label="显示" width="80" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.isShow ? 'success' : 'info'">
|
||||
{{ scope.row.isShow ? '是' : '否' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="views" label="访问" width="80" align="center" />
|
||||
<el-table-column label="操作" width="140">
|
||||
<template #default="scope">
|
||||
<el-button size="small" @click="openDialog(scope.row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteLink(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<el-dialog v-model="dialogVisible" :title="editId ? '编辑网址' : '新增网址'" width="500px">
|
||||
<el-form :model="form" label-width="80px">
|
||||
<el-form-item label="标题">
|
||||
<el-input v-model="form.title" placeholder="如:百度" />
|
||||
</el-form-item>
|
||||
<el-form-item label="网址">
|
||||
<el-input v-model="form.url" placeholder="https://" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类">
|
||||
<el-select v-model="form.categoryId" placeholder="选择分类">
|
||||
<el-option v-for="c in categories" :key="c.id" :label="c.name" :value="c.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="图标URL">
|
||||
<el-input v-model="form.iconUrl" placeholder="图标链接(可选)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="form.description" type="textarea" placeholder="简短描述" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<el-input-number v-model="form.sort" :min="0" />
|
||||
</el-form-item>
|
||||
<el-form-item label="显示">
|
||||
<el-switch v-model="form.isShow" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="save">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { Plus } from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { adminApi } from '@/api'
|
||||
|
||||
const links = ref([])
|
||||
const categories = ref([])
|
||||
const keyword = ref('')
|
||||
const catFilter = ref('')
|
||||
const dialogVisible = ref(false)
|
||||
const editId = ref(null)
|
||||
const form = ref({ title: '', url: '', categoryId: '', description: '', iconUrl: '', sort: 0, isShow: true })
|
||||
|
||||
async function loadLinks() {
|
||||
links.value = (await adminApi.getLinks({ keyword: keyword.value || undefined, categoryId: catFilter.value || undefined })).result.data
|
||||
}
|
||||
async function loadCats() {
|
||||
categories.value = (await adminApi.getCategories()).result.data
|
||||
}
|
||||
|
||||
function openDialog(row?: any) {
|
||||
editId.value = row?.id || null
|
||||
form.value = row || { title: '', url: '', categoryId: '', description: '', iconUrl: '', sort: 0, isShow: true }
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (editId.value) {
|
||||
await adminApi.updateLink(editId.value, form.value)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await adminApi.addLink(form.value)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await loadLinks()
|
||||
}
|
||||
|
||||
async function deleteLink(row: any) {
|
||||
await ElMessageBox.confirm('确定删除?')
|
||||
await adminApi.deleteLink(row.id)
|
||||
ElMessage.success('删除成功')
|
||||
await loadLinks()
|
||||
}
|
||||
|
||||
onMounted(async () => { await loadLinks(); await loadCats() })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
|
||||
.page-header h2 { font-size: 20px; font-weight: 600; }
|
||||
</style>
|
||||
@@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<div class="login-page">
|
||||
<div class="login-card">
|
||||
<h2>后台管理</h2>
|
||||
<p class="subtitle">言逍导航</p>
|
||||
<el-form @submit.prevent="handleLogin">
|
||||
<el-form-item>
|
||||
<el-input v-model="form.username" placeholder="用户名" size="large" autofocus>
|
||||
<template #prefix><el-icon><User /></el-icon></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-input v-model="form.password" type="password" placeholder="密码" size="large" show-password @keyup.enter="handleLogin">
|
||||
<template #prefix><el-icon><Lock /></el-icon></template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-button type="primary" size="large" class="login-btn" @click="handleLogin" :loading="loading">登录</el-button>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { User, Lock } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { authApi } from '@/api'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
const router = useRouter()
|
||||
const store = useUserStore()
|
||||
const loading = ref(false)
|
||||
const form = ref({ username: '', password: '' })
|
||||
|
||||
async function handleLogin() {
|
||||
if (!form.value.username || !form.value.password) {
|
||||
ElMessage.warning('请输入用户名和密码')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await authApi.login(form.value)
|
||||
store.setToken(res.data.token)
|
||||
await store.fetchProfile()
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/admin/dashboard')
|
||||
} catch {
|
||||
ElMessage.error('用户名或密码错误')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea, #764ba2);
|
||||
}
|
||||
.login-card {
|
||||
background: white;
|
||||
padding: 48px 40px;
|
||||
border-radius: 16px;
|
||||
width: 380px;
|
||||
box-shadow: 0 20px 60px rgba(0,0,0,0.2);
|
||||
text-align: center;
|
||||
}
|
||||
.login-card h2 { font-size: 24px; font-weight: 700; }
|
||||
.subtitle { color: #888; margin: 8px 0 24px; }
|
||||
.login-btn { width: 100%; margin-top: 8px; }
|
||||
</style>
|
||||
@@ -0,0 +1,59 @@
|
||||
<template>
|
||||
<div class="settings-page">
|
||||
<div class="page-header"><h2>站点配置</h2></div>
|
||||
|
||||
<el-card>
|
||||
<el-form :model="settings" label-width="120px">
|
||||
<el-form-item label="站点名称">
|
||||
<el-input v-model="settings.site_name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="站点描述">
|
||||
<el-input v-model="settings.site_description" />
|
||||
</el-form-item>
|
||||
<el-form-item label="主题色">
|
||||
<el-color-picker v-model="settings.theme_color" />
|
||||
</el-form-item>
|
||||
<el-form-item label="布局模式">
|
||||
<el-radio-group v-model="settings.layout_mode">
|
||||
<el-radio value="grid">卡片网格</el-radio>
|
||||
<el-radio value="list">列表</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="页脚文字">
|
||||
<el-input v-model="settings.footer_text" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="save">保存配置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { adminApi } from '@/api'
|
||||
|
||||
const settings = ref({
|
||||
site_name: '',
|
||||
site_description: '',
|
||||
theme_color: '#6366F1',
|
||||
layout_mode: 'grid',
|
||||
footer_text: '',
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
Object.assign(settings.value, (await adminApi.getSettings()).result.data)
|
||||
})
|
||||
|
||||
async function save() {
|
||||
await adminApi.updateSettings(settings.value)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-header { margin-bottom: 20px; }
|
||||
.page-header h2 { font-size: 20px; font-weight: 600; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user