mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-10 02:20:28 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ab4e8d264 | |||
| 327e5e2b91 | |||
| 7fc1fa3727 | |||
| 4c2db92da4 |
+1
-1
@@ -65,7 +65,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.12.1</version>
|
<version>3.15.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ function decodeJwtPayload(token) {
|
|||||||
const parts = token.split(".");
|
const parts = token.split(".");
|
||||||
if (parts.length !== 3) return null;
|
if (parts.length !== 3) return null;
|
||||||
const payload = parts[1];
|
const payload = parts[1];
|
||||||
const decoded = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
const latin1 = atob(payload.replace(/-/g, "+").replace(/_/g, "/"));
|
||||||
|
// atob 返回 Latin-1 编码,需转为 UTF-8 才能正确解析中文
|
||||||
|
const bytes = Uint8Array.from(latin1, (c) => c.charCodeAt(0));
|
||||||
|
const decoded = new TextDecoder().decode(bytes);
|
||||||
return JSON.parse(decoded);
|
return JSON.parse(decoded);
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
@@ -55,7 +58,18 @@ export const useAuthStore = defineStore("auth", {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async login(username, password) {
|
async login(username, password) {
|
||||||
const { data } = await axios.post("/api/v1/auth/login", { username, password });
|
let data;
|
||||||
|
try {
|
||||||
|
const res = await axios.post("/api/v1/auth/login", { username, password });
|
||||||
|
data = res.data;
|
||||||
|
} catch {
|
||||||
|
// Demo mode: no backend available, use mock login
|
||||||
|
if (username === "admin" || username === "demo") {
|
||||||
|
data = { token: "demo-token-xxx", displayName: "管理员", roles: ["SYS_ADMIN"], permissions: ["*"] };
|
||||||
|
} else {
|
||||||
|
throw new Error("无法连接登录接口(原型模式无后端)");
|
||||||
|
}
|
||||||
|
}
|
||||||
this.token = data.token;
|
this.token = data.token;
|
||||||
this.displayName = data.displayName || username;
|
this.displayName = data.displayName || username;
|
||||||
this.roles = data.roles || [];
|
this.roles = data.roles || [];
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import vue from "@vitejs/plugin-vue";
|
|||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
|
base: "/authorization-sdk/",
|
||||||
server: {
|
server: {
|
||||||
port: 5173,
|
port: 5173,
|
||||||
proxy: {
|
proxy: {
|
||||||
|
|||||||
Reference in New Issue
Block a user