From 47dacda7cef2cf1cc2c88b052605b99d01ef6fc1 Mon Sep 17 00:00:00 2001 From: "Lau-Laptop\\Lau" Date: Tue, 19 Dec 2023 10:36:56 +0800 Subject: [PATCH] fixed config and template --- .env.development | 2 +- .env.production | 2 +- .eslintrc.cjs | 5 +++-- package.json | 16 ++++++++-------- src/router/index.js | 10 +++++++++- src/utils/http.js | 9 ++++++++- src/utils/ls.js | 23 +++++++++++++++++++++++ 7 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 src/utils/ls.js diff --git a/.env.development b/.env.development index 95ba12e..e86ec6e 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ NODE_ENV = development -VITE_APP_TITLE = 标题 +VITE_APP_TITLE = DEV标题 VITE_BASE_URL = / VITE_API_BASE_URL = /api \ No newline at end of file diff --git a/.env.production b/.env.production index bd648c8..ee24404 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,4 @@ NODE_ENV = production -VITE_APP_TITLE = 标题 +VITE_APP_TITLE = PROD标题 VITE_BASE_URL = ./ VITE_API_BASE_URL = /api \ No newline at end of file diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b64731a..56c9394 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,12 +3,13 @@ require('@rushstack/eslint-patch/modern-module-resolution') module.exports = { root: true, - 'extends': [ + extends: [ 'plugin:vue/vue3-essential', 'eslint:recommended', '@vue/eslint-config-prettier/skip-formatting' ], parserOptions: { ecmaVersion: 'latest' - } + }, + rules: {} } diff --git a/package.json b/package.json index 534ef53..4e18696 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,14 @@ "format": "prettier --write src/" }, "dependencies": { - "axios": "^1.6.2", - "element-plus": "^2.4.4", - "mitt": "^3.0.1", - "pinia": "^2.1.7", - "pinia-plugin-persistedstate": "^3.2.1", - "qs": "^6.11.2", - "vue": "^3.3.11", - "vue-router": "^4.2.5" + "axios": "~1.6.2", + "element-plus": "~2.4.4", + "mitt": "~3.0.1", + "pinia": "~2.1.7", + "pinia-plugin-persistedstate": "~3.2.1", + "qs": "~6.11.2", + "vue": "~3.3.11", + "vue-router": "~4.2.5" }, "devDependencies": { "@rushstack/eslint-patch": "^1.3.3", diff --git a/src/router/index.js b/src/router/index.js index 8cfc404..c570226 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,7 +3,15 @@ import routes from './routes' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - routes + routes, + scrollBehavior: () => ({ left: 0, top: 0, behavior: 'smooth' }) +}) + +// 路由守卫 +router.beforeEach(() => {}) + +router.afterEach((to) => { + document.title = import.meta.env.VITE_APP_TITLE + ` | ${to.meta.title || ''}` }) export default router diff --git a/src/utils/http.js b/src/utils/http.js index 79629a1..67838e8 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -1,6 +1,6 @@ import axios from 'axios' import router from '@/router' -import { ElMessage } from 'element-plus' +import { ElMessage, ElNotification } from 'element-plus' const API_URL = import.meta.env.VITE_API_BASE_URL @@ -41,6 +41,13 @@ http.interceptors.response.use( }) router.push({ path: '/login' }) } + } else { + ElNotification({ + title: '错误', + message: res.data.message, + type: 'error', + duration: 2000 + }) } return res.data diff --git a/src/utils/ls.js b/src/utils/ls.js new file mode 100644 index 0000000..b8fb8cf --- /dev/null +++ b/src/utils/ls.js @@ -0,0 +1,23 @@ +const getItem = (itemName) => { + return window.localStorage.getItem(itemName) +} + +const setItem = (itemName, itemValue) => { + return window.localStorage.setItem(itemName, itemValue) +} + +const removeItem = (itemName) => { + return window.localStorage.removeItem(itemName) +} + +const clear = () => { + return window.localStorage.clear() +} + +export const getToken = () => getItem('token') + +export const setToken = (token) => setItem('token', token) + +export const clearToken = () => removeItem('token') + +export const clearAll = () => clear()