From 53c78d788bac80cc5fa370ef42accba768eab80b Mon Sep 17 00:00:00 2001 From: xzt <1113240624@qq.com> Date: Mon, 5 Feb 2024 18:27:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jwtech-pc-page/src/api/login.js | 8 +++++ jwtech-pc-page/src/http/http.js | 56 ++++++++++++++++-------------- jwtech-pc-page/src/router/index.js | 10 ++++++ 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/jwtech-pc-page/src/api/login.js b/jwtech-pc-page/src/api/login.js index 69cf71dd..73cc9f3a 100644 --- a/jwtech-pc-page/src/api/login.js +++ b/jwtech-pc-page/src/api/login.js @@ -1,6 +1,14 @@ import request from '@/http/http' //登录 +export function loginPc(data) { + return request({ + url: '/login', + method: 'post', + data: data + }) +} + export function login(data) { return request({ url: '/login/pc', diff --git a/jwtech-pc-page/src/http/http.js b/jwtech-pc-page/src/http/http.js index dffaf775..0b38b69a 100644 --- a/jwtech-pc-page/src/http/http.js +++ b/jwtech-pc-page/src/http/http.js @@ -5,6 +5,7 @@ import router from "../router" import store from "../store" import { Notification } from "element-ui"; import qs from "qs" +import { loginPc } from "@/api/login"; axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' @@ -31,7 +32,7 @@ const codeMessage = { axios.interceptors.request.use( - config => { + config => { const requestConfig = config; if (!requestConfig.data) { requestConfig.data = {}; @@ -46,8 +47,9 @@ axios.interceptors.request.use( if (store.state.token) { // requestConfig.headers["token"] = `${store.state.token}`; requestConfig.headers['jianwei'] = 'jwtech ' + `${store.state.token}` ; - }else { - requestConfig.headers['jianwei'] = 'jwtech cf351e12-5418-456d-8934-d878d4f0147c' ; + } else { + // requestConfig.headers['jianwei'] = 'jwtech ' + `${store.state.token}` ; + // requestConfig.headers['jianwei'] = 'jwtech cf351e12-5418-456d-8934-d878d4f0147c'; } if (config.noSuffix) { config.baseURL = window.g.noSuffixUrl @@ -74,30 +76,30 @@ axios.interceptors.response.use( // duration: 2000 // }); } - if (response.data.code === 405 || response.data.code === 403) { - Notification.closeAll() - Notification.warning({ - title: "系统提示", - dangerouslyUseHTMLString: true, - message: "检测用户未登录,即将跳转到登录页面", - duration: 3000 - }); - setTimeout(() => { - router.replace({ - path: 'login', - query: { redirect: router.currentRoute.fullPath } - }) - }, 2000) - } else if (response.data.code === 500) { - Notification.closeAll() - Notification.warning({ - title: "系统提示", - dangerouslyUseHTMLString: true, - message: response.data.msg, - duration: 3000 - }); - return Promise.reject(new Error(response.data.msg)) - } + // if (response.data.code === 405 || response.data.code === 403) { + // Notification.closeAll() + // Notification.warning({ + // title: "系统提示", + // dangerouslyUseHTMLString: true, + // message: "检测用户未登录,即将跳转到登录页面", + // duration: 3000 + // }); + // setTimeout(() => { + // router.replace({ + // path: 'login', + // query: { redirect: router.currentRoute.fullPath } + // }) + // }, 2000) + // } else if (response.data.code === 500) { + // Notification.closeAll() + // Notification.warning({ + // title: "系统提示", + // dangerouslyUseHTMLString: true, + // message: response.data.msg, + // duration: 3000 + // }); + // return Promise.reject(new Error(response.data.msg)) + // } return response; }, diff --git a/jwtech-pc-page/src/router/index.js b/jwtech-pc-page/src/router/index.js index cf3351e4..e0966fdb 100644 --- a/jwtech-pc-page/src/router/index.js +++ b/jwtech-pc-page/src/router/index.js @@ -1,6 +1,7 @@ import Vue from 'vue' import Router from 'vue-router' import store from '../store' +import axios from "axios"; Vue.use(Router) // const routerPush = Router.prototype.push; @@ -353,6 +354,15 @@ const router = new Router({ ] }) router.beforeEach((to, from, next) => { + if (!store.state.token) { + axios.post('/login', { + username: "admin", + password: "Sgcjs@2023" + }).then(res => { + store.commit("setToken", res.data.token) + }) + } + if (to.path === '/') { router.push({ // name: 'login'