art: 🎨 页面全局提示
This commit is contained in:
@@ -1,22 +1,22 @@
|
||||
/**
|
||||
* @desc 登录
|
||||
*/
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
export default async function (
|
||||
/** 请求体 */
|
||||
requestBody: auth.LoginDTO,
|
||||
/** 请求体 */
|
||||
requestBody: auth.LoginDTO,
|
||||
|
||||
success: (data: auth.AuthUser) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
success: (data: auth.AuthUser) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
): Promise<void> {
|
||||
return http({
|
||||
method: 'post',
|
||||
url: `/auth/login`,
|
||||
data: requestBody,
|
||||
})
|
||||
.then((data: AxiosResponse<auth.AuthUser, unknown>) => {
|
||||
success(data.data);
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error));
|
||||
return http({
|
||||
method: 'post',
|
||||
url: `/auth/login`,
|
||||
data: requestBody,
|
||||
})
|
||||
.then((data: AxiosResponse<auth.AuthUser, unknown>) => {
|
||||
success(data.data)
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error))
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/**
|
||||
* @desc 增加/编辑物料
|
||||
*/
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
|
||||
import type { AxiosResponse } from 'axios'
|
||||
export default async function (
|
||||
/** 请求体 */
|
||||
requestBody: material.Material,
|
||||
/** 请求体 */
|
||||
requestBody: material.Material,
|
||||
|
||||
success: (data: material.Material) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
success: (data: material.Material) => void = defaultSuccess,
|
||||
fail: (error: { code: string; error?: string }) => void = defaultError,
|
||||
): Promise<void> {
|
||||
return http({
|
||||
method: 'put',
|
||||
url: `/material`,
|
||||
data: requestBody,
|
||||
})
|
||||
.then((data: AxiosResponse<material.Material, unknown>) => {
|
||||
success(data.data);
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error));
|
||||
return http({
|
||||
method: 'put',
|
||||
url: `/material`,
|
||||
data: requestBody,
|
||||
})
|
||||
.then((data: AxiosResponse<material.Material, unknown>) => {
|
||||
success(data.data)
|
||||
})
|
||||
.catch((error: { code: string; error?: string }) => fail(error))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { http } from '@/settings/http'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import axios, { InternalAxiosRequestConfig, type AxiosError, type AxiosResponse } from 'axios'
|
||||
import type { App } from 'vue'
|
||||
import router from '@/router'
|
||||
import { notification } from 'ant-design-vue'
|
||||
|
||||
export interface GlobalError {
|
||||
/** 错误码 */
|
||||
@@ -24,9 +24,13 @@ export function defaultSuccess(data: unknown): void {
|
||||
console.log(data)
|
||||
}
|
||||
export function defaultError(error: { code: string; error?: string }): void {
|
||||
if (error) {
|
||||
router.push({ path: '/message', query: { status: error.code, message: error.error } })
|
||||
}
|
||||
window.console.log(error)
|
||||
notification.error({
|
||||
message: '操作异常: ',
|
||||
placement: 'top',
|
||||
description: error.error + '(' + error.code + ')',
|
||||
duration: null,
|
||||
})
|
||||
}
|
||||
const config = {
|
||||
baseURL: http.prefix,
|
||||
|
||||
Reference in New Issue
Block a user