提交 c0fd1eb4 authored 作者: 刘旭's avatar 刘旭

优化

上级 0aa8f812
...@@ -43,18 +43,20 @@ router.beforeEach(async (to, from, next) => { ...@@ -43,18 +43,20 @@ router.beforeEach(async (to, from, next) => {
let token = getToken(); let token = getToken();
if (token) { if (token) {
if (to.path === '/login' || to.path === '/') { if (to.path === '/login' || to.path === '/') {
// console.log('/import/lic', to.path);
next({ path: '/' }) next({ path: '/' })
} else { } else {
// if (to.path === '/import/lic') return window.location.href = '/#/import/lic'
if (store.state.menu.menuList.length == 1) { if (store.state.menu.menuList.length == 1) {
try { try {
await store.dispatch('user/getInfo') await store.dispatch('user/getInfo')
await store.dispatch('menu/getMenuList', router) await store.dispatch('menu/getMenuList', router)
next({ ...to, replace: true }) next({ ...to, replace: true })
} catch (error) { } catch (error) {
// if (to.path === '/import/lic') return next({ path: '/import/lic' })
cleanSession(); cleanSession();
next({ path: '/login' }) next({ path: '/login' })
} }
} else { } else {
next() next()
} }
......
...@@ -40,7 +40,7 @@ const routes: Array<RouteRecordRaw> = [ ...@@ -40,7 +40,7 @@ const routes: Array<RouteRecordRaw> = [
{ {
path: "/import/lic", path: "/import/lic",
name: "importLic", name: "importLic",
component: () => import("@/views/importLic/index.vue"), component: () => import("@/views/login/importLic.vue"),
}, },
{ {
path: "/404", path: "/404",
......
import router from '@/router'
import axios, { AxiosInstance } from 'axios' import axios, { AxiosInstance } from 'axios'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
...@@ -32,6 +33,7 @@ service.interceptors.response.use( ...@@ -32,6 +33,7 @@ service.interceptors.response.use(
error => { error => {
// 数据请求失败后的相应操作 // 数据请求失败后的相应操作
const response = error.response; const response = error.response;
// 根据返回的code值来做不同的处理(和后端约定) // 根据返回的code值来做不同的处理(和后端约定)
switch (response.status) { switch (response.status) {
case 401: case 401:
...@@ -40,7 +42,7 @@ service.interceptors.response.use( ...@@ -40,7 +42,7 @@ service.interceptors.response.use(
sessionStorage.clear() sessionStorage.clear()
return ElMessage.error('请重新登录') return ElMessage.error('请重新登录')
} else if (response.data.code === 913) { } else if (response.data.code === 913) {
window.location.href = '/#/import/lic' router.push({ path: '/import/lic' })
return ElMessage.error('请重新导入lic文件') return ElMessage.error('请重新导入lic文件')
} }
ElMessage.error('错误请求') ElMessage.error('错误请求')
......
...@@ -4,7 +4,7 @@ import { AxiosRequest, ResponseType, CustomResponse } from './types'; ...@@ -4,7 +4,7 @@ import { AxiosRequest, ResponseType, CustomResponse } from './types';
import { LoginParm } from './types/user/userModel'; import { LoginParm } from './types/user/userModel';
// import storage from '@/utils/storage'; // import storage from '@/utils/storage';
import { ElLoading, ElMessage } from 'element-plus' import { ElLoading, ElMessage } from 'element-plus'
import {store} from '@/store' import { store } from '@/store'
// import { ILoadingInstance } from 'element-plus/lib/components/loading' // import { ILoadingInstance } from 'element-plus/lib/components/loading'
import qs from 'qs'; import qs from 'qs';
import axios, { AxiosRequestHeaders, AxiosInstance, AxiosResponse, AxiosRequestConfig, Method } from 'axios'; import axios, { AxiosRequestHeaders, AxiosInstance, AxiosResponse, AxiosRequestConfig, Method } from 'axios';
...@@ -19,8 +19,8 @@ interface PendingType { ...@@ -19,8 +19,8 @@ interface PendingType {
cancel: Function; cancel: Function;
} }
interface listParms { interface listParms {
pageNo:number; pageNo: number;
pageSize:number; pageSize: number;
} }
//加载效果 //加载效果
// let loading: ILoadingInstance; // let loading: ILoadingInstance;
...@@ -87,7 +87,7 @@ class BaseHttp { ...@@ -87,7 +87,7 @@ class BaseHttp {
(response: AxiosResponse) => { (response: AxiosResponse) => {
// loading.close();//关闭loading动画 // loading.close();//关闭loading动画
removePending(response.config); removePending(response.config);
switch(response.data.code){ switch (response.data.code) {
case 401: case 401:
ElMessage.error(response.data.msg) ElMessage.error(response.data.msg)
break; break;
...@@ -109,6 +109,10 @@ class BaseHttp { ...@@ -109,6 +109,10 @@ class BaseHttp {
// 根据返回的code值来做不同的处理(和后端约定) // 根据返回的code值来做不同的处理(和后端约定)
switch (response.status) { switch (response.status) {
case 401: case 401:
if (response.data.code === 913) {
router.push({ path: '/import/lic' })
return ElMessage.error('请重新导入lic文件')
}
ElMessage.error('错误请求') ElMessage.error('错误请求')
break; break;
case 403: case 403:
...@@ -168,7 +172,7 @@ class BaseHttp { ...@@ -168,7 +172,7 @@ class BaseHttp {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sericeAPI.get<T>(url, { this.sericeAPI.get<T>(url, {
params: parms, params: parms,
headers:{ headers: {
}, },
paramsSerializer: (parms) => { paramsSerializer: (parms) => {
return qs.stringify(parms) return qs.stringify(parms)
...@@ -201,7 +205,7 @@ class BaseHttp { ...@@ -201,7 +205,7 @@ class BaseHttp {
delete<T = any>(url: string, parms: any): Promise<CustomResponse<T>> { delete<T = any>(url: string, parms: any): Promise<CustomResponse<T>> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sericeAPI.delete(url, { this.sericeAPI.delete(url, {
params:parms params: parms
}).then((res) => { }).then((res) => {
resolve(res.data as any) resolve(res.data as any)
}).catch((error) => { }).catch((error) => {
...@@ -212,7 +216,7 @@ class BaseHttp { ...@@ -212,7 +216,7 @@ class BaseHttp {
put<T = any>(url: string, parm: any): Promise<CustomResponse<T>> { put<T = any>(url: string, parm: any): Promise<CustomResponse<T>> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sericeAPI.put(url,parm).then((res) => { this.sericeAPI.put(url, parm).then((res) => {
resolve(res.data as any) resolve(res.data as any)
}).catch((error) => { }).catch((error) => {
reject(error) reject(error)
...@@ -250,7 +254,7 @@ class BaseHttp { ...@@ -250,7 +254,7 @@ class BaseHttp {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sericeAPI.get<T>(url, { this.sericeAPI.get<T>(url, {
params: parms, params: parms,
headers:{ headers: {
}, },
paramsSerializer: (parms) => { paramsSerializer: (parms) => {
return qs.stringify(parms) return qs.stringify(parms)
......
...@@ -21,7 +21,6 @@ const handleSelected = () => uploadInput.value.click() ...@@ -21,7 +21,6 @@ const handleSelected = () => uploadInput.value.click()
const submitUpload = (e: any) => { const submitUpload = (e: any) => {
const files = e.target.files const files = e.target.files
const rawFile = files[0] const rawFile = files[0]
console.log(rawFile);
if (!rawFile) return if (!rawFile) return
upload(rawFile) upload(rawFile)
} }
...@@ -33,7 +32,6 @@ const upload = (rawFile: any) => { ...@@ -33,7 +32,6 @@ const upload = (rawFile: any) => {
} }
const uploadSectionFile = (file: any, params?: any) => { const uploadSectionFile = (file: any, params?: any) => {
// let data = params
let fromData = new FormData()// FormData 对象 let fromData = new FormData()// FormData 对象
let fileObj = file// 相当于input里取得的files let fileObj = file// 相当于input里取得的files
fromData.append('file', fileObj)// 文件对象 fromData.append('file', fileObj)// 文件对象
...@@ -41,6 +39,7 @@ const uploadSectionFile = (file: any, params?: any) => { ...@@ -41,6 +39,7 @@ const uploadSectionFile = (file: any, params?: any) => {
importFile(fromData).then((res: any) => { importFile(fromData).then((res: any) => {
//调用上传接口 //调用上传接口
if (res.code === 200) { if (res.code === 200) {
window.location.href = '/#/login'
sessionStorage.clear() sessionStorage.clear()
ElMessage({ type: 'success', message: '导入成功!' }) ElMessage({ type: 'success', message: '导入成功!' })
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论