From 3f0aee87ac4b9d63d9118ffe33439830cdf14f38 Mon Sep 17 00:00:00 2001 From: zhanglei Date: Wed, 25 Mar 2026 09:28:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=88=B7=E6=96=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/vue/index.vue.j2 | 26 ++++++------- .../apps/web-antd/src/views/device/index.vue | 38 ++++++++----------- .../apps/web-antd/src/views/fun/index.vue | 26 ++++++------- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/templates/vue/index.vue.j2 b/templates/vue/index.vue.j2 index 943fac4..3b20dad 100644 --- a/templates/vue/index.vue.j2 +++ b/templates/vue/index.vue.j2 @@ -134,7 +134,8 @@ watch( {immediate: false} ); -// ========== 表格配置 ========== +// 存储当前页码 +const currentPageRef = ref(1); // ========== 表格配置 ========== const gridOptions = { columns: [ @@ -292,22 +293,21 @@ const gridOptions = { console.log('=== 查询参数 ===', { pageNum: page?.currentPage || 1, pageSize: page?.pageSize || 10, + currentPageRef: currentPageRef.value, ...queryValues, }) const res = await {{entity}}Api.page({ - pageNum: page?.currentPage || 1, + pageNum: page.currentPage || 1, pageSize: page?.pageSize || 10, ...queryValues, // 携带查询条件 }) const data = res.error?.result || res.result || res - return { items: data.records || [], total: data.total || 0 } - } catch (error) { console.error('查询列表失败:', error) throw error @@ -360,15 +360,15 @@ const [Modal, modalApi] = useVbenModal({ if (isEdit.value && currentRow.value?.id) { await {{entity}}Api.save({...finalSubmitValues, id: currentRow.value.id}); + Object.assign(currentRow.value, finalSubmitValues); + modalApi.close(); + gridApi.reloadRow(currentRow.value); + isEdit.value = false; } else { await {{entity}}Api.add(finalSubmitValues); - } - - modalApi.close(); - gridApi.reload(); - - // 重置上传 URL 记录 - if (!isEdit.value) { + // 新增才 reload(必须) + modalApi.close(); + gridApi.reload(); formUploadUrls.value = {}; } } catch (error) { @@ -433,7 +433,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 关闭弹窗并刷新表格 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); // 重置状态 uploadFileList.value = []; @@ -447,7 +447,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 只更新预览,不保存 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); } } catch (error: any) { diff --git a/vue-vben-admin/apps/web-antd/src/views/device/index.vue b/vue-vben-admin/apps/web-antd/src/views/device/index.vue index 3e0e17e..b760d3e 100644 --- a/vue-vben-admin/apps/web-antd/src/views/device/index.vue +++ b/vue-vben-admin/apps/web-antd/src/views/device/index.vue @@ -134,7 +134,8 @@ watch( {immediate: false} ); -// ========== 表格配置 ========== +// 存储当前页码 +const currentPageRef = ref(1); // ========== 表格配置 ========== const gridOptions = { columns: [ @@ -292,22 +293,21 @@ const gridOptions = { console.log('=== 查询参数 ===', { pageNum: page?.currentPage || 1, pageSize: page?.pageSize || 10, + currentPageRef: currentPageRef.value, ...queryValues, }) const res = await deviceApi.page({ - pageNum: page?.currentPage || 1, + pageNum: page.currentPage || 1, pageSize: page?.pageSize || 10, ...queryValues, // 携带查询条件 }) const data = res.error?.result || res.result || res - return { items: data.records || [], total: data.total || 0 } - } catch (error) { console.error('查询列表失败:', error) throw error @@ -360,15 +360,15 @@ const [Modal, modalApi] = useVbenModal({ if (isEdit.value && 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 { await deviceApi.add(finalSubmitValues); - } - - modalApi.close(); - gridApi.reload(); - - // 重置上传 URL 记录 - if (!isEdit.value) { + // 新增才 reload(必须) + modalApi.close(); + gridApi.reload(); formUploadUrls.value = {}; } } catch (error) { @@ -433,7 +433,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 关闭弹窗并刷新表格 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); // 重置状态 uploadFileList.value = []; @@ -447,7 +447,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 只更新预览,不保存 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); } } catch (error: any) { @@ -478,7 +478,7 @@ const getEditFormSchema = () => { // 只在新增模式下,且是图片字段,添加上传组件 if (!isEdit.value && isImageField(item.fieldName)) { // 优先使用 formUploadUrls 中存储的 URL,其次使用表单值 - const currentImageUrl = formUploadUrls.value[item.fieldName] || formApi.getValues()?.[item.fieldName] || ''; + const currentImageUrl = formUploadUrls.value[item.fieldName] || ''; return { ...item, component: 'Upload', @@ -510,20 +510,14 @@ const getEditFormSchema = () => { // 保存上传返回的 URL 到专用存储 formUploadUrls.value[item.fieldName] = resultUrl; - // 同时更新表单值(用于显示) - const currentValues = formApi.getValues(); - formApi.setValues({ - ...currentValues, - [item.fieldName]: resultUrl - }); - // 上传成功后,重新生成 schema 以更新 fileList 显示 setTimeout(() => { formApi.setState({ schema: getEditFormSchema(), }); }, 0); - formApi.resetForm(); + + // Deleted:formApi.resetForm(); // 返回 false 阻止默认上传行为 return false; } catch (error: any) { diff --git a/vue-vben-admin/apps/web-antd/src/views/fun/index.vue b/vue-vben-admin/apps/web-antd/src/views/fun/index.vue index 324d114..9cda98c 100644 --- a/vue-vben-admin/apps/web-antd/src/views/fun/index.vue +++ b/vue-vben-admin/apps/web-antd/src/views/fun/index.vue @@ -134,7 +134,8 @@ watch( {immediate: false} ); -// ========== 表格配置 ========== +// 存储当前页码 +const currentPageRef = ref(1); // ========== 表格配置 ========== const gridOptions = { columns: [ @@ -292,22 +293,21 @@ const gridOptions = { console.log('=== 查询参数 ===', { pageNum: page?.currentPage || 1, pageSize: page?.pageSize || 10, + currentPageRef: currentPageRef.value, ...queryValues, }) const res = await funApi.page({ - pageNum: page?.currentPage || 1, + pageNum: page.currentPage || 1, pageSize: page?.pageSize || 10, ...queryValues, // 携带查询条件 }) const data = res.error?.result || res.result || res - return { items: data.records || [], total: data.total || 0 } - } catch (error) { console.error('查询列表失败:', error) throw error @@ -360,15 +360,15 @@ const [Modal, modalApi] = useVbenModal({ if (isEdit.value && currentRow.value?.id) { await funApi.save({...finalSubmitValues, id: currentRow.value.id}); + Object.assign(currentRow.value, finalSubmitValues); + modalApi.close(); + gridApi.reloadRow(currentRow.value); + isEdit.value = false; } else { await funApi.add(finalSubmitValues); - } - - modalApi.close(); - gridApi.reload(); - - // 重置上传 URL 记录 - if (!isEdit.value) { + // 新增才 reload(必须) + modalApi.close(); + gridApi.reload(); formUploadUrls.value = {}; } } catch (error) { @@ -433,7 +433,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 关闭弹窗并刷新表格 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); // 重置状态 uploadFileList.value = []; @@ -447,7 +447,7 @@ const [UploadModal, uploadModalApi] = useVbenModal({ // 只更新预览,不保存 uploadModalApi.close(); - gridApi.reload(); + // gridApi.reload(); } } catch (error: any) {