diff --git a/index.html b/index.html index c450a44..fc77ae2 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ 双碳金融系统 -
+
diff --git a/package-lock.json b/package-lock.json index 411b7d9..018e2cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^6.0.1", - "prettier": "^3.6.2", "vite": "^7.1.7" } }, @@ -1166,6 +1165,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -1201,22 +1201,6 @@ "node": "^10 || ^12 || >=14" } }, - "node_modules/prettier": { - "version": "3.6.2", - "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.6.2.tgz", - "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==", - "dev": true, - "license": "MIT", - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, "node_modules/rollup": { "version": "4.52.5", "resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.52.5.tgz", @@ -1351,6 +1335,7 @@ "integrity": "sha512-ZWyE8YXEXqJrrSLvYgrRP7p62OziLW7xI5HYGWFzOvupfAlrLvURSzv/FyGyy0eidogEM3ujU+kUG1zuHgb6Ug==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -1425,6 +1410,7 @@ "resolved": "https://registry.npmmirror.com/vue/-/vue-3.5.22.tgz", "integrity": "sha512-toaZjQ3a/G/mYaLSbV+QsQhIdMo9x5rrqIpYRObsJ6T/J+RyCSFwN2LHNVH9v8uIcljDNa3QzPVdv3Y6b9hAJQ==", "license": "MIT", + "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.22", "@vue/compiler-sfc": "3.5.22", diff --git a/src/components/layout/index.vue b/src/components/layout/index.vue index 8c82f4e..7fb5c18 100644 --- a/src/components/layout/index.vue +++ b/src/components/layout/index.vue @@ -1,39 +1,48 @@ \ No newline at end of file diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 3aaae3d..89fd328 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -13,7 +13,7 @@ - + @@ -30,6 +30,7 @@ diff --git a/src/router/index.js b/src/router/index.js index 49aaed8..07572a2 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,4 +1,5 @@ import { createRouter, createWebHistory} from 'vue-router'; +import { authToken } from '@/store/index.js' const routes = [ { path: "/", redirect: "/login" }, { @@ -14,6 +15,7 @@ const routes = [ { path: "", name: "工作台", + meta: { icon: "file"}, children: [ // { // path: "home", @@ -52,4 +54,20 @@ const router = createRouter({ routes, }); +router.beforeEach((to, from, next) => { + if (to.path === "/login") { + if (authToken.access) { + next("/home"); + } else { + next(); + } + } else { + if (authToken.access) { + next(); + } else { + next("/login"); + } + } +}) + export default router; diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..0a5b0a4 --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,17 @@ +import { reactive, watch } from "vue"; + +export const userInfo = reactive(JSON.parse(localStorage.getItem("userInfo")) || { + name: "张三", + username: "zhangsan" +}); +watch(userInfo, (newVal) => { + localStorage.setItem("userInfo", JSON.stringify(newVal)); +}, { deep: true, immediate: true}) + +export const authToken = reactive(JSON.parse(localStorage.getItem("authToken")) ||{ + access: null, + refresh: null +}) +watch(authToken, (newVal) => { + localStorage.setItem("authToken", JSON.stringify(newVal)); +}, { deep: true, immediate: true}) \ No newline at end of file