26 changed files with 521 additions and 2502 deletions
File diff suppressed because it is too large
@ -1,32 +0,0 @@ |
|||||
import type { AxiosInstance, AxiosRequestConfig } from 'axios' |
|
||||
import { userStore } from '@/store/module/user' |
|
||||
|
|
||||
export default function createInterceptors(axios: AxiosInstance) { |
|
||||
axios.interceptors.request.use( |
|
||||
function (config: AxiosRequestConfig) { |
|
||||
const store = userStore() |
|
||||
if (config && config.headers&&store.token){ |
|
||||
config.headers['token'] = store.token |
|
||||
} |
|
||||
if (config && config.headers && !config!.headers['Content-Type']) { |
|
||||
config.headers['Accept'] = 'application/json'; |
|
||||
config.headers['Content-Type'] = 'application/x-www-form-urlencoded'; |
|
||||
} |
|
||||
// 在发送请求之前做些什么
|
|
||||
return config |
|
||||
}, |
|
||||
function (error) { |
|
||||
// 对请求错误做些什么
|
|
||||
return Promise.reject(error) |
|
||||
} |
|
||||
) |
|
||||
|
|
||||
axios.interceptors.response.use( |
|
||||
function (response) { |
|
||||
return response |
|
||||
}, |
|
||||
function (error) { |
|
||||
return Promise.reject(error) |
|
||||
} |
|
||||
) |
|
||||
} |
|
@ -1,11 +0,0 @@ |
|||||
import { http } from "@/api/_request" |
|
||||
import { IHttpMethod } from "@/enum" |
|
||||
import { readonly } from "vue" |
|
||||
|
|
||||
const api = { |
|
||||
getStruct: (data?: any) => http("/enesoon/organization/v1.0/orgStructure", IHttpMethod.GET, data), |
|
||||
getDepartment: (data?: any) => http("/enesoon/organization/v1.0/orgDepartment", IHttpMethod.GET, data), |
|
||||
getDepartmentEmp: (data?: any) => http("/enesoon/organization/v1.0/departmentEmp", IHttpMethod.GET, data), |
|
||||
} |
|
||||
|
|
||||
export default api |
|
@ -1,9 +1,8 @@ |
|||||
import { IHttpMethod } from '@/enum' |
import { IHttpMethod } from '@/enum' |
||||
import { http } from './_request' |
import { http } from '$/request' |
||||
|
|
||||
const api = { |
export const User = { |
||||
login: (data?: any) => http('/enesoon/login/v1.0/employees', IHttpMethod.GET, data), |
// login: (data?: any) => http('/enesoon/login/v1.0/employees', IHttpMethod.GET, data),
|
||||
|
login: (data?: any) => http('/api/login', IHttpMethod.GET, data), |
||||
getUserProfile: (data?: any) => http('/enesoon/user/v1.0/employees', IHttpMethod.GET, data) |
getUserProfile: (data?: any) => http('/enesoon/user/v1.0/employees', IHttpMethod.GET, data) |
||||
} |
} |
||||
|
|
||||
export default api |
|
@ -1,13 +1,14 @@ |
|||||
import { message } from 'ant-design-vue' |
|
||||
import { userStore } from "@/store/module/user" |
import { userStore } from "@/store/module/user" |
||||
|
|
||||
export default function error(err: any, type: number) { |
export default function error(err: any, type: number) { |
||||
switch (type) { |
switch (type) { |
||||
case 0: |
case 0: |
||||
const store = userStore() |
const store = userStore() |
||||
message.error(err?.data?.message?err?.data?.message:"未知错误") |
console.log(err?.data?.message?err?.data?.message:"未知错误"); |
||||
if(err?.data&&err?.data.code === -1){ |
if(err?.data&&err?.data.code === -1){ |
||||
store.logout(false) |
// Token过期逻辑
|
||||
|
// store.logout(false)
|
||||
} |
} |
||||
// 响应正确,服务器返回错误
|
// 响应正确,服务器返回错误
|
||||
break |
break |
@ -0,0 +1,55 @@ |
|||||
|
import type { AxiosInstance, AxiosRequestConfig } from "axios" |
||||
|
import { userStore } from "@/store/module/user" |
||||
|
import checkError from './error' |
||||
|
|
||||
|
export default function createInterceptors(axios: AxiosInstance) { |
||||
|
axios.interceptors.request.use( |
||||
|
function (config: AxiosRequestConfig) { |
||||
|
const store = userStore() |
||||
|
if (config && config.headers && store.token) { |
||||
|
config.headers["token"] = store.token |
||||
|
} |
||||
|
if (config && config.headers && !config!.headers["Content-Type"]) { |
||||
|
config.headers["Accept"] = "application/json" |
||||
|
config.headers["Content-Type"] = "application/x-www-form-urlencoded" |
||||
|
} |
||||
|
// 在发送请求之前做些什么
|
||||
|
return config |
||||
|
}, |
||||
|
function (error) { |
||||
|
// 对请求错误做些什么
|
||||
|
return Promise.reject(error) |
||||
|
} |
||||
|
) |
||||
|
|
||||
|
axios.interceptors.response.use( |
||||
|
function (response) { |
||||
|
console.log(response); |
||||
|
return Promise.reject(response); |
||||
|
return response |
||||
|
}, |
||||
|
function (error) { |
||||
|
const { response } = error |
||||
|
console.log(error); |
||||
|
console.log(response); |
||||
|
|
||||
|
if (response) { |
||||
|
// 请求已发出,但是不在2xx的范围
|
||||
|
console.log("请求已发出,但是不在2xx的范围"); |
||||
|
return Promise.reject(response); |
||||
|
} else { |
||||
|
// 处理断网的情况
|
||||
|
// eg:请求超时或断网时,更新state的network状态
|
||||
|
// network状态在app.vue中控制着一个全局的断网提示组件的显示隐藏
|
||||
|
// 关于断网组件中的刷新重新获取数据,会在断网组件中说明
|
||||
|
if (!window.navigator.onLine) { |
||||
|
console.log("网络连接断开"); |
||||
|
// store.commit("changeNetwork", false)
|
||||
|
} else { |
||||
|
return Promise.reject(error) |
||||
|
} |
||||
|
} |
||||
|
return Promise.reject(error) |
||||
|
} |
||||
|
) |
||||
|
} |
@ -1 +1,2 @@ |
|||||
export const BASE_URL = "https://enesoon-saas-back-test.cn:8381" |
// export const BASE_URL = "https://enesoon-saas-back-test.cn:8381"
|
||||
|
export const BASE_URL = "" |
||||
|
@ -1,8 +1,11 @@ |
|||||
<template> |
<template> |
||||
<div>header</div> |
<div @click="post">header</div> |
||||
</template> |
</template> |
||||
<script lang="ts" setup> |
<script lang="ts" setup> |
||||
|
import * as http from "@/api" |
||||
|
async function post(){ |
||||
|
await http.User.login() |
||||
|
} |
||||
</script> |
</script> |
||||
|
|
||||
<style lang="less" scoped> |
<style lang="less" scoped> |
@ -1,12 +1,11 @@ |
|||||
export const REDIRECT_NAME = 'Redirect'; |
/** |
||||
|
* @description: system pages |
||||
export const PARENT_LAYOUT_NAME = 'ParentLayout'; |
*/ |
||||
export const PAGE_NOT_FOUND_NAME = 'PageNotFound'; |
export const LOGIN_COMPONENT = () => import("@/pagesSys/Login/Login.vue") |
||||
|
export const EXCEPTION_COMPONENT = () => import("@/pagesSys/Exception/Exception.vue") |
||||
|
export const REDIRECT_COMPONENT = () => import("@/pagesSys/Redirect/Redirect.vue") |
||||
|
|
||||
export const LOGIN_COMPONENT = () => import('@/pagesSys/Login/Login.vue'); |
|
||||
export const EXCEPTION_COMPONENT = () => import('@/pagesSys/Exception/Exception.vue'); |
|
||||
export const REDIRECT_COMPONENT = () => import('@/pagesSys/Redirect/Redirect.vue'); |
|
||||
/** |
/** |
||||
* @description: default layout |
* @description: default layout |
||||
*/ |
*/ |
||||
export const LAYOUT = () => import('@/pagesSys/Layout/Layout.vue'); |
export const LAYOUT = () => import("@/layout/Layout.vue") |
||||
|
Loading…
Reference in new issue