完善类型配置,新增L1, L4数据展示界面
This commit is contained in:
7
src/api/common/model.d.ts
vendored
Normal file
7
src/api/common/model.d.ts
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface ApiResponse<T = any> {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
data?: T;
|
||||
rows?: T[];
|
||||
total?: number;
|
||||
}
|
||||
20
src/api/data/index.ts
Normal file
20
src/api/data/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import request from '../request';
|
||||
import type { QueryParams } from './model';
|
||||
|
||||
// 获取 L1 数据
|
||||
export function getL1Data(params: QueryParams) {
|
||||
return request({
|
||||
url: '/jinghua/l1Data/list',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
// 获取 L4 数据
|
||||
export function getL4Data(params: QueryParams) {
|
||||
return request({
|
||||
url: '/jinghua/l4Data/list',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
9
src/api/data/model.d.ts
vendored
Normal file
9
src/api/data/model.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface QueryParams {
|
||||
pageNum?: number;
|
||||
pageSize?: number;
|
||||
orderByColumn?: string;
|
||||
isAsc?: boolean;
|
||||
qrCode?: string;
|
||||
createTimeBegin?: string;
|
||||
createTimeEnd?: string;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import type { LmsWorkMode } from './model';
|
||||
// 获取 LMS 工作模式
|
||||
export const fetchLmsWorkMode = () => {
|
||||
return request({
|
||||
url: '/jinghua/mes/work-mode',
|
||||
url: '/jinghua/work-mode',
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export const fetchLmsWorkMode = () => {
|
||||
// 更新 LMS 工作模式
|
||||
export const updateLmsWorkMode = (workMode: LmsWorkMode) => {
|
||||
return request({
|
||||
url: `/jinghua/mes/work-mode/${workMode}`,
|
||||
url: `/jinghua/work-mode/${workMode}`,
|
||||
method: 'put',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import axios from 'axios';
|
||||
import { Modal, notification } from 'ant-design-vue';
|
||||
import router from '@/router';
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { Modal, notification } from 'ant-design-vue';
|
||||
import type { AxiosRequestConfig } from "axios";
|
||||
import type { ApiResponse } from "@/api/common/model";
|
||||
|
||||
const errCodeMap: { [key: string]: string } = {
|
||||
'403': '当前操作没有权限',
|
||||
@@ -12,7 +14,7 @@ const errCodeMap: { [key: string]: string } = {
|
||||
// 创建axios实例
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.VITE_APP_BASE_API as string,
|
||||
timeout: 10000
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
// 请求拦截器
|
||||
@@ -36,37 +38,46 @@ service.interceptors.request.use(
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
console.log(response)
|
||||
// 未设置状态码则默认成功状态
|
||||
const code = response.data.code || 200;
|
||||
const data = response.data;
|
||||
|
||||
if (code === 200) {
|
||||
return response.data ?? response;
|
||||
} else if (code === 401) {
|
||||
Modal.error({
|
||||
title: '系统提示',
|
||||
content: '登录状态已过期,请重新登录',
|
||||
onOk: () => {
|
||||
router.push('/login')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const codeStr = String(code);
|
||||
const errMsg = errCodeMap[codeStr] || response.data.msg || errCodeMap['default'];
|
||||
notification.error({
|
||||
message: '请求错误',
|
||||
description: errMsg,
|
||||
});
|
||||
return Promise.reject(response.data);
|
||||
switch (code) {
|
||||
case 200:
|
||||
return data ?? response;
|
||||
case 401:
|
||||
Modal.error({
|
||||
title: '系统提示',
|
||||
content: '登录状态已过期,请重新登录',
|
||||
onOk: () => {
|
||||
router.push('/login')
|
||||
}
|
||||
})
|
||||
return Promise.reject(data);
|
||||
default:
|
||||
const errMsg = errCodeMap[code] || data.msg || errCodeMap['default'];
|
||||
notification.error({
|
||||
message: '请求错误',
|
||||
description: errMsg,
|
||||
});
|
||||
return Promise.reject(data);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
error.message = error.code === "ECONNABORTED" ? '请求超时,请稍后重试' : error.message;
|
||||
|
||||
// 网络/服务器错误统一处理
|
||||
notification.error({
|
||||
message: '网络错误',
|
||||
description: error.message || '请求失败',
|
||||
message: "网络错误",
|
||||
description: error.message,
|
||||
});
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
||||
// 类型检查
|
||||
function request<T = any>(config: AxiosRequestConfig): Promise<ApiResponse<T>> {
|
||||
return service(config) as unknown as Promise<ApiResponse<T>>;
|
||||
}
|
||||
|
||||
export default request;
|
||||
// export default service;
|
||||
Reference in New Issue
Block a user