Browse Source

登录修改

dev_kxc
xzt 1 year ago
parent
commit
53c78d788b
  1. 8
      jwtech-pc-page/src/api/login.js
  2. 54
      jwtech-pc-page/src/http/http.js
  3. 10
      jwtech-pc-page/src/router/index.js

8
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',

54
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'
@ -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;
},

10
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'

Loading…
Cancel
Save