fix: 提供可访问的后台登录入口
This commit is contained in:
1 parent
e0fb508c0a
commit
e23d0baba7
2 files changed
+17
-1
No files matched your search
@@ -1 +1 @@
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>品牌后台</title></head><body><main id="app"></main><script type="module" src="./dist/main.js"></script></body></html>
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>品牌后台</title></head><body><main id="app"></main><script type="module" src="./dist/entry.js"></script></body></html>
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ApiClient } from "@personal-brand/api-client";
|
||||
import { bootstrapAdmin } from "./main.js";
|
||||
|
||||
const root = document.querySelector<HTMLElement>("#app");
|
||||
if (root) {
|
||||
const token = localStorage.getItem("adminToken");
|
||||
if (!token) {
|
||||
root.innerHTML = `<h1>品牌后台</h1><form id="login"><input id="username" value="admin" placeholder="账号"><input id="password" type="password" placeholder="密码"><button>登录</button></form>`;
|
||||
root.querySelector("#login")?.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const username = (root.querySelector("#username") as HTMLInputElement).value;
|
||||
const password = (root.querySelector("#password") as HTMLInputElement).value;
|
||||
try { const client = new ApiClient({ baseUrl: "http://localhost:3001", fetcher: (input, init) => fetch(input, init) }); const result = await client.loginAdmin(username, password); localStorage.setItem("adminToken", result.token); location.reload(); } catch (error) { alert(error instanceof Error ? error.message : "登录失败"); }
|
||||
});
|
||||
} else bootstrapAdmin(root);
|
||||
}
|
||||
Reference in new issue
Block a user