前端启动成功

This commit is contained in:
2025-10-07 13:31:06 +08:00
parent 8bd1edc75d
commit 741e89bc62
39 changed files with 19370 additions and 1458 deletions

View File

@@ -0,0 +1,101 @@
<template>
<div class="forgot-password-container">
<div class="forgot-password-box">
<div class="forgot-password-header">
<div class="logo">
<img src="@/assets/logo.png" alt="Logo" />
</div>
<h1 class="title">找回密码</h1>
<p class="subtitle">重置您的账户密码</p>
</div>
<div class="forgot-password-form">
<!-- 找回密码表单内容 -->
<div class="form-placeholder">
<p>找回密码功能开发中...</p>
</div>
</div>
<div class="forgot-password-footer">
<p>
想起密码了
<el-link type="primary" @click="goToLogin">返回登录</el-link>
</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
function goToLogin() {
router.push('/login');
}
</script>
<style lang="scss" scoped>
.forgot-password-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.forgot-password-box {
width: 100%;
max-width: 400px;
background: white;
border-radius: 12px;
padding: 40px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.forgot-password-header {
text-align: center;
margin-bottom: 32px;
.logo img {
width: 64px;
height: 64px;
margin-bottom: 16px;
}
.title {
font-size: 24px;
font-weight: 600;
color: #333;
margin: 0 0 8px 0;
}
.subtitle {
color: #666;
font-size: 14px;
margin: 0;
}
}
.forgot-password-form {
.form-placeholder {
text-align: center;
padding: 60px 20px;
color: #999;
font-size: 16px;
}
}
.forgot-password-footer {
text-align: center;
margin-top: 24px;
p {
color: #666;
font-size: 14px;
margin: 0;
}
}
</style>

View File

@@ -0,0 +1,286 @@
<template>
<div class="login-container">
<div class="login-box">
<div class="login-header">
<div class="logo">
<img src="@/assets/logo.png" alt="Logo" />
</div>
<h1 class="title">校园新闻管理系统</h1>
<p class="subtitle">登录您的账户</p>
</div>
<el-form
ref="loginFormRef"
:model="loginForm"
:rules="loginRules"
class="login-form"
size="large"
@submit.prevent="handleLogin"
>
<el-form-item prop="username">
<el-input
v-model="loginForm.username"
placeholder="请输入用户名"
prefix-icon="User"
clearable
/>
</el-form-item>
<el-form-item prop="password">
<el-input
v-model="loginForm.password"
type="password"
placeholder="请输入密码"
prefix-icon="Lock"
show-password
clearable
/>
</el-form-item>
<el-form-item prop="captcha" v-if="showCaptcha">
<div class="captcha-input">
<el-input
v-model="loginForm.captcha"
placeholder="请输入验证码"
prefix-icon="PictureRounded"
clearable
/>
<div class="captcha-image" @click="refreshCaptcha">
<img :src="captchaImage" alt="验证码" v-if="captchaImage" />
<div class="captcha-loading" v-else>加载中...</div>
</div>
</div>
</el-form-item>
<el-form-item>
<div class="login-options">
<el-checkbox v-model="loginForm.rememberMe">
记住我
</el-checkbox>
<el-link type="primary" @click="goToForgotPassword">
忘记密码
</el-link>
</div>
</el-form-item>
<el-form-item>
<el-button
type="primary"
size="large"
:loading="loginLoading"
@click="handleLogin"
class="login-button"
>
登录
</el-button>
</el-form-item>
</el-form>
<div class="login-footer">
<p>
还没有账户
<el-link type="primary" @click="goToRegister">立即注册</el-link>
</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { useStore } from 'vuex';
import { ElMessage, type FormInstance, type FormRules } from 'element-plus';
import type { LoginParam } from '@/types';
import { authApi } from '@/apis/auth';
// 响应式引用
const loginFormRef = ref<FormInstance>();
const loginLoading = ref(false);
const showCaptcha = ref(false);
const captchaImage = ref('');
// Composition API
const router = useRouter();
const route = useRoute();
const store = useStore();
// 表单数据
const loginForm = reactive<LoginParam>({
username: '',
password: '',
captcha: '',
captchaId: '',
rememberMe: false
});
// 表单验证规则
const loginRules: FormRules = {
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{ min: 3, max: 20, message: '用户名长度为3-20个字符', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, message: '密码至少6个字符', trigger: 'blur' }
],
captcha: [
{ required: true, message: '请输入验证码', trigger: 'blur' },
{ len: 4, message: '验证码为4位', trigger: 'blur' }
]
};
// 方法
const handleLogin = async () => {
if (!loginFormRef.value) return;
try {
const valid = await loginFormRef.value.validate();
if (!valid) return;
loginLoading.value = true;
// 调用store中的登录action
await store.dispatch('auth/login', loginForm);
ElMessage.success('登录成功!');
// 获取重定向路径
const redirectPath = (route.query.redirect as string) || '/dashboard';
router.push(redirectPath);
} catch (error: any) {
console.error('登录失败:', error);
ElMessage.error(error.message || '登录失败,请检查用户名和密码');
// 登录失败后显示验证码
showCaptcha.value = true;
refreshCaptcha();
} finally {
loginLoading.value = false;
}
};
const refreshCaptcha = async () => {
try {
const captchaData = await authApi.getCaptcha();
captchaImage.value = captchaData.captchaImage;
loginForm.captchaId = captchaData.captchaId;
} catch (error) {
console.error('获取验证码失败:', error);
ElMessage.error('获取验证码失败');
}
};
function goToRegister() {
router.push('/register');
}
function goToForgotPassword() {
router.push('/forgot-password');
}
// 组件挂载时检查是否需要显示验证码
onMounted(() => {
// 可以根据需要决定是否默认显示验证码
// refreshCaptcha();
});
</script>
<style lang="scss" scoped>
.login-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.login-box {
width: 100%;
max-width: 400px;
background: white;
border-radius: 12px;
padding: 40px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.login-header {
text-align: center;
margin-bottom: 32px;
.logo img {
width: 64px;
height: 64px;
margin-bottom: 16px;
}
.title {
font-size: 24px;
font-weight: 600;
color: #333;
margin: 0 0 8px 0;
}
.subtitle {
color: #666;
font-size: 14px;
margin: 0;
}
}
.login-form {
.captcha-input {
display: flex;
gap: 12px;
.el-input {
flex: 1;
}
.captcha-image {
width: 100px;
height: 40px;
border: 1px solid #dcdfe6;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
img {
max-width: 100%;
max-height: 100%;
}
.captcha-loading {
font-size: 12px;
color: #999;
}
}
}
.login-options {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}
.login-button {
width: 100%;
}
}
.login-footer {
text-align: center;
margin-top: 24px;
p {
color: #666;
font-size: 14px;
margin: 0;
}
}
</style>

View File

@@ -0,0 +1,101 @@
<template>
<div class="register-container">
<div class="register-box">
<div class="register-header">
<div class="logo">
<img src="@/assets/logo.png" alt="Logo" />
</div>
<h1 class="title">注册账户</h1>
<p class="subtitle">创建您的校园新闻管理系统账户</p>
</div>
<div class="register-form">
<!-- 注册表单内容 -->
<div class="form-placeholder">
<p>注册功能开发中...</p>
</div>
</div>
<div class="register-footer">
<p>
已有账户
<el-link type="primary" @click="goToLogin">立即登录</el-link>
</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
function goToLogin() {
router.push('/login');
}
</script>
<style lang="scss" scoped>
.register-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.register-box {
width: 100%;
max-width: 400px;
background: white;
border-radius: 12px;
padding: 40px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.register-header {
text-align: center;
margin-bottom: 32px;
.logo img {
width: 64px;
height: 64px;
margin-bottom: 16px;
}
.title {
font-size: 24px;
font-weight: 600;
color: #333;
margin: 0 0 8px 0;
}
.subtitle {
color: #666;
font-size: 14px;
margin: 0;
}
}
.register-form {
.form-placeholder {
text-align: center;
padding: 60px 20px;
color: #999;
font-size: 16px;
}
}
.register-footer {
text-align: center;
margin-top: 24px;
p {
color: #666;
font-size: 14px;
margin: 0;
}
}
</style>

View File

@@ -0,0 +1,466 @@
<template>
<div class="workplace">
<div class="workplace-header">
<div class="welcome-info">
<h1 class="welcome-title">
欢迎回来{{ userInfo?.realName || userInfo?.username }}
</h1>
<p class="welcome-subtitle">
今天是 {{ currentDate }}{{ greetingText }}
</p>
</div>
<div class="user-stats">
<div class="stat-card">
<div class="stat-icon">📝</div>
<div class="stat-content">
<div class="stat-number">{{ todayNews }}</div>
<div class="stat-label">今日新闻</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon">👥</div>
<div class="stat-content">
<div class="stat-number">{{ onlineUsers }}</div>
<div class="stat-label">在线用户</div>
</div>
</div>
<div class="stat-card" v-permission="'system:news:view'">
<div class="stat-icon">📊</div>
<div class="stat-content">
<div class="stat-number">{{ totalViews }}</div>
<div class="stat-label">总阅读量</div>
</div>
</div>
</div>
</div>
<div class="workplace-content">
<!-- 快捷操作 -->
<div class="quick-actions">
<h2 class="section-title">快捷操作</h2>
<div class="action-grid">
<div class="action-card" @click="goToCreateNews" v-permission="'news:create'">
<div class="action-icon"></div>
<div class="action-title">发布新闻</div>
<div class="action-desc">创建新的校园新闻</div>
</div>
<div class="action-card" @click="goToUserManage" v-permission="'system:user:view'">
<div class="action-icon">👤</div>
<div class="action-title">用户管理</div>
<div class="action-desc">管理系统用户</div>
</div>
<div class="action-card" @click="goToSystemSettings" v-permission="'system:settings:view'">
<div class="action-icon"></div>
<div class="action-title">系统设置</div>
<div class="action-desc">配置系统参数</div>
</div>
<div class="action-card" @click="goToProfile">
<div class="action-icon">📋</div>
<div class="action-title">个人资料</div>
<div class="action-desc">编辑个人信息</div>
</div>
</div>
</div>
<!-- 最近活动 -->
<div class="recent-activities">
<h2 class="section-title">最近活动</h2>
<div class="activity-list">
<div class="activity-item" v-for="activity in recentActivities" :key="activity.id">
<div class="activity-icon" :class="activity.type">
{{ getActivityIcon(activity.type) }}
</div>
<div class="activity-content">
<div class="activity-title">{{ activity.title }}</div>
<div class="activity-time">{{ formatTime(activity.time) }}</div>
</div>
</div>
</div>
</div>
<!-- 系统公告 -->
<div class="system-notice">
<h2 class="section-title">系统公告</h2>
<div class="notice-list">
<div class="notice-item" v-for="notice in systemNotices" :key="notice.id">
<div class="notice-type" :class="notice.type">
{{ getNoticeTypeText(notice.type) }}
</div>
<div class="notice-content">
<div class="notice-title">{{ notice.title }}</div>
<div class="notice-time">{{ formatTime(notice.time) }}</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
// import { usePermission } from '@/directives/permission'; // 暂时注释,后续权限功能开发时启用
// 数据
const todayNews = ref(12);
const onlineUsers = ref(56);
const totalViews = ref(8924);
const recentActivities = ref([
{
id: 1,
type: 'news',
title: '发布了新闻《学校举办科技创新大赛》',
time: new Date(Date.now() - 10 * 60 * 1000) // 10分钟前
},
{
id: 2,
type: 'user',
title: '新用户注册:张三',
time: new Date(Date.now() - 30 * 60 * 1000) // 30分钟前
},
{
id: 3,
type: 'system',
title: '系统维护完成',
time: new Date(Date.now() - 2 * 60 * 60 * 1000) // 2小时前
}
]);
const systemNotices = ref([
{
id: 1,
type: 'info',
title: '系统将于本周日进行例行维护',
time: new Date(Date.now() - 24 * 60 * 60 * 1000) // 1天前
},
{
id: 2,
type: 'warning',
title: '请及时更新个人资料信息',
time: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000) // 3天前
}
]);
// Composition API
const router = useRouter();
const store = useStore();
// const { hasPermission } = usePermission(); // 暂时注释,后续权限功能开发时启用
// 计算属性
const userInfo = computed(() => store.getters['auth/userInfo']);
const currentDate = computed(() => {
return new Date().toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long'
});
});
const greetingText = computed(() => {
const hour = new Date().getHours();
if (hour < 6) return '夜深了,注意休息';
if (hour < 12) return '早上好';
if (hour < 18) return '下午好';
return '晚上好';
});
// 方法
function goToCreateNews() {
router.push('/news/create');
}
function goToUserManage() {
router.push('/system/user');
}
function goToSystemSettings() {
router.push('/system/settings');
}
function goToProfile() {
router.push('/profile');
}
function getActivityIcon(type: string) {
const icons = {
news: '📰',
user: '👤',
system: '⚙️'
};
return icons[type as keyof typeof icons] || '📝';
}
function getNoticeTypeText(type: string) {
const types = {
info: '通知',
warning: '提醒',
error: '警告'
};
return types[type as keyof typeof types] || '公告';
}
function formatTime(time: Date) {
const now = new Date();
const diff = now.getTime() - time.getTime();
if (diff < 60 * 1000) return '刚刚';
if (diff < 60 * 60 * 1000) return `${Math.floor(diff / 60 / 1000)}分钟前`;
if (diff < 24 * 60 * 60 * 1000) return `${Math.floor(diff / 60 / 60 / 1000)}小时前`;
if (diff < 7 * 24 * 60 * 60 * 1000) return `${Math.floor(diff / 24 / 60 / 60 / 1000)}天前`;
return time.toLocaleDateString('zh-CN');
}
// 生命周期
onMounted(() => {
// 可以在这里加载统计数据
});
</script>
<style lang="scss" scoped>
.workplace {
padding: 0;
}
.workplace-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 32px;
border-radius: 8px;
margin-bottom: 24px;
.welcome-info {
margin-bottom: 24px;
.welcome-title {
font-size: 28px;
font-weight: 600;
margin: 0 0 8px 0;
}
.welcome-subtitle {
font-size: 16px;
opacity: 0.9;
margin: 0;
}
}
.user-stats {
display: flex;
gap: 24px;
flex-wrap: wrap;
}
.stat-card {
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
padding: 20px;
display: flex;
align-items: center;
gap: 16px;
min-width: 150px;
backdrop-filter: blur(10px);
.stat-icon {
font-size: 32px;
}
.stat-content {
.stat-number {
font-size: 24px;
font-weight: 600;
line-height: 1;
}
.stat-label {
font-size: 14px;
opacity: 0.8;
margin-top: 4px;
}
}
}
}
.workplace-content {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
@media (max-width: 768px) {
grid-template-columns: 1fr;
}
}
.section-title {
font-size: 18px;
font-weight: 600;
margin: 0 0 16px 0;
color: #333;
}
.quick-actions {
background: white;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
.action-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 16px;
}
.action-card {
padding: 20px;
border: 1px solid #e8e8e8;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s ease;
text-align: center;
&:hover {
border-color: #1890ff;
box-shadow: 0 2px 8px rgba(24, 144, 255, 0.2);
transform: translateY(-2px);
}
.action-icon {
font-size: 32px;
margin-bottom: 12px;
}
.action-title {
font-size: 16px;
font-weight: 600;
color: #333;
margin-bottom: 8px;
}
.action-desc {
font-size: 14px;
color: #666;
}
}
}
.recent-activities {
background: white;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
grid-column: 1;
.activity-list {
.activity-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
&:last-child {
border-bottom: none;
}
.activity-icon {
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
&.news { background: #e6f7ff; }
&.user { background: #f6ffed; }
&.system { background: #fff7e6; }
}
.activity-content {
flex: 1;
.activity-title {
font-size: 14px;
color: #333;
margin-bottom: 4px;
}
.activity-time {
font-size: 12px;
color: #999;
}
}
}
}
}
.system-notice {
background: white;
padding: 24px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
grid-column: 2;
.notice-list {
.notice-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 0;
border-bottom: 1px solid #f0f0f0;
&:last-child {
border-bottom: none;
}
.notice-type {
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
&.info {
background: #e6f7ff;
color: #1890ff;
}
&.warning {
background: #fff7e6;
color: #fa8c16;
}
&.error {
background: #fff2f0;
color: #f5222d;
}
}
.notice-content {
flex: 1;
.notice-title {
font-size: 14px;
color: #333;
margin-bottom: 4px;
}
.notice-time {
font-size: 12px;
color: #999;
}
}
}
}
}
</style>

View File

@@ -0,0 +1,90 @@
<template>
<div class="error-page">
<div class="error-content">
<div class="error-icon">
<span class="error-number">403</span>
</div>
<div class="error-info">
<h1 class="error-title">无权限访问</h1>
<p class="error-description">
抱歉您没有权限访问此页面请联系管理员获取相应权限
</p>
<div class="error-actions">
<el-button type="primary" @click="goHome">
返回首页
</el-button>
<el-button @click="goBack">
返回上页
</el-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
function goHome() {
router.push('/dashboard');
}
function goBack() {
router.go(-1);
}
</script>
<style lang="scss" scoped>
.error-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
padding: 20px;
}
.error-content {
text-align: center;
max-width: 500px;
}
.error-icon {
margin-bottom: 32px;
.error-number {
font-size: 120px;
font-weight: 700;
color: #fa8c16;
line-height: 1;
text-shadow: 0 4px 8px rgba(250, 140, 22, 0.2);
}
}
.error-info {
.error-title {
font-size: 32px;
font-weight: 600;
color: #333;
margin: 0 0 16px 0;
}
.error-description {
font-size: 16px;
color: #666;
margin: 0 0 32px 0;
line-height: 1.6;
}
.error-actions {
display: flex;
gap: 16px;
justify-content: center;
flex-wrap: wrap;
}
}
</style>

View File

@@ -0,0 +1,90 @@
<template>
<div class="error-page">
<div class="error-content">
<div class="error-icon">
<span class="error-number">404</span>
</div>
<div class="error-info">
<h1 class="error-title">页面不存在</h1>
<p class="error-description">
抱歉您访问的页面不存在或已被删除
</p>
<div class="error-actions">
<el-button type="primary" @click="goHome">
返回首页
</el-button>
<el-button @click="goBack">
返回上页
</el-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
function goHome() {
router.push('/dashboard');
}
function goBack() {
router.go(-1);
}
</script>
<style lang="scss" scoped>
.error-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
padding: 20px;
}
.error-content {
text-align: center;
max-width: 500px;
}
.error-icon {
margin-bottom: 32px;
.error-number {
font-size: 120px;
font-weight: 700;
color: #1890ff;
line-height: 1;
text-shadow: 0 4px 8px rgba(24, 144, 255, 0.2);
}
}
.error-info {
.error-title {
font-size: 32px;
font-weight: 600;
color: #333;
margin: 0 0 16px 0;
}
.error-description {
font-size: 16px;
color: #666;
margin: 0 0 32px 0;
line-height: 1.6;
}
.error-actions {
display: flex;
gap: 16px;
justify-content: center;
flex-wrap: wrap;
}
}
</style>

