yinxia.yang 23 시간 전
부모
커밋
7ba5c5aeef
6개의 변경된 파일33개의 추가작업 그리고 72개의 파일을 삭제
  1. 0 9
      .dockerignore
  2. 0 14
      Dockerfile
  3. 0 32
      nginx.conf
  4. 28 12
      public/forward.html
  5. 3 3
      src/router/index.ts
  6. 2 2
      src/utils/auth.ts

+ 0 - 9
.dockerignore

@@ -1,9 +0,0 @@
-node_modules
-dist
-.git
-.gitignore
-*.md
-.DS_Store
-npm-debug.log*
-.vscode
-.idea

+ 0 - 14
Dockerfile

@@ -1,14 +0,0 @@
-# 构建阶段
-FROM node:20-alpine AS builder
-WORKDIR /app
-COPY package*.json ./
-RUN npm ci
-COPY . .
-RUN npm run build
-
-# 运行阶段
-FROM nginx:alpine
-COPY --from=builder /app/dist /usr/share/nginx/html
-COPY nginx.conf /etc/nginx/conf.d/default.conf
-EXPOSE 80
-CMD ["nginx", "-g", "daemon off;"]

+ 0 - 32
nginx.conf

@@ -1,32 +0,0 @@
-server {
-    listen 80;
-    server_name _;
-    root /usr/share/nginx/html;
-    index index.html;
-
-    # Vue Router history 模式:所有路径回退到 index.html
-    location / {
-        try_files $uri $uri/ /index.html;
-    }
-
-    # 静态资源长缓存
-    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|ttf|eot)$ {
-        expires 30d;
-        add_header Cache-Control "public, immutable";
-    }
-
-    # gzip 压缩
-    gzip on;
-    gzip_vary on;
-    gzip_min_length 1024;
-    gzip_types
-        text/plain
-        text/css
-        text/xml
-        text/javascript
-        application/javascript
-        application/json
-        application/xml
-        application/xml+rss
-        image/svg+xml;
-}

+ 28 - 12
public/forward.html

@@ -1,23 +1,39 @@
 <!DOCTYPE html>
-<html lang="en">
-
+<html lang="zh-CN">
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Document</title>
+    <title>登录中...</title>
 </head>
-
 <body>
-    <div>......</div>
+    <div style="display:flex;align-items:center;justify-content:center;height:100vh;font-family:sans-serif;color:#666">
+        正在跳转登录页...
+    </div>
     <script>
-        // 获取所有url参数,并拼接参数转发到http://www.baidu.com
-        var url = window.location.href;
-        var params = url.split('?')[1];
-        var newUrl = `${window.location.origin}/#/login?` + params;
-        // 跳转页面
-        window.location.replace(newUrl);
+        // OAuth 回调中转页:将 URL 参数暂存到 sessionStorage,然后跳转到 SPA 根路径
+        // 用于解决 history 路由模式下 nginx 无 SPA fallback 导致的 404 问题
+        (function () {
+            var search = window.location.search || '';
+            var hash = window.location.hash || '';
+            // 合并 query 和 hash 中的参数(兼容 form_post 可能的传递方式)
+            var queryString = search.replace(/^\?/, '');
+            if (hash && hash.indexOf('?') !== -1) {
+                var hashQuery = hash.split('?')[1] || '';
+                if (hashQuery) {
+                    queryString = queryString ? (queryString + '&' + hashQuery) : hashQuery;
+                }
+            }
+            if (queryString) {
+                try {
+                    sessionStorage.setItem('oauth_callback_params', queryString);
+                } catch (e) {
+                    // sessionStorage 不可用时忽略,后续登录页会走正常流程
+                }
+            }
+            // 跳转到 SPA 根路径,确保能加载到 index.html
+            window.location.replace(window.location.origin + '/');
+        })();
     </script>
 </body>
-
 </html>

+ 3 - 3
src/router/index.ts

@@ -1,4 +1,4 @@
-import { createRouter, createWebHistory } from 'vue-router'
+import { createRouter, createWebHashHistory } from 'vue-router'
 import { getToken } from '../utils/auth'
 import Login from '../views/Login/index.vue'
 import Dashboard from '../views/Dashboard.vue'
@@ -8,9 +8,9 @@ import Inbound from '../views/Inbound.vue'
 import Outbound from '../views/Outbound.vue'
 import Ledger from '../views/Ledger.vue'
 
-export const router = createRouter({ history: createWebHistory(), routes: [
-  { path: '/login', component: Login },
+export const router = createRouter({ history: createWebHashHistory(), routes: [
   { path: '/', redirect: '/dashboard' }, 
+  { path: '/login', component: Login },
   { path: '/dashboard', component: Dashboard, meta: { title: '工作台' } },
   { path: '/master', component: Master, meta: { title: '基础资料管理' } },
   { path: '/sku', component: Sku, meta: { title: '商品 / SKU 管理' } },

+ 2 - 2
src/utils/auth.ts

@@ -49,9 +49,9 @@ export function clearAuthInfo() {
 	useStore().CLEAR_AUTH_INFO()
 }
 
-/** 优先使用配置的回调地址,否则回到站点 /login;部署时需配置 SPA 路径回退。 */
+/** 优先使用配置的回调地址,否则使用 forward.html 中转页,避免 history 路由 404。 */
 export function getOAuthRedirectUri() {
-	return String(import.meta.env.VITE_OAUTH_REDIRECT_URI || '').trim() || `${location.origin}/login`
+	return String(import.meta.env.VITE_OAUTH_REDIRECT_URI || '').trim() || `${location.origin}/forward.html`
 }
 
 /** 读取有效的 PKCE 缓存:verifier 长度为 43~128 位,不设置本地过期时间。 */