debug(aiot): 添加工作时间参数保存的详细日志
问题:用户保存工作时间参数时提示"参数保存失败" 调试:添加详细console日志帮助排查问题 - 显示保存前的原始数据 - 显示参数验证过程 - 显示working_hours格式检查 - 显示请求payload - 显示完整的错误响应 使用:打开浏览器F12控制台查看日志
This commit is contained in:
@@ -94,22 +94,34 @@ function isWorkingHoursField(key: string): boolean {
|
|||||||
|
|
||||||
async function handleSave() {
|
async function handleSave() {
|
||||||
try {
|
try {
|
||||||
|
console.log('[算法参数保存] 开始保存,原始数据:', formData.value);
|
||||||
|
|
||||||
// 保存前验证参数
|
// 保存前验证参数
|
||||||
const validation = validateParams(formData.value);
|
const validation = validateParams(formData.value);
|
||||||
|
console.log('[算法参数保存] 验证结果:', validation);
|
||||||
|
|
||||||
if (!validation.valid) {
|
if (!validation.valid) {
|
||||||
message.error(validation.error || '参数格式错误');
|
message.error(validation.error || '参数格式错误');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateAlgoParams({
|
const paramsJson = JSON.stringify(formData.value);
|
||||||
|
console.log('[算法参数保存] JSON序列化后:', paramsJson);
|
||||||
|
|
||||||
|
const payload = {
|
||||||
bindId: props.bindId,
|
bindId: props.bindId,
|
||||||
params: JSON.stringify(formData.value),
|
params: paramsJson,
|
||||||
});
|
};
|
||||||
|
console.log('[算法参数保存] 发送请求:', payload);
|
||||||
|
|
||||||
|
await updateAlgoParams(payload);
|
||||||
message.success('参数保存成功');
|
message.success('参数保存成功');
|
||||||
emit('saved', formData.value);
|
emit('saved', formData.value);
|
||||||
emit('update:open', false);
|
emit('update:open', false);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('保存失败:', error);
|
console.error('[算法参数保存] 保存失败,完整错误:', error);
|
||||||
|
console.error('[算法参数保存] 错误响应:', error?.response);
|
||||||
|
|
||||||
// 改进错误提示:显示后端返回的具体错误信息
|
// 改进错误提示:显示后端返回的具体错误信息
|
||||||
const errorMsg = error?.response?.data?.msg ||
|
const errorMsg = error?.response?.data?.msg ||
|
||||||
error?.response?.data?.message ||
|
error?.response?.data?.message ||
|
||||||
@@ -151,18 +163,30 @@ function validateParams(params: Record<string, any>): {
|
|||||||
|
|
||||||
// 特殊校验 working_hours 格式
|
// 特殊校验 working_hours 格式
|
||||||
if (key === 'working_hours' && value.length > 0) {
|
if (key === 'working_hours' && value.length > 0) {
|
||||||
|
console.log('[working_hours 验证] 当前值:', value);
|
||||||
|
console.log('[working_hours 验证] 值类型:', typeof value);
|
||||||
|
console.log('[working_hours 验证] 是否数组:', Array.isArray(value));
|
||||||
|
|
||||||
const isValid = value.every(
|
const isValid = value.every(
|
||||||
(item: any) =>
|
(item: any, index: number) => {
|
||||||
typeof item === 'object' &&
|
const valid = typeof item === 'object' &&
|
||||||
typeof item.start === 'string' &&
|
typeof item.start === 'string' &&
|
||||||
typeof item.end === 'string',
|
typeof item.end === 'string';
|
||||||
|
if (!valid) {
|
||||||
|
console.error(`[working_hours 验证] 第 ${index} 项格式错误:`, item);
|
||||||
|
}
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
error: '工作时间段格式错误,每项需包含 start 和 end',
|
error: '工作时间段格式错误,每项需包含 start 和 end 字符串',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[working_hours 验证] 格式正确 ✓');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user