View File

@@ -0,0 +1,90 @@
<template>
<div class="error-page">
<div class="error-content">
<div class="error-icon">
<span class="error-number">500</span>
</div>
<div class="error-info">
<h1 class="error-title">服务器错误</h1>
<p class="error-description">
抱歉服务器出现内部错误请稍后重试或联系技术支持
</p>
<div class="error-actions">
<el-button type="primary" @click="refresh">
刷新页面
</el-button>
<el-button @click="goHome">
返回首页
</el-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
function refresh() {
location.reload();
}
function goHome() {
router.push('/dashboard');
}
</script>
<style lang="scss" scoped>
.error-page {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
padding: 20px;
}
.error-content {
text-align: center;
max-width: 500px;
}
.error-icon {
margin-bottom: 32px;
.error-number {
font-size: 120px;
font-weight: 700;
color: #f5222d;
line-height: 1;
text-shadow: 0 4px 8px rgba(245, 34, 45, 0.2);
}
}
.error-info {
.error-title {
font-size: 32px;
font-weight: 600;
color: #333;
margin: 0 0 16px 0;
}
.error-description {
font-size: 16px;
color: #666;
margin: 0 0 32px 0;
line-height: 1.6;
}
.error-actions {
display: flex;
gap: 16px;
justify-content: center;
flex-wrap: wrap;
}
}
</style>