mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-05 19:41:59 +08:00
feat(service): 去除请求虚值字段
This commit is contained in:
parent
a1ffb3c884
commit
2dbea4b4cd
@ -1,5 +1,5 @@
|
|||||||
import { ERROR_MSG_DURATION, ERROR_NO_TIP_STATUS } from '@/config';
|
import { ERROR_MSG_DURATION, ERROR_NO_TIP_STATUS } from '@/config';
|
||||||
import { isArray, isFile } from '@/utils';
|
import { isArray, isFile, isEmpty, isNullOrUnDef } from '@/utils';
|
||||||
import { EnumContentType } from '@/enum';
|
import { EnumContentType } from '@/enum';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
|
|
||||||
@ -18,14 +18,16 @@ export function showError(error: Service.RequestError) {
|
|||||||
*/
|
*/
|
||||||
export async function transformRequestData(requestData: any, contentType?: string) {
|
export async function transformRequestData(requestData: any, contentType?: string) {
|
||||||
// application/json类型不处理
|
// application/json类型不处理
|
||||||
let data = requestData;
|
let data = clearInvalidParameters(requestData);
|
||||||
|
// let data = requestData;
|
||||||
|
|
||||||
// form类型转换
|
// form类型转换
|
||||||
if (contentType === EnumContentType.formUrlencoded) {
|
if (contentType === EnumContentType.formUrlencoded) {
|
||||||
data = qs.stringify(requestData);
|
data = qs.stringify(data);
|
||||||
}
|
}
|
||||||
// form-data类型转换
|
// form-data类型转换
|
||||||
if (contentType === EnumContentType.formData) {
|
if (contentType === EnumContentType.formData) {
|
||||||
data = await handleFormData(requestData);
|
data = await handleFormData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -67,3 +69,16 @@ async function transformFile(formData: FormData, key: string, file: File[] | Fil
|
|||||||
formData.append(key, file);
|
formData.append(key, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口提交的参数去除无效字段
|
||||||
|
* @param requestData -接口提交的参数
|
||||||
|
*/
|
||||||
|
function clearInvalidParameters(requestData: Record<string, any>) {
|
||||||
|
const result: Record<string, any> = {};
|
||||||
|
for (const key in requestData) {
|
||||||
|
if (isEmpty(requestData[key]) || isNullOrUnDef(requestData[key])) continue;
|
||||||
|
result[key] = requestData[key];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -80,7 +80,7 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
async initDynamicRoute() {
|
async initDynamicRoute() {
|
||||||
// 根据用户id来获取用户的路由
|
// 根据用户id来获取用户的路由
|
||||||
const { userId } = getUserInfo();
|
const { userId } = getUserInfo();
|
||||||
const { data: routes } = await fetchUserRoutes(userId);
|
const { data: routes } = await fetchUserRoutes({ userId });
|
||||||
// 根据用户返回的路由表来生成真实路由
|
// 根据用户返回的路由表来生成真实路由
|
||||||
const appRoutes = await createDynamicRoutes(routes);
|
const appRoutes = await createDynamicRoutes(routes);
|
||||||
// 生成侧边菜单
|
// 生成侧边菜单
|
||||||
|
@ -142,6 +142,11 @@ const delete2 = () => {
|
|||||||
const post = () => {
|
const post = () => {
|
||||||
const params = {
|
const params = {
|
||||||
data: '2022-2-2',
|
data: '2022-2-2',
|
||||||
|
data1: [],
|
||||||
|
data2: {},
|
||||||
|
data3: '',
|
||||||
|
data4: null,
|
||||||
|
data5: undefined,
|
||||||
};
|
};
|
||||||
fetachPost(params).then((res) => {
|
fetachPost(params).then((res) => {
|
||||||
msg.value = res;
|
msg.value = res;
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
// "sourceMap": true,
|
// "sourceMap": true,
|
||||||
"removeComments": false, //编译删除注释
|
"removeComments": false, //编译删除注释
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"lib": ["ESNext", "DOM"],
|
"lib": ["ESNext", "DOM"],
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"~/*": ["./*"],
|
"~/*": ["./*"],
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
},
|
},
|
||||||
"types": ["node", "vite/client", "naive-ui/volar"]
|
"types": ["node", "vite/client", "naive-ui/volar"]
|
||||||
},
|
},
|
||||||
// "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
// "include": ["src/**/*.d.ts", "src/**/*.vue", "./*.d.ts"]
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user