Skip to content

Commit d2513fd

Browse files
committed
修改extend传参
1 parent def75c1 commit d2513fd

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

dashboard/src/api/modules/module.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,22 @@ const buildModuleUrl = (module) => {
2626
*/
2727
const directApiCall = async (apiUrl, params = {}) => {
2828
try {
29+
// 为了确保像 `extend` 这样的对象被作为单个 JSON 字符串传递(而不是被 axios 序列化为 extend[host]=...&extend[version]=...),
30+
const serializedParams = { ...params }
31+
Object.keys(serializedParams).forEach((key) => {
32+
const val = serializedParams[key]
33+
if (val !== null && typeof val === 'object') {
34+
try {
35+
serializedParams[key] = JSON.stringify(val)
36+
} catch (err) {
37+
// 如果序列化失败,保留原值并打印警告
38+
console.warn(`无法序列化参数 ${key}`, err)
39+
}
40+
}
41+
})
42+
2943
const response = await axios.get(apiUrl, {
30-
params,
44+
params: serializedParams,
3145
timeout: 30000,
3246
headers: {
3347
'Accept': 'application/json'

0 commit comments

Comments
 (0)