From d391726dd1c8e2460175fcd4d16a63e9decf15c6 Mon Sep 17 00:00:00 2001 From: JianMiau Date: Mon, 3 Aug 2026 11:30:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E4=B8=80=E8=88=AC=20Router?= =?UTF-8?q?=20=E4=B8=A6=E6=94=AF=E6=8F=B4=20LINE=20=E7=84=A1=E7=B6=81?= =?UTF-8?q?=E5=AE=9A=E8=87=AA=E5=8B=95=E5=BB=BA=E5=B8=B3=E8=99=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根本原因: 1. Hash router 網址帶 /#/ 不美觀且與一般網站行為不一致。 2. register.line_login 收到 status 12(LINE 帳號無綁定)時直接中止, 新 token 無法登入。 影響: 網址改為一般路徑(自動偵測部署子路徑,不需放網站根目錄);靜態主機在 /lobby 重新整理由殘根導回入口頁。無綁定帳號時自動 account.create 取得 [id, pw] 後直接 account.login,登入面板顯示建立進度。 修法: - index.tsx:createHashRouter 改 createBrowserRouter,getBasename() 依 location.pathname 推導子路徑並去除已知路由字尾 - build-templates/lobby/index.html:靜態主機 SPA 殘根,重整時導回 ../ - Login.tsx:status 12 時走 createAccountAndLogin()(account.create 回傳 格式為 [id, pw] 陣列) Co-Authored-By: Claude Fable 5 --- build-templates/lobby/index.html | 12 ++++++++++++ src/UI/Login.tsx | 22 +++++++++++++++++++--- src/index.tsx | 17 ++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 build-templates/lobby/index.html diff --git a/build-templates/lobby/index.html b/build-templates/lobby/index.html new file mode 100644 index 0000000..8e9fcaa --- /dev/null +++ b/build-templates/lobby/index.html @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/UI/Login.tsx b/src/UI/Login.tsx index 600b333..009e1c7 100644 --- a/src/UI/Login.tsx +++ b/src/UI/Login.tsx @@ -4,7 +4,7 @@ import { CoroutineV2 } from "@/Engine/CatanEngine/CoroutineV2/CoroutineV2"; import { INetResponse } from "@/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import { BusinessEnum } from "@/_BusinessTypeSetting/BusinessTypeSetting"; import { useGameItems } from "@/context/GameItemsContext"; -import { AccountLoginRequest } from "@/define/Request/AccountRequest"; +import { AccountCreateRequest, AccountLoginRequest } from "@/define/Request/AccountRequest"; import { CommonAccountResponse, LineLoginRequest } from "@/define/Request/RegisterRequest"; import WheelSelect from "@/components/WheelSelect"; import { EnvName, fetchGameUrl, fetchPlatformConfig, fetchPlatformList, PlatformEnvConfig, PlatformOption } from "@/modules/GoogleSheet/GoogleSheetService"; @@ -148,13 +148,29 @@ const Login = () => { setIsLogin(false); return; } - console.warn("LINE帳號無綁定"); - setIsLogin(false); + console.warn("LINE帳號無綁定,自動建立帳號"); + setLoginStep("無綁定帳號,建立新帳號中"); + yield* createAccountAndLogin(); return; } yield* serverAccountLogin(resp.Data.id, resp.Data.pw); } + /** LINE帳號無綁定(status 12)時:請Server建立訪客帳號後直接登入 */ + function* createAccountAndLogin(): IterableIterator { + const req: AccountCreateRequest = new AccountCreateRequest(); + yield req.SendAsync(true); + const resp: INetResponse = req.Result; + if (!resp.IsValid) { + CSMessage.CreateYesMsg("Account Create Error! Error Code : " + resp.Status); + setIsLogin(false); + return; + } + // 回傳格式為 [id, pw] + const [id, pw] = resp.Data as [number, string]; + yield* serverAccountLogin(String(id), pw); + } + /** 遊戲帳號登入取得玩家資料.統一登入時在刪除需要刪除的資料 */ function* serverAccountLogin(a: string, pw: string, partner: string = null): IterableIterator { let hasAP: boolean = (a && a != "null" && a != "undefined" && pw && pw != "null" && pw != "undefined"); diff --git a/src/index.tsx b/src/index.tsx index 2a04f90..bf5c874 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,7 +5,7 @@ import "dayjs/locale/zh-tw"; import React from "react"; import ReactDOM from "react-dom/client"; -import { createHashRouter, RouterProvider } from "react-router-dom"; +import { createBrowserRouter, RouterProvider } from "react-router-dom"; import { BaseEnumerator } from "./Engine/CatanEngine/CoroutineV2/Core/BaseEnumerator"; import { GameItemsProvider } from "@/context/GameItemsContext"; @@ -27,11 +27,22 @@ BaseEnumerator.Init(); // 設定 dayjs 語言 dayjs.locale("zh-tw"); +// 依目前網址推導部署子路徑(專案不一定放在網站根目錄,例如 /Line_Project_Bot/) +function getBasename(): string { + let path: string = location.pathname.replace(/index\.html$/, ""); + // 去除已知路由字尾,避免在 /lobby 重新整理時把路由誤當成資料夾 + path = path.replace(/lobby\/?$/, ""); + if (!path.endsWith("/")) { + path += "/"; + } + return path; +} + // 路由設定 -const router = createHashRouter([ +const router = createBrowserRouter([ { path: "/", element: }, { path: "/lobby", element: }, -]); +], { basename: getBasename() }); // Render // 注意:不能用 React.StrictMode — 開發模式雙重掛載會讓 NetManagerSD 等靜態單例的連線互相覆蓋