Skip to content

Commit c0d71c7

Browse files
committed
chore: 优化判断顺序
1 parent ba62651 commit c0d71c7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/templates/template.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ ${options.useStaticMethod ? 'static' : ''} ${camelcase(
238238
}
239239

240240
function requestBodyString(method: string, parsedParameters: [], bodyParameter: [], requestBody: string, contentType: string, formData: string) {
241-
if (method === 'post' || method === 'put') {
242-
return `
241+
if (parsedParameters && bodyParameter && bodyParameter.length > 0 || !!requestBody) {
242+
if (method === 'post' || method === 'put') {
243+
return `
243244
let data = ${parsedParameters && bodyParameter && bodyParameter.length > 0
244-
?
245-
bodyParameter
246-
: !!requestBody
247-
? 'params.body'
248-
: 'null'
249-
}
245+
?
246+
bodyParameter
247+
: !!requestBody
248+
? 'params.body'
249+
: 'null'
250+
}
250251
${contentType === 'multipart/form-data' ? formData : ''}
251252
configs.data = data;`
252-
}
253-
else {
254-
if (bodyParameter && bodyParameter.length > 0 || !!requestBody) {
253+
}
254+
else {
255255
return `/** 适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body */ \n
256-
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')
257-
`
256+
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')
257+
`
258258
}
259259
}
260260
}

0 commit comments

Comments
 (0)