修改小程序,前端,官网跳转路径

This commit is contained in:
2025-09-28 18:00:03 +08:00
parent ec3f472641
commit e79e5bb086
8 changed files with 199 additions and 22 deletions

View File

@@ -11,14 +11,14 @@ const getEnvVar = (key, defaultValue = '') => {
// API配置
export const API_CONFIG = {
// API基础URL
baseUrl: getEnvVar('VITE_API_BASE_URL', 'http://localhost:5351'),
// API基础URL - 根据环境动态设置
baseUrl: getEnvVar('VITE_API_BASE_URL', import.meta.env.DEV ? '/bank/api' : '/bank/api'),
// 是否使用代理
useProxy: getEnvVar('VITE_USE_PROXY', 'true') === 'true',
// 完整的基础URL用于直接请求
fullBaseUrl: getEnvVar('VITE_API_BASE_URL', 'http://localhost:5351'),
fullBaseUrl: getEnvVar('VITE_API_BASE_URL', import.meta.env.DEV ? '/bank/api' : '/bank/api'),
// 请求超时时间
timeout: parseInt(getEnvVar('VITE_API_TIMEOUT', '10000')),

View File

@@ -9,7 +9,7 @@ import routes from './routes'
// 创建路由实例
const router = createRouter({
history: createWebHistory(),
history: createWebHistory('/bank/'), // 设置基础路径
routes,
scrollBehavior(to, from, savedPosition) {
// 如果有保存的位置,则恢复到保存的位置
@@ -29,9 +29,19 @@ router.beforeEach(async (to, from, next) => {
// 获取用户存储
const userStore = useUserStore()
// 如果访问登录页面且已有有效token重定向到仪表盘
// 处理根路径的认证检查
if (to.path === '/') {
if (userStore.isLoggedIn) {
next('/project-list')
} else {
next('/login')
}
return
}
// 如果访问登录页面且已有有效token重定向到项目列表
if (to.path === '/login' && userStore.token && userStore.isLoggedIn) {
const redirectPath = to.query.redirect || '/dashboard'
const redirectPath = to.query.redirect || '/project-list'
next(redirectPath)
return
}
@@ -49,8 +59,8 @@ router.beforeEach(async (to, from, next) => {
if (to.meta.roles && to.meta.roles.length > 0) {
const userRole = userStore.getUserRoleName()
if (!to.meta.roles.includes(userRole)) {
// 用户角色不匹配,重定向到仪表盘
next('/dashboard')
// 用户角色不匹配,重定向到项目列表
next('/project-list')
} else {
// 用户已登录且角色匹配,允许访问
next()

View File

@@ -32,7 +32,11 @@ import {
const routes = [
{
path: '/',
redirect: '/project-list',
name: 'Root',
meta: {
hideInMenu: true
}
// 重定向逻辑已移至路由守卫中处理
},
{
path: '/login',

View File

@@ -101,7 +101,7 @@ export const api = {
* @returns {Promise} 登录结果
*/
async login(username, password) {
const response = await fetch(`${API_CONFIG.baseUrl}/api/auth/login`, {
const response = await fetch(`${API_CONFIG.baseUrl}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -119,7 +119,7 @@ export const api = {
* @returns {Promise} 响应数据
*/
async get(endpoint, options = {}) {
let url = `${API_CONFIG.baseUrl}/api${endpoint}`
let url = `${API_CONFIG.baseUrl}${endpoint}`
// 处理查询参数
if (options.params && Object.keys(options.params).length > 0) {
@@ -158,7 +158,7 @@ export const api = {
* @returns {Promise} 响应数据
*/
async post(endpoint, data, options = {}) {
const url = `${API_CONFIG.baseUrl}/api${endpoint}`
const url = `${API_CONFIG.baseUrl}${endpoint}`
const response = await fetch(url, {
method: 'POST',
headers: createHeaders(options.headers),
@@ -176,7 +176,7 @@ export const api = {
* @returns {Promise} 响应数据
*/
async put(endpoint, data, options = {}) {
const url = `${API_CONFIG.baseUrl}/api${endpoint}`
const url = `${API_CONFIG.baseUrl}${endpoint}`
const response = await fetch(url, {
method: 'PUT',
headers: createHeaders(options.headers),
@@ -193,7 +193,7 @@ export const api = {
* @returns {Promise} 响应数据
*/
async delete(endpoint, options = {}) {
const url = `${API_CONFIG.baseUrl}/api${endpoint}`
const url = `${API_CONFIG.baseUrl}${endpoint}`
const response = await fetch(url, {
method: 'DELETE',
headers: createHeaders(options.headers),

View File

@@ -109,8 +109,8 @@ const handleLogin = async () => {
if (result.success) {
message.success('登录成功')
// 重定向到目标页面或仪表盘
const redirectPath = route.query.redirect || '/dashboard'
// 重定向到目标页面或项目列表
const redirectPath = route.query.redirect || '/project-list'
router.push(redirectPath)
} else {
message.error(result.message || '登录失败')
@@ -125,7 +125,7 @@ const handleLogin = async () => {
// 页面加载时检查是否已登录
if (userStore.isLoggedIn) {
const redirectPath = route.query.redirect || '/dashboard'
const redirectPath = route.query.redirect || '/project-list'
router.push(redirectPath)
}
</script>