Merge branch 'master' of gitee.com:liangzigongshe/foreign-admin-ui into 2026-4-8SongslDev
Signed-off-by: Songsl <16905340+songsl2000@user.noreply.gitee.com>
This commit is contained in:
commit
b743b76f7e
|
|
@ -79,6 +79,7 @@ service.interceptors.request.use(requestInterceptor, requestErrorInterceptor)
|
||||||
const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>>) => {
|
const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>>) => {
|
||||||
//关闭loading(无论成功失败都要关)
|
//关闭loading(无论成功失败都要关)
|
||||||
hideLoading()
|
hideLoading()
|
||||||
|
const config = response.config
|
||||||
if (response.headers['new_token'] !== undefined) {
|
if (response.headers['new_token'] !== undefined) {
|
||||||
setStorage('token', response.headers['new_token'] as string)
|
setStorage('token', response.headers['new_token'] as string)
|
||||||
}
|
}
|
||||||
|
|
@ -87,13 +88,14 @@ const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>
|
||||||
console.log('响应数据data', data)
|
console.log('响应数据data', data)
|
||||||
// 判断业务状态码
|
// 判断业务状态码
|
||||||
if (data.code == 200 || data.code == 0) {
|
if (data.code == 200 || data.code == 0) {
|
||||||
// 仅当业务成功时,才弹成功提示
|
if (config.showMessage !== false) {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
message: data.msg || '操作成功!',
|
message: data.msg || '操作成功!',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
customClass: 'global-notification',
|
customClass: 'global-notification'
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return data.data
|
return data.data
|
||||||
} else {
|
} else {
|
||||||
switch (data.code) {
|
switch (data.code) {
|
||||||
|
|
@ -156,12 +158,14 @@ const responseErrorInterceptor = (error: AxiosError) => {
|
||||||
errMsg = error.message || '服务器错误'
|
errMsg = error.message || '服务器错误'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (error.config?.showMessage !== false) {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
message: errMsg,
|
message: errMsg,
|
||||||
type: 'error',
|
type: 'error',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
customClass: 'global-notification',
|
customClass: 'global-notification'
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,14 +174,14 @@ service.interceptors.response.use(responseInterceptor, responseErrorInterceptor)
|
||||||
// 5. 封装通用请求方法
|
// 5. 封装通用请求方法
|
||||||
export const request = {
|
export const request = {
|
||||||
get<T = unknown>(url: string, params?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
get<T = unknown>(url: string, params?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||||
return service.get<ApiResponse<T>>(url, { params, ...config }).then((res) => {
|
return service.get<ApiResponse<T>>(url, { params, ...config,showMessage:false }).then((res) => {
|
||||||
return res as T
|
return res as T;
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
post<T = unknown>(url: string, data?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
post<T = unknown>(url: string, data?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||||
return service.post<ApiResponse<T>>(url, data, config).then((res) => {
|
return service.post<ApiResponse<T>>(url, data, {config,showMessage: true,}).then((res) => {
|
||||||
return res as T
|
return res as T;
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<!-- 菜单区域 -->
|
<!-- 菜单区域 -->
|
||||||
<el-menu class="menu" :unique-opened="true" :default-active="activeMenu" router>
|
<el-menu class="menu" :unique-opened="true" :default-active="activeMenu" router>
|
||||||
<template v-for="menu in staticMenuList" :key="menu.id">
|
<template v-for="menu in menuList" :key="menu.id">
|
||||||
<!-- 无子菜单 -->
|
<!-- 无子菜单 -->
|
||||||
<el-menu-item v-if="!menu.children || menu.children.length === 0" :index="menu.path">
|
<el-menu-item v-if="!menu.children || menu.children.length === 0" :index="menu.path">
|
||||||
<el-icon>
|
<el-icon>
|
||||||
|
|
@ -58,7 +58,7 @@ const menuList = ref<any[]>([])
|
||||||
|
|
||||||
// 计算当前激活的菜单 index(取路由 fullPath 作为激活标识)
|
// 计算当前激活的菜单 index(取路由 fullPath 作为激活标识)
|
||||||
const activeMenu = computed(() => {
|
const activeMenu = computed(() => {
|
||||||
return route.fullPath // 直接使用完整路径,和你的菜单 path 保持一致
|
return route.fullPath // 直接使用完整路径,和菜单 path 保持一致
|
||||||
})
|
})
|
||||||
// 组件挂载时异步加载菜单
|
// 组件挂载时异步加载菜单
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue