feat:【antd/ele】将文章的商品关联字段从手动输入 SPU 编号改为使用 SpuShowcase 组件选择商品

This commit is contained in:
puhui999
2026-01-13 12:13:22 +08:00
parent e2433fc531
commit 2426f891e7
4 changed files with 22 additions and 10 deletions

View File

@@ -96,14 +96,10 @@ export function useFormSchema(): VbenFormSchema[] {
defaultValue: true, defaultValue: true,
}, },
{ {
// TODO: @puhui999商品关联
fieldName: 'spuId', fieldName: 'spuId',
label: '商品关联', label: '商品关联',
component: 'Input', component: 'Input',
formItemClass: 'col-span-2', formItemClass: 'col-span-2',
componentProps: {
placeholder: '请输入商品 SPU 编号',
},
}, },
{ {
fieldName: 'sort', fieldName: 'sort',

View File

@@ -14,6 +14,7 @@ import {
updateArticle, updateArticle,
} from '#/api/mall/promotion/article'; } from '#/api/mall/promotion/article';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { SpuShowcase } from '#/views/mall/product/spu/components';
import { useFormSchema } from '../data'; import { useFormSchema } from '../data';
@@ -41,6 +42,10 @@ const [Form, formApi] = useVbenForm({
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
async onConfirm() { async onConfirm() {
// 同步商品选择到表单,确保验证时能获取到值
if (formData.value?.spuId) {
await formApi.setFieldValue('spuId', formData.value.spuId);
}
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();
if (!valid) { if (!valid) {
return; return;
@@ -82,6 +87,11 @@ const [Modal, modalApi] = useVbenModal({
<template> <template>
<Modal :title="getTitle" class="w-2/5"> <Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" /> <Form class="mx-4">
<!-- 自定义插槽商品选择 -->
<template #spuId>
<SpuShowcase v-model="formData!.spuId" :limit="1" />
</template>
</Form>
</Modal> </Modal>
</template> </template>

View File

@@ -92,14 +92,10 @@ export function useFormSchema(): VbenFormSchema[] {
defaultValue: true, defaultValue: true,
}, },
{ {
// TODO: @puhui999商品关联
fieldName: 'spuId', fieldName: 'spuId',
label: '商品关联', label: '商品关联',
component: 'Input', component: 'Input',
formItemClass: 'col-span-2', formItemClass: 'col-span-2',
componentProps: {
placeholder: '请输入商品 SPU 编号',
},
}, },
{ {
fieldName: 'sort', fieldName: 'sort',

View File

@@ -14,6 +14,7 @@ import {
updateArticle, updateArticle,
} from '#/api/mall/promotion/article'; } from '#/api/mall/promotion/article';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { SpuShowcase } from '#/views/mall/product/spu/components';
import { useFormSchema } from '../data'; import { useFormSchema } from '../data';
@@ -41,6 +42,10 @@ const [Form, formApi] = useVbenForm({
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
async onConfirm() { async onConfirm() {
// 同步商品选择到表单,确保验证时能获取到值
if (formData.value?.spuId) {
await formApi.setFieldValue('spuId', formData.value.spuId);
}
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();
if (!valid) { if (!valid) {
return; return;
@@ -82,6 +87,11 @@ const [Modal, modalApi] = useVbenModal({
<template> <template>
<Modal :title="getTitle" class="w-2/5"> <Modal :title="getTitle" class="w-2/5">
<Form class="mx-4" /> <Form class="mx-4">
<!-- 自定义插槽商品选择 -->
<template #spuId>
<SpuShowcase v-model="formData!.spuId" :limit="1" />
</template>
</Form>
</Modal> </Modal>
</template> </template>