From b81ad87f957de34cca37c6048b127083c1a37c4b Mon Sep 17 00:00:00 2001 From: jiangzhe <244140623@qq.com> Date: Thu, 11 Apr 2024 17:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E6=A0=A1=E7=AB=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - pnpm-lock.yaml | 20 --- src/apis/user.js | 29 ++-- src/main.js | 2 - src/router/index.js | 21 ++- src/stores/userStore.js | 31 ---- src/styles/element/index.scss | 2 +- src/styles/var.scss | 2 +- src/utils/http.js | 11 +- src/views/Exam/index.vue | 75 +++++---- src/views/Login/index.vue | 306 +++++++++++----------------------- vite.config.js | 9 + 12 files changed, 193 insertions(+), 316 deletions(-) delete mode 100644 src/stores/userStore.js diff --git a/package.json b/package.json index 8b5e94f..73cb395 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "axios": "^1.6.3", "dayjs": "^1.11.10", "element-plus": "^2.6.2", - "pinia": "^2.1.7", "vue": "^3.3.11", "vue-router": "^4.2.5" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d0c7ad8..04c4789 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,6 @@ dependencies: element-plus: specifier: ^2.6.2 version: 2.6.2(vue@3.4.15) - pinia: - specifier: ^2.1.7 - version: 2.1.7(vue@3.4.15) vue: specifier: ^3.3.11 version: 3.4.15 @@ -1756,23 +1753,6 @@ packages: engines: {node: '>=8.6'} dev: true - /pinia@2.1.7(vue@3.4.15): - resolution: {integrity: sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==} - peerDependencies: - '@vue/composition-api': ^1.4.0 - typescript: '>=4.4.4' - vue: ^2.6.14 || ^3.3.0 - peerDependenciesMeta: - '@vue/composition-api': - optional: true - typescript: - optional: true - dependencies: - '@vue/devtools-api': 6.5.1 - vue: 3.4.15 - vue-demi: 0.14.6(vue@3.4.15) - dev: false - /pkg-types@1.0.3: resolution: {integrity: sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==} dependencies: diff --git a/src/apis/user.js b/src/apis/user.js index 89cf512..ead93e1 100644 --- a/src/apis/user.js +++ b/src/apis/user.js @@ -1,23 +1,26 @@ // 封装所有和用户相关的接口函数 import request from '@/utils/http' -export const loginAPI = ({ account, password }) => { +export const getAuthCodeAPI = () => { return request({ - url: '/login', - method: 'POST', - data: { - account, - password - } + url: '/auth/code' }) } - -export const getLikeListAPI = ({ limit = 4 }) => { +export const loginAPI = (loginBody) => { return request({ - url: '/goods/relevant', - params: { - limit - } + url: '/auth/passwordLogin', + method: 'POST', + headers: { + isToken: false, + isEncrypt: false + }, + data: loginBody + }) +} + +export const getPublishAPI = () => { + return request({ + url: '/web/scale/publish' }) } \ No newline at end of file diff --git a/src/main.js b/src/main.js index c70e0ee..52715d9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,4 @@ import { createApp } from 'vue' -import { createPinia } from 'pinia' import * as Elicons from '@element-plus/icons-vue' //引入Elmessage和Elloading的css样式文件 import 'element-plus/theme-chalk/el-loading.css' @@ -15,7 +14,6 @@ import { lazyPlugin } from '@/directives' const app = createApp(App) -app.use(createPinia()) app.use(router) app.use(lazyPlugin) diff --git a/src/router/index.js b/src/router/index.js index 20e3855..295d05d 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router' import Login from '@/views/Login/index.vue' import Exam from '@/views/Exam/index.vue' +import ScaleList from '@/views/ScaleList/index.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -12,8 +13,12 @@ const router = createRouter({ }, { path: '/', + component: ScaleList + }, + { + path: '/exam/:scaleId', component: Exam - } + } ], // 路由滚动行为定制 scrollBehavior() { @@ -23,4 +28,18 @@ const router = createRouter({ } }) +router.beforeEach((to, from, next) => { + const token = localStorage.getItem('token') + if (to.path === '/login') { + next() + } else { + if (token) { + next() + } else { + next('/login') + } + } +} +) + export default router diff --git a/src/stores/userStore.js b/src/stores/userStore.js deleted file mode 100644 index b48e035..0000000 --- a/src/stores/userStore.js +++ /dev/null @@ -1,31 +0,0 @@ -// 管理用户数据相关 - -import { defineStore } from 'pinia' -import { ref } from 'vue' -import { loginAPI } from '@/apis/user' -export const useUserStore = defineStore( - 'user', - () => { - // 1. 定义管理用户数据的state - const userInfo = ref({}) - // 2. 定义获取接口数据的action函数 - const getUserInfo = async ({ account, password }) => { - const res = await loginAPI({ account, password }) - userInfo.value = res.result - } - - // 退出时清除用户信息 - const clearUserInfo = () => { - userInfo.value = {} - } - // 3. 以对象的格式把state和action return - return { - userInfo, - getUserInfo, - clearUserInfo - } - }, - { - persist: true - } -) diff --git a/src/styles/element/index.scss b/src/styles/element/index.scss index fe904ff..4de3db2 100644 --- a/src/styles/element/index.scss +++ b/src/styles/element/index.scss @@ -1,6 +1,6 @@ /* 只需要重写你需要的即可 */ @forward 'element-plus/theme-chalk/src/common/var.scss' with ($colors: ('primary': ( // 主色 - 'base': #129AFE, + 'base': #1CC19A, ), 'success': ( // 成功色 'base': #1dc779, diff --git a/src/styles/var.scss b/src/styles/var.scss index 95a2e33..150afee 100644 --- a/src/styles/var.scss +++ b/src/styles/var.scss @@ -1,4 +1,4 @@ -$xtxColor: #129AFE; +$xtxColor: #1CC19A; $helpColor: #e26237; $sucColor: #1dc779; $warnColor: #ffb302; diff --git a/src/utils/http.js b/src/utils/http.js index ed874fd..b65be3e 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -1,12 +1,19 @@ import axios from 'axios' const http = axios.create({ - baseURL: 'http://pcapi-xiaotuxian-front-devtest.itheima.net', - timeout: 5000 + baseURL: '/api', + timeout: 50000 }) // axios请求拦截器 http.interceptors.request.use(config => { + const isToken = config.headers.isToken === false + if(!isToken && localStorage.getItem('token')){ + config.headers.Authorization = `Bearer ${localStorage.getItem('token')}` + } + + config.headers.clientId = 'e5cd7e4891bf95d1d19206ce24a7b32e' + return config }, e => Promise.reject(e)) diff --git a/src/views/Exam/index.vue b/src/views/Exam/index.vue index efb97ea..4472c34 100644 --- a/src/views/Exam/index.vue +++ b/src/views/Exam/index.vue @@ -1,33 +1,18 @@