From f03e9a0e07a02ca5063c8ca6ed6b176cbcf0f1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Tue, 28 Apr 2026 09:12:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(product):=20=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=94=B9=E7=94=A8useVbenForm=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96flex=E5=B8=83=E5=B1=80=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/ecommerce/product/index.vue | 307 ++++++++++-------- 1 file changed, 174 insertions(+), 133 deletions(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue index 22c74c0a..06d6f590 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/index.vue @@ -9,18 +9,9 @@ import 'vue-waterfall-plugin-next/dist/style.css'; import { Page } from '@vben/common-ui'; import { createIconifyIcon } from '@vben/icons'; -import { - Button, - Card, - Empty, - Flex, - Form, - Input, - message, - Space, - Spin, -} from 'ant-design-vue'; +import { Button, Card, Empty, message, Spin } from 'ant-design-vue'; +import { useVbenForm } from '#/adapter/form'; import { deleteProductApi, getProductPageApi } from '#/api/ecommerce/product'; import ProductCard from './components/ProductCard.vue'; @@ -39,6 +30,98 @@ const searchForm = ref({ specName: '', }); +const searchFormSubmitRef = ref Promise)>(null); + +const [SearchForm, formApi] = useVbenForm({ + commonConfig: { + componentProps: { + class: 'w-full', + }, + }, + handleReset: handleSearchFormReset, + handleSubmit: handleSearchFormSubmit, + layout: 'horizontal', + schema: [ + { + component: 'Input', + componentProps: { + placeholder: '请输入商品名称(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'name', + label: '商品名称', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入商品编码(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'productCode', + label: '商品编码', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入规格编码(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'specCode', + label: '规格编码', + }, + { + component: 'Input', + componentProps: { + placeholder: '请输入规格名称(回车搜索)', + allowClear: true, + onPressEnter: () => void searchFormSubmitRef.value?.(), + }, + defaultValue: '', + fieldName: 'specName', + label: '规格名称', + }, + ], + showCollapseButton: false, + showDefaultActions: true, + submitButtonOptions: { + content: '搜索', + }, + resetButtonOptions: { + content: '重置', + }, + submitOnEnter: true, + wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', +}); + +searchFormSubmitRef.value = () => formApi.validateAndSubmitForm(); + +async function handleSearchFormSubmit(values: Record) { + searchForm.value = { + name: String(values.name ?? '').trim(), + productCode: String(values.productCode ?? '').trim(), + specCode: String(values.specCode ?? '').trim(), + specName: String(values.specName ?? '').trim(), + }; + runSearch(); +} + +async function handleSearchFormReset() { + await formApi.resetForm(); + searchForm.value = { + name: '', + productCode: '', + specCode: '', + specName: '', + }; + runSearch(); +} + const loading = ref(false); const productList = ref([]); const total = ref(0); @@ -87,22 +170,12 @@ const loadProductList = async (reset = false) => { } }; -const handleSearch = () => { +function runSearch() { current.value = 1; productList.value = []; hasMore.value = true; loadProductList(true); -}; - -const handleReset = () => { - searchForm.value = { - name: '', - productCode: '', - specCode: '', - specName: '', - }; - handleSearch(); -}; +} const handleScroll = () => { const container = scrollContainerRef.value; @@ -170,130 +243,98 @@ onUnmounted(() => {