|
|
@ -134,7 +134,8 @@ watch( |
|
|
{immediate: false} |
|
|
{immediate: false} |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// ========== 表格配置 ========== |
|
|
// 存储当前页码 |
|
|
|
|
|
const currentPageRef = ref(1); |
|
|
// ========== 表格配置 ========== |
|
|
// ========== 表格配置 ========== |
|
|
const gridOptions = { |
|
|
const gridOptions = { |
|
|
columns: [ |
|
|
columns: [ |
|
|
@ -292,22 +293,21 @@ const gridOptions = { |
|
|
console.log('=== 查询参数 ===', { |
|
|
console.log('=== 查询参数 ===', { |
|
|
pageNum: page?.currentPage || 1, |
|
|
pageNum: page?.currentPage || 1, |
|
|
pageSize: page?.pageSize || 10, |
|
|
pageSize: page?.pageSize || 10, |
|
|
|
|
|
currentPageRef: currentPageRef.value, |
|
|
...queryValues, |
|
|
...queryValues, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const res = await deviceApi.page({ |
|
|
const res = await deviceApi.page({ |
|
|
pageNum: page?.currentPage || 1, |
|
|
pageNum: page.currentPage || 1, |
|
|
pageSize: page?.pageSize || 10, |
|
|
pageSize: page?.pageSize || 10, |
|
|
...queryValues, // 携带查询条件 |
|
|
...queryValues, // 携带查询条件 |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const data = res.error?.result || res.result || res |
|
|
const data = res.error?.result || res.result || res |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
items: data.records || [], |
|
|
items: data.records || [], |
|
|
total: data.total || 0 |
|
|
total: data.total || 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('查询列表失败:', error) |
|
|
console.error('查询列表失败:', error) |
|
|
throw error |
|
|
throw error |
|
|
@ -360,15 +360,15 @@ const [Modal, modalApi] = useVbenModal({ |
|
|
|
|
|
|
|
|
if (isEdit.value && currentRow.value?.id) { |
|
|
if (isEdit.value && currentRow.value?.id) { |
|
|
await deviceApi.save({...finalSubmitValues, id: currentRow.value.id}); |
|
|
await deviceApi.save({...finalSubmitValues, id: currentRow.value.id}); |
|
|
|
|
|
Object.assign(currentRow.value, finalSubmitValues); |
|
|
|
|
|
modalApi.close(); |
|
|
|
|
|
gridApi.reloadRow(currentRow.value); |
|
|
|
|
|
isEdit.value = false; |
|
|
} else { |
|
|
} else { |
|
|
await deviceApi.add(finalSubmitValues); |
|
|
await deviceApi.add(finalSubmitValues); |
|
|
} |
|
|
// 新增才 reload(必须) |
|
|
|
|
|
modalApi.close(); |
|
|
modalApi.close(); |
|
|
gridApi.reload(); |
|
|
gridApi.reload(); |
|
|
|
|
|
|
|
|
|
|
|
// 重置上传 URL 记录 |
|
|
|
|
|
if (!isEdit.value) { |
|
|
|
|
|
formUploadUrls.value = {}; |
|
|
formUploadUrls.value = {}; |
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
@ -433,7 +433,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ |
|
|
|
|
|
|
|
|
// 关闭弹窗并刷新表格 |
|
|
// 关闭弹窗并刷新表格 |
|
|
uploadModalApi.close(); |
|
|
uploadModalApi.close(); |
|
|
gridApi.reload(); |
|
|
// gridApi.reload(); |
|
|
|
|
|
|
|
|
// 重置状态 |
|
|
// 重置状态 |
|
|
uploadFileList.value = []; |
|
|
uploadFileList.value = []; |
|
|
@ -447,7 +447,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ |
|
|
|
|
|
|
|
|
// 只更新预览,不保存 |
|
|
// 只更新预览,不保存 |
|
|
uploadModalApi.close(); |
|
|
uploadModalApi.close(); |
|
|
gridApi.reload(); |
|
|
// gridApi.reload(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} catch (error: any) { |
|
|
} catch (error: any) { |
|
|
@ -478,7 +478,7 @@ const getEditFormSchema = () => { |
|
|
// 只在新增模式下,且是图片字段,添加上传组件 |
|
|
// 只在新增模式下,且是图片字段,添加上传组件 |
|
|
if (!isEdit.value && isImageField(item.fieldName)) { |
|
|
if (!isEdit.value && isImageField(item.fieldName)) { |
|
|
// 优先使用 formUploadUrls 中存储的 URL,其次使用表单值 |
|
|
// 优先使用 formUploadUrls 中存储的 URL,其次使用表单值 |
|
|
const currentImageUrl = formUploadUrls.value[item.fieldName] || formApi.getValues()?.[item.fieldName] || ''; |
|
|
const currentImageUrl = formUploadUrls.value[item.fieldName] || ''; |
|
|
return { |
|
|
return { |
|
|
...item, |
|
|
...item, |
|
|
component: 'Upload', |
|
|
component: 'Upload', |
|
|
@ -510,20 +510,14 @@ const getEditFormSchema = () => { |
|
|
// 保存上传返回的 URL 到专用存储 |
|
|
// 保存上传返回的 URL 到专用存储 |
|
|
formUploadUrls.value[item.fieldName] = resultUrl; |
|
|
formUploadUrls.value[item.fieldName] = resultUrl; |
|
|
|
|
|
|
|
|
// 同时更新表单值(用于显示) |
|
|
|
|
|
const currentValues = formApi.getValues(); |
|
|
|
|
|
formApi.setValues({ |
|
|
|
|
|
...currentValues, |
|
|
|
|
|
[item.fieldName]: resultUrl |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// 上传成功后,重新生成 schema 以更新 fileList 显示 |
|
|
// 上传成功后,重新生成 schema 以更新 fileList 显示 |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
formApi.setState({ |
|
|
formApi.setState({ |
|
|
schema: getEditFormSchema(), |
|
|
schema: getEditFormSchema(), |
|
|
}); |
|
|
}); |
|
|
}, 0); |
|
|
}, 0); |
|
|
formApi.resetForm(); |
|
|
|
|
|
|
|
|
// Deleted:formApi.resetForm(); |
|
|
// 返回 false 阻止默认上传行为 |
|
|
// 返回 false 阻止默认上传行为 |
|
|
return false; |
|
|
return false; |
|
|
} catch (error: any) { |
|
|
} catch (error: any) { |
|
|
|