mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-10 18:40:29 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a6c531ac8 | |||
| 327e5e2b91 | |||
| 7fc1fa3727 | |||
| 4c2db92da4 |
+16
-6
@@ -16,7 +16,7 @@
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vitejs/plugin-vue": "^6.0.7",
|
||||
"vite": "^6.0.7"
|
||||
}
|
||||
},
|
||||
@@ -568,6 +568,13 @@
|
||||
"url": "https://opencollective.com/popperjs"
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/pluginutils": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.1.tgz",
|
||||
"integrity": "sha512-2j9bGt5Jh8hj+vPtgzPtl72j0yRxHAyumoo6TNfAjsLB04UtpSvPbPcDcBMxz7n+9CYB0c1GxQFxYRg2jimqGw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@rollup/rollup-android-arm-eabi": {
|
||||
"version": "4.60.1",
|
||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.60.1.tgz",
|
||||
@@ -947,16 +954,19 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@vitejs/plugin-vue": {
|
||||
"version": "5.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.4.tgz",
|
||||
"integrity": "sha512-7Yx/SXSOcQq5HiiV3orevHUFn+pmMB4cgbEkDYgnkUWb0WfeQ/wa2yFv6D5ICiCQOVpjA7vYDXrC7AGO8yjDHA==",
|
||||
"version": "6.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-6.0.7.tgz",
|
||||
"integrity": "sha512-km+p+XdSz9Sxm5rqUbqcSfZYaAniKxWBj1KURl+Jr7UaPvvX7BmaWMdP69I5rrFDeQGyxAG7NXdc57vz+snhWg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@rolldown/pluginutils": "^1.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
"node": "^20.19.0 || >=22.12.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^5.0.0 || ^6.0.0",
|
||||
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
|
||||
"vue": "^3.2.25"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"@vitejs/plugin-vue": "^6.0.7",
|
||||
"vite": "^6.0.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ function decodeJwtPayload(token) {
|
||||
const parts = token.split(".");
|
||||
if (parts.length !== 3) return null;
|
||||
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);
|
||||
} catch {
|
||||
return null;
|
||||
@@ -55,7 +58,18 @@ export const useAuthStore = defineStore("auth", {
|
||||
},
|
||||
actions: {
|
||||
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.displayName = data.displayName || username;
|
||||
this.roles = data.roles || [];
|
||||
|
||||
@@ -3,6 +3,7 @@ import vue from "@vitejs/plugin-vue";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
base: "/authorization-sdk/",
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
|
||||
Reference in New Issue
Block a user