parent
8b57c2932a
commit
1d05a6a2fd
@ -1,8 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Front.iml" filepath="$PROJECT_DIR$/.idea/Front.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +0,0 @@
|
||||
import userApi from './user';
|
||||
|
||||
export {
|
||||
userApi
|
||||
};
|
@ -1,119 +0,0 @@
|
||||
import { get, post, put } from './request';
|
||||
|
||||
// 用户接口类型定义
|
||||
export interface UserInfo {
|
||||
username: string;
|
||||
email: string;
|
||||
avatar?: string;
|
||||
gender?: number;
|
||||
bio?: string;
|
||||
birthday?: string;
|
||||
studentId?: string;
|
||||
department?: string;
|
||||
major?: string;
|
||||
grade?: string;
|
||||
}
|
||||
|
||||
export interface LoginParams {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface RegisterParams {
|
||||
email: string;
|
||||
password: string;
|
||||
username?: string;
|
||||
nickname?: string;
|
||||
studentId?: string;
|
||||
department?: string;
|
||||
major?: string;
|
||||
grade?: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface EmailCodeParams {
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface VerifyCodeParams {
|
||||
email: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface UpdateProfileParams {
|
||||
username?: string;
|
||||
bio?: string;
|
||||
gender?: number;
|
||||
birthday?: string;
|
||||
}
|
||||
|
||||
export interface UpdatePasswordParams {
|
||||
code: string;
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
// 用户API
|
||||
export default {
|
||||
// 登录
|
||||
login(data: LoginParams) {
|
||||
return post<{code: number; data: {token: string}}>(
|
||||
'/users/login',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 注册
|
||||
register(data: RegisterParams) {
|
||||
return post<{code: number; data: {token: string}}>(
|
||||
'/users/register',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 获取邮箱验证码
|
||||
getEmailCode(data: EmailCodeParams) {
|
||||
return post<{code: number; message: string}>(
|
||||
'/users/code',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 验证邮箱验证码
|
||||
verifyEmailCode(data: VerifyCodeParams) {
|
||||
return post<{code: number; data: {token: string}}>(
|
||||
'/users/login/code',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
getUserInfo() {
|
||||
return get<{code: number; data: UserInfo}>(
|
||||
'/users/info'
|
||||
);
|
||||
},
|
||||
|
||||
// 更新用户资料
|
||||
updateProfile(data: UpdateProfileParams) {
|
||||
return put<{code: number; message: string}>(
|
||||
'/users/profile',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 更新用户密码
|
||||
updatePassword(data: UpdatePasswordParams) {
|
||||
return put<{code: number; message: string}>(
|
||||
'/users/password',
|
||||
data
|
||||
);
|
||||
},
|
||||
|
||||
// 上传头像
|
||||
uploadAvatar(formData: FormData) {
|
||||
return post<{code: number; data: {avatarUrl: string}}>(
|
||||
'/users/avatar',
|
||||
formData
|
||||
);
|
||||
}
|
||||
};
|
@ -1,76 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useUIStore } from '../stores';
|
||||
|
||||
const uiStore = useUIStore();
|
||||
|
||||
// 计算是否显示加载状态
|
||||
const isVisible = computed(() => uiStore.isLoading);
|
||||
const loadingText = computed(() => uiStore.loadingText);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<transition name="fade">
|
||||
<div v-if="isVisible" class="loading-overlay">
|
||||
<div class="loading-container">
|
||||
<div class="loading-spinner"></div>
|
||||
<div class="loading-text">{{ loadingText }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border: 4px solid var(--secondary-color);
|
||||
border-top: 4px solid var(--primary-color);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
color: var(--text-primary);
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.fade-enter-active,
|
||||
.fade-leave-active {
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.fade-enter-from,
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
@ -0,0 +1,24 @@
|
||||
<script lang="ts">
|
||||
import Personal from './Personal/Personal.vue'
|
||||
import { defineComponent } from "vue";
|
||||
export default defineComponent({
|
||||
name:'PersonalLayout',
|
||||
components:{
|
||||
Personal
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Personal/>
|
||||
<div>
|
||||
<router-view/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
@ -0,0 +1,27 @@
|
||||
import request from "../../src/utils/request"
|
||||
|
||||
|
||||
export function useEmailCode(){
|
||||
const sendEmailCode = async(email:string) =>
|
||||
{
|
||||
return await request.post('/user/code',
|
||||
{
|
||||
params:{email:email}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const verifyEmailCode = async(email:string,code:string) =>
|
||||
{
|
||||
return await request.post('users/login/code',
|
||||
{
|
||||
params:{email:email,code:code}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return{
|
||||
sendEmailCode,
|
||||
verifyEmailCode
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
import { ref } from 'vue';
|
||||
import { userApi } from '../api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
export function useEmailCode() {
|
||||
const isSending = ref(false);
|
||||
const countdown = ref(0);
|
||||
let timer: number | null = null;
|
||||
|
||||
// 发送邮箱验证码
|
||||
const sendEmailCode = async (email: string) => {
|
||||
if (isSending.value) return;
|
||||
|
||||
if (!email) {
|
||||
ElMessage.warning('请输入邮箱地址');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isSending.value = true;
|
||||
const res = await userApi.getEmailCode({ email });
|
||||
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('验证码已发送,请查收邮件');
|
||||
startCountdown();
|
||||
}
|
||||
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error('发送验证码失败:', error);
|
||||
ElMessage.error('发送验证码失败,请稍后重试');
|
||||
} finally {
|
||||
isSending.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 验证邮箱验证码
|
||||
const verifyEmailCode = async (email: string, code: string) => {
|
||||
if (!email || !code) {
|
||||
ElMessage.warning('请输入邮箱和验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await userApi.verifyEmailCode({ email, code });
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error('验证码验证失败:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 开始倒计时
|
||||
const startCountdown = () => {
|
||||
countdown.value = 60;
|
||||
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
|
||||
timer = window.setInterval(() => {
|
||||
if (countdown.value > 0) {
|
||||
countdown.value--;
|
||||
} else {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
return {
|
||||
isSending,
|
||||
countdown,
|
||||
sendEmailCode,
|
||||
verifyEmailCode
|
||||
};
|
||||
}
|
@ -1,26 +1,16 @@
|
||||
import { createApp } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import ElementPlus from 'element-plus';
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import router from './routers'
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
|
||||
// 样式
|
||||
import 'element-plus/dist/index.css';
|
||||
import './styles/global.css';
|
||||
const app = createApp(App)
|
||||
|
||||
// 创建应用实例
|
||||
const app = createApp(App);
|
||||
|
||||
// 使用插件
|
||||
app.use(createPinia());
|
||||
app.use(ElementPlus);
|
||||
app.use(router);
|
||||
|
||||
// 注册所有Element Plus图标
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component);
|
||||
app.use(ElementPlus)
|
||||
app.use(router)
|
||||
for(const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
|
||||
// 挂载应用
|
||||
app.mount('#app');
|
||||
app.mount('#app')
|
||||
|
@ -1,129 +0,0 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { useUserStore } from '../stores';
|
||||
|
||||
// 布局
|
||||
import BaseLayout from '../layouts/BaseLayout.vue';
|
||||
import PersonalLayout from '../layouts/PersonalLayout.vue';
|
||||
|
||||
// 页面
|
||||
import Login from '../views/Login.vue';
|
||||
import Home from '../views/Home.vue';
|
||||
import AccountManager from '../views/AccountManager.vue';
|
||||
import NotFound from '../views/NotFound.vue';
|
||||
|
||||
// 路由配置
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/',
|
||||
component: BaseLayout,
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirect: '/login'
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
name: 'Login',
|
||||
component: Login,
|
||||
meta: {
|
||||
title: '登录 - UniLife学生论坛',
|
||||
requiresAuth: false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/personal',
|
||||
component: PersonalLayout,
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'Home',
|
||||
component: Home,
|
||||
meta: {
|
||||
title: '个人主页 - UniLife学生论坛',
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'account',
|
||||
name: 'AccountManager',
|
||||
component: AccountManager,
|
||||
meta: {
|
||||
title: '账号管理 - UniLife学生论坛',
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
// 其他个人中心页面可以在这里添加
|
||||
{
|
||||
path: 'posts',
|
||||
name: 'Posts',
|
||||
component: () => import('../views/NotFound.vue'), // 暂时使用NotFound页面
|
||||
meta: {
|
||||
title: '我的帖子 - UniLife学生论坛',
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'messages',
|
||||
name: 'Messages',
|
||||
component: () => import('../views/NotFound.vue'), // 暂时使用NotFound页面
|
||||
meta: {
|
||||
title: '消息中心 - UniLife学生论坛',
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'settings',
|
||||
name: 'Settings',
|
||||
component: () => import('../views/NotFound.vue'), // 暂时使用NotFound页面
|
||||
meta: {
|
||||
title: '设置 - UniLife学生论坛',
|
||||
requiresAuth: true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'NotFound',
|
||||
component: NotFound,
|
||||
meta: {
|
||||
title: '页面不存在 - UniLife学生论坛'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes
|
||||
});
|
||||
|
||||
// 全局前置守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 设置页面标题
|
||||
document.title = to.meta.title as string || 'UniLife学生论坛';
|
||||
|
||||
// 检查是否需要登录权限
|
||||
if (to.matched.some(record => record.meta.requiresAuth)) {
|
||||
const userStore = useUserStore();
|
||||
|
||||
// 如果需要登录但用户未登录,重定向到登录页
|
||||
if (!userStore.isLoggedIn) {
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: to.fullPath }
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
@ -0,0 +1,44 @@
|
||||
import type { RouteRecord, RouteRecordRaw } from 'vue-router';
|
||||
import { createWebHashHistory, createRouter,createWebHistory } from 'vue-router';
|
||||
import LogPage from './components/LogPage.vue';
|
||||
import Personal from './components/Personal/Personal.vue'
|
||||
import Manager from './components/Personal/AcountManager.vue';
|
||||
import PersonalLayout from './components/PersonLayout.vue'
|
||||
import PersonalHome from './components/Personal/Home.vue'
|
||||
|
||||
const routes:Array<RouteRecordRaw> = [
|
||||
{
|
||||
path:'/log',
|
||||
name: 'LogPage',
|
||||
component: LogPage
|
||||
},
|
||||
{
|
||||
path:'/personal',
|
||||
name: 'Personal',
|
||||
component: Personal,
|
||||
children: [
|
||||
{
|
||||
path:'',
|
||||
name:'Home',
|
||||
component:PersonalHome,
|
||||
},
|
||||
{
|
||||
path:'manager',
|
||||
name: 'Manager',
|
||||
component:Manager,
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
path:"/personalLayout",
|
||||
name:'Personallayout',
|
||||
component:PersonalLayout,
|
||||
}
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes
|
||||
});
|
||||
|
||||
export default router;
|
@ -1,7 +0,0 @@
|
||||
import { useUserStore } from './user';
|
||||
import { useUIStore } from './ui';
|
||||
|
||||
export {
|
||||
useUserStore,
|
||||
useUIStore
|
||||
};
|
@ -1,66 +0,0 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const useUIStore = defineStore('ui', () => {
|
||||
// 状态
|
||||
const isMobileView = ref(false);
|
||||
const isSidebarCollapsed = ref(false);
|
||||
const isDarkMode = ref(false);
|
||||
const isLoading = ref(false);
|
||||
const loadingText = ref('加载中...');
|
||||
|
||||
// 检测是否为移动视图
|
||||
const checkMobileView = () => {
|
||||
isMobileView.value = window.innerWidth < 768;
|
||||
};
|
||||
|
||||
// 切换侧边栏状态
|
||||
const toggleSidebar = () => {
|
||||
isSidebarCollapsed.value = !isSidebarCollapsed.value;
|
||||
};
|
||||
|
||||
// 切换暗黑模式
|
||||
const toggleDarkMode = () => {
|
||||
isDarkMode.value = !isDarkMode.value;
|
||||
|
||||
// 应用暗黑模式到文档
|
||||
if (isDarkMode.value) {
|
||||
document.documentElement.classList.add('dark-mode');
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark-mode');
|
||||
}
|
||||
};
|
||||
|
||||
// 设置加载状态
|
||||
const setLoading = (loading: boolean, text?: string) => {
|
||||
isLoading.value = loading;
|
||||
if (text) {
|
||||
loadingText.value = text;
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化
|
||||
const initialize = () => {
|
||||
// 检测移动视图
|
||||
checkMobileView();
|
||||
window.addEventListener('resize', checkMobileView);
|
||||
|
||||
// 检测系统暗黑模式偏好
|
||||
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
if (prefersDarkMode) {
|
||||
toggleDarkMode();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isMobileView,
|
||||
isSidebarCollapsed,
|
||||
isDarkMode,
|
||||
isLoading,
|
||||
loadingText,
|
||||
toggleSidebar,
|
||||
toggleDarkMode,
|
||||
setLoading,
|
||||
initialize
|
||||
};
|
||||
});
|
@ -1,187 +0,0 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
import userApi from '../api/user';
|
||||
import type { UserInfo } from '../api/user';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
// 状态
|
||||
const token = ref<string>(localStorage.getItem('token') || '');
|
||||
const userInfo = ref<UserInfo | null>(null);
|
||||
const isLoggedIn = ref<boolean>(!!token.value);
|
||||
const loading = ref<boolean>(false);
|
||||
|
||||
// 设置token
|
||||
const setToken = (newToken: string) => {
|
||||
token.value = newToken;
|
||||
localStorage.setItem('token', newToken);
|
||||
isLoggedIn.value = true;
|
||||
};
|
||||
|
||||
// 清除token
|
||||
const clearToken = () => {
|
||||
token.value = '';
|
||||
localStorage.removeItem('token');
|
||||
isLoggedIn.value = false;
|
||||
};
|
||||
|
||||
// 登录
|
||||
const login = async (email: string, password: string) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await userApi.login({ email, password });
|
||||
|
||||
if (res.code === 200 && res.data.token) {
|
||||
setToken(res.data.token);
|
||||
ElMessage.success('登录成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error);
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 通过验证码登录
|
||||
const loginWithCode = async (email: string, code: string) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await userApi.verifyEmailCode({ email, code });
|
||||
|
||||
if (res.code === 200 && res.data.token) {
|
||||
setToken(res.data.token);
|
||||
ElMessage.success('登录成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error);
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 注册
|
||||
const register = async (email: string, password: string, code: string) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
|
||||
const res = await userApi.register({ email, password, code });
|
||||
|
||||
if (res.code === 200 && res.data.token) {
|
||||
setToken(res.data.token);
|
||||
ElMessage.success('注册成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('注册失败:', error);
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 登出
|
||||
const logout = () => {
|
||||
clearToken();
|
||||
userInfo.value = null;
|
||||
ElMessage.success('已退出登录');
|
||||
};
|
||||
|
||||
// 获取用户信息
|
||||
const fetchUserInfo = async () => {
|
||||
if (!token.value) return null;
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await userApi.getUserInfo();
|
||||
|
||||
if (res.code === 200) {
|
||||
userInfo.value = res.data;
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
return null;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新用户资料
|
||||
const updateProfile = async (data: {
|
||||
username?: string;
|
||||
bio?: string;
|
||||
gender?: number;
|
||||
birthday?: string;
|
||||
}) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await userApi.updateProfile(data);
|
||||
|
||||
if (res.code === 200) {
|
||||
// 更新本地用户信息
|
||||
if (userInfo.value) {
|
||||
userInfo.value = {
|
||||
...userInfo.value,
|
||||
...data
|
||||
};
|
||||
}
|
||||
|
||||
ElMessage.success('个人资料更新成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('更新个人资料失败:', error);
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 更新密码
|
||||
const updatePassword = async (code: string, newPassword: string) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const res = await userApi.updatePassword({ code, newPassword });
|
||||
|
||||
if (res.code === 200) {
|
||||
ElMessage.success('密码修改成功');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('修改密码失败:', error);
|
||||
return false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
token,
|
||||
userInfo,
|
||||
isLoggedIn,
|
||||
loading,
|
||||
login,
|
||||
loginWithCode,
|
||||
register,
|
||||
logout,
|
||||
fetchUserInfo,
|
||||
updateProfile,
|
||||
updatePassword
|
||||
};
|
||||
});
|
@ -0,0 +1,79 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
@import './variables.css';
|
||||
@import './reset.css';
|
||||
|
||||
/* 全局样式 */
|
||||
body {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
color: var(--text-primary);
|
||||
background-color: var(--bg-primary);
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* 通用容器 */
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: var(--content-max-width);
|
||||
margin: 0 auto;
|
||||
padding: var(--spacing-lg);
|
||||
}
|
||||
|
||||
/* 卡片样式 */
|
||||
.card {
|
||||
background-color: var(--bg-primary);
|
||||
border-radius: var(--border-radius-lg);
|
||||
padding: var(--spacing-xl);
|
||||
box-shadow: var(--shadow-md);
|
||||
transition: transform var(--transition-normal), box-shadow var(--transition-normal);
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
.btn {
|
||||
border: none;
|
||||
border-radius: var(--border-radius-md);
|
||||
padding: var(--spacing-sm) var(--spacing-lg);
|
||||
font-size: var(--font-size-md);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-normal);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
color: white;
|
||||
box-shadow: 0 4px 10px rgba(147, 112, 219, 0.3);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: var(--primary-dark);
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 12px rgba(147, 112, 219, 0.4);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--secondary-color);
|
||||
color: var(--text-secondary);
|
||||
box-shadow: 0 4px 10px rgba(230, 230, 250, 0.3);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: #dcdcdc;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 12px rgba(230, 230, 250, 0.4);
|
||||
}
|
||||
|
||||
/* 表单样式 */
|
||||
.form-group {
|
||||
margin-bottom: var(--spacing-md);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
width: 100px;
|
||||
font-size: var(--font-size-lg);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.form-input {
|
||||
flex: 1;
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
border: 2px solid var(--border-color);
|
||||
border-radius: var(--border-radius-md);
|
||||
outline: none;
|
||||
transition: border-color var(--transition-normal);
|
||||
font-size: var(--font-size-md);
|
||||
}
|
||||
|
||||
.form-input:focus {
|
||||
border-color: var(--primary-light);
|
||||
}
|
||||
|
||||
/* 响应式设计 */
|
||||
@media (max-width: 1024px) {
|
||||
.container {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.form-group {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
width: 100%;
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
}
|
||||
|
||||
/* 动画 */
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.fade-in {
|
||||
animation: fadeIn var(--transition-normal);
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
.float {
|
||||
animation: float 5s ease-in-out infinite;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/* CSS Reset */
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
img, picture, video, canvas, svg {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
input, button, textarea, select {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
p, h1, h2, h3, h4, h5, h6 {
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
ul, ol {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
button {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
:root {
|
||||
/* 主题颜色 */
|
||||
--primary-color: #9370DB;
|
||||
--primary-light: #b19cd9;
|
||||
--primary-dark: #8a63d2;
|
||||
--secondary-color: #e6e6fa;
|
||||
|
||||
/* 文本颜色 */
|
||||
--text-primary: #333333;
|
||||
--text-secondary: #666666;
|
||||
--text-light: #999999;
|
||||
|
||||
/* 背景颜色 */
|
||||
--bg-primary: #ffffff;
|
||||
--bg-secondary: #f9f7ff;
|
||||
--bg-gradient: linear-gradient(200deg, #f3e7e9, #e3eeff);
|
||||
|
||||
/* 边框颜色 */
|
||||
--border-color: #e6e6fa;
|
||||
|
||||
/* 阴影 */
|
||||
--shadow-sm: 0 2px 5px rgba(0, 0, 0, 0.05);
|
||||
--shadow-md: 0 5px 15px rgba(0, 0, 0, 0.05);
|
||||
--shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.1);
|
||||
|
||||
/* 圆角 */
|
||||
--border-radius-sm: 5px;
|
||||
--border-radius-md: 10px;
|
||||
--border-radius-lg: 20px;
|
||||
--border-radius-full: 50%;
|
||||
|
||||
/* 间距 */
|
||||
--spacing-xs: 5px;
|
||||
--spacing-sm: 10px;
|
||||
--spacing-md: 15px;
|
||||
--spacing-lg: 20px;
|
||||
--spacing-xl: 30px;
|
||||
|
||||
/* 字体大小 */
|
||||
--font-size-xs: 0.75rem;
|
||||
--font-size-sm: 0.875rem;
|
||||
--font-size-md: 1rem;
|
||||
--font-size-lg: 1.25rem;
|
||||
--font-size-xl: 1.5rem;
|
||||
--font-size-xxl: 2rem;
|
||||
|
||||
/* 过渡 */
|
||||
--transition-fast: 0.2s ease;
|
||||
--transition-normal: 0.3s ease;
|
||||
--transition-slow: 0.5s ease;
|
||||
|
||||
/* 布局 */
|
||||
--sidebar-width: 84px;
|
||||
--sidebar-width-expanded: 300px;
|
||||
--header-height: 60px;
|
||||
--content-max-width: 1280px;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: 'http://localhost:8080',
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
console.log("前端发送信息");
|
||||
return config;
|
||||
}
|
||||
else
|
||||
{ console.log("没有token");
|
||||
return config;
|
||||
}
|
||||
},
|
||||
error => {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
console.log("后端返回信息");
|
||||
return response.data;
|
||||
},
|
||||
error => {
|
||||
// 对响应错误做些什么
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
Loading…
Reference in new issue