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

优化

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