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 { isArray, isFile } from '@/utils';
|
||||
import { isArray, isFile, isEmpty, isNullOrUnDef } from '@/utils';
|
||||
import { EnumContentType } from '@/enum';
|
||||
import qs from 'qs';
|
||||
|
||||
@ -18,14 +18,16 @@ export function showError(error: Service.RequestError) {
|
||||
*/
|
||||
export async function transformRequestData(requestData: any, contentType?: string) {
|
||||
// application/json类型不处理
|
||||
let data = requestData;
|
||||
let data = clearInvalidParameters(requestData);
|
||||
// let data = requestData;
|
||||
|
||||
// form类型转换
|
||||
if (contentType === EnumContentType.formUrlencoded) {
|
||||
data = qs.stringify(requestData);
|
||||
data = qs.stringify(data);
|
||||
}
|
||||
// form-data类型转换
|
||||
if (contentType === EnumContentType.formData) {
|
||||
data = await handleFormData(requestData);
|
||||
data = await handleFormData(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
@ -67,3 +69,16 @@ async function transformFile(formData: FormData, key: string, file: File[] | Fil
|
||||
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() {
|
||||
// 根据用户id来获取用户的路由
|
||||
const { userId } = getUserInfo();
|
||||
const { data: routes } = await fetchUserRoutes(userId);
|
||||
const { data: routes } = await fetchUserRoutes({ userId });
|
||||
// 根据用户返回的路由表来生成真实路由
|
||||
const appRoutes = await createDynamicRoutes(routes);
|
||||
// 生成侧边菜单
|
||||
|
@ -142,6 +142,11 @@ const delete2 = () => {
|
||||
const post = () => {
|
||||
const params = {
|
||||
data: '2022-2-2',
|
||||
data1: [],
|
||||
data2: {},
|
||||
data3: '',
|
||||
data4: null,
|
||||
data5: undefined,
|
||||
};
|
||||
fetachPost(params).then((res) => {
|
||||
msg.value = res;
|
||||
|
@ -1,25 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
// "sourceMap": true,
|
||||
"removeComments": false, //编译删除注释
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"~/*": ["./*"],
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"types": ["node", "vite/client", "naive-ui/volar"]
|
||||
},
|
||||
// "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
// "sourceMap": true,
|
||||
"removeComments": false, //编译删除注释
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"~/*": ["./*"],
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"types": ["node", "vite/client", "naive-ui/volar"]
|
||||
},
|
||||
// "include": ["src/**/*.d.ts", "src/**/*.vue", "./*.d.ts"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user