review:【antd】【mall】商品发布相关

This commit is contained in:
YunaiV
2025-11-01 11:05:04 +08:00
parent f2c90ea7a4
commit 7f192823d7
11 changed files with 35 additions and 47 deletions

View File

@@ -18,6 +18,7 @@ export namespace MallRewardActivityApi {
export interface RewardActivity { export interface RewardActivity {
id?: number; // 活动编号 id?: number; // 活动编号
name?: string; // 活动名称 name?: string; // 活动名称
status?: number; // 活动状态
startTime?: Date; // 开始时间 startTime?: Date; // 开始时间
endTime?: Date; // 结束时间 endTime?: Date; // 结束时间
startAndEndTime?: Date[]; // 开始和结束时间(仅前端使用) startAndEndTime?: Date[]; // 开始和结束时间(仅前端使用)

View File

@@ -8,8 +8,6 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
import { fenToYuan } from '@vben/utils'; import { fenToYuan } from '@vben/utils';
import { message } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getSpu } from '#/api/mall/product/spu'; import { getSpu } from '#/api/mall/product/spu';
@@ -61,6 +59,7 @@ const gridColumns = computed<VxeGridProps['columns']>(() => [
}, },
]); ]);
// TODO @芋艿:要不要直接非 pager
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: { gridOptions: {
columns: gridColumns.value, columns: gridColumns.value,
@@ -76,17 +75,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
if (!spuId.value) { if (!spuId.value) {
return { items: [], total: 0 }; return { items: [], total: 0 };
} }
try { const spu = await getSpu(spuId.value);
const spu = await getSpu(spuId.value); return {
return { items: spu.skus || [],
items: spu.skus || [], total: spu.skus?.length || 0,
total: spu.skus?.length || 0, };
};
} catch (error) {
message.error('加载 SKU 数据失败');
console.error(error);
return { items: [], total: 0 };
}
}, },
}, },
}, },
@@ -113,12 +106,10 @@ const [Modal, modalApi] = useVbenModal({
spuId.value = undefined; spuId.value = undefined;
return; return;
} }
const data = modalApi.getData<SpuData>(); const data = modalApi.getData<SpuData>();
if (!data?.spuId) { if (!data?.spuId) {
return; return;
} }
spuId.value = data.spuId; spuId.value = data.spuId;
await gridApi.query(); await gridApi.query();
}, },

View File

@@ -28,17 +28,19 @@ const emit = defineEmits(['update:modelValue', 'change']);
const productSpus = ref<MallSpuApi.Spu[]>([]); const productSpus = ref<MallSpuApi.Spu[]>([]);
const spuTableSelectRef = ref<InstanceType<typeof SpuTableSelect>>(); const spuTableSelectRef = ref<InstanceType<typeof SpuTableSelect>>();
const isMultiple = computed(() => props.limit !== 1); // 是否为多选模式
/** 计算是否可以添加 */ /** 计算是否可以添加 */
const canAdd = computed(() => { const canAdd = computed(() => {
if (props.disabled) return false; if (props.disabled) {
if (!props.limit) return true; return false;
}
if (!props.limit) {
return true;
}
return productSpus.value.length < props.limit; return productSpus.value.length < props.limit;
}); });
/** 是否为多选模式 */
const isMultiple = computed(() => props.limit !== 1);
/** 监听 modelValue 变化,加载商品详情 */ /** 监听 modelValue 变化,加载商品详情 */
watch( watch(
() => props.modelValue, () => props.modelValue,

View File

@@ -26,6 +26,7 @@ const emit = defineEmits<{
change: [spu: MallSpuApi.Spu | MallSpuApi.Spu[]]; change: [spu: MallSpuApi.Spu | MallSpuApi.Spu[]];
}>(); }>();
// TODO @芋艿:要不要加类型;
const categoryList = ref<any[]>([]); const categoryList = ref<any[]>([]);
const categoryTreeList = ref<any[]>([]); const categoryTreeList = ref<any[]>([]);
@@ -71,13 +72,11 @@ const formSchema = computed<VbenFormSchema[]>(() => [
/** 表格列配置 */ /** 表格列配置 */
const gridColumns = computed<VxeGridProps['columns']>(() => { const gridColumns = computed<VxeGridProps['columns']>(() => {
const columns: VxeGridProps['columns'] = []; const columns: VxeGridProps['columns'] = [];
if (props.multiple) { if (props.multiple) {
columns.push({ type: 'checkbox', width: 55 }); columns.push({ type: 'checkbox', width: 55 });
} else { } else {
columns.push({ type: 'radio', width: 55 }); columns.push({ type: 'radio', width: 55 });
} }
columns.push( columns.push(
{ {
field: 'id', field: 'id',
@@ -109,7 +108,6 @@ const gridColumns = computed<VxeGridProps['columns']>(() => {
}, },
}, },
); );
return columns; return columns;
}); });
@@ -129,14 +127,15 @@ const [Grid, gridApi] = useVbenVxeGrid({
reserve: true, reserve: true,
} }
: undefined, : undefined,
radioConfig: !props.multiple radioConfig: props.multiple
? { ? undefined
: {
reserve: true, reserve: true,
} },
: undefined,
proxyConfig: { proxyConfig: {
ajax: { ajax: {
async query({ page }: any, formValues: any) { async query({ page }: any, formValues: any) {
// TODO @芋艿:怎么简化下。
const data = await getSpuPage({ const data = await getSpuPage({
pageNo: page.currentPage, pageNo: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
@@ -145,7 +144,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
categoryId: formValues.categoryId || undefined, categoryId: formValues.categoryId || undefined,
createTime: formValues.createTime || undefined, createTime: formValues.createTime || undefined,
}); });
return { return {
items: data.list || [], items: data.list || [],
total: data.total || 0, total: data.total || 0,
@@ -165,6 +163,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
/** 多选:处理选中变化 */ /** 多选:处理选中变化 */
// TODO @芋艿:要不要清理掉?
function handleCheckboxChange() { function handleCheckboxChange() {
// vxe-table 自动管理选中状态,无需手动处理 // vxe-table 自动管理选中状态,无需手动处理
} }
@@ -180,13 +179,16 @@ function handleRadioChange() {
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
destroyOnClose: true, destroyOnClose: true,
// TODO @芋艿:看看怎么简化
onConfirm: props.multiple onConfirm: props.multiple
? () => { ? () => {
const selectedRows = gridApi.grid.getCheckboxRecords() as MallSpuApi.Spu[]; const selectedRows =
gridApi.grid.getCheckboxRecords() as MallSpuApi.Spu[];
emit('change', selectedRows); emit('change', selectedRows);
modalApi.close(); modalApi.close();
} }
: undefined, : undefined,
// TODO @芋艿:看看怎么简化?
async onOpenChange(isOpen: boolean) { async onOpenChange(isOpen: boolean) {
if (!isOpen) { if (!isOpen) {
gridApi.grid.clearCheckboxRow(); gridApi.grid.clearCheckboxRow();

View File

@@ -102,6 +102,7 @@ export function useInfoFormSchema(): VbenFormSchema[] {
} }
/** 价格库存的表单 */ /** 价格库存的表单 */
// TODO @puhui999貌似太宽了。。。屏幕小的整个 table 展示补全哈~~
export function useSkuFormSchema( export function useSkuFormSchema(
propertyList: any[] = [], propertyList: any[] = [],
isDetail: boolean = false, isDetail: boolean = false,

View File

@@ -212,7 +212,9 @@ function build(
const result: MallSpuApi.Property[][] = []; const result: MallSpuApi.Property[][] = [];
const rest = build(propertyValuesList.slice(1)); const rest = build(propertyValuesList.slice(1));
const firstList = propertyValuesList[0]; const firstList = propertyValuesList[0];
if (!firstList) return []; if (!firstList) {
return [];
}
for (const element of firstList) { for (const element of firstList) {
for (const element_ of rest) { for (const element_ of rest) {
@@ -289,8 +291,6 @@ defineExpose({
<template> <template>
<div> <div>
<!-- 情况一添加/修改 --> <!-- 情况一添加/修改 -->
<!-- TODO @puhui999有可以通过 grid 来做么主要考虑这样不直接使用 vxe 标签抽象程度更高 -->
<!-- TODO 还是先这样吧 🤣🤣 -->
<VxeTable <VxeTable
v-if="!isDetail && !isActivityComponent" v-if="!isDetail && !isActivityComponent"
:data="isBatch ? skuList : formData?.skus || []" :data="isBatch ? skuList : formData?.skus || []"

View File

@@ -37,6 +37,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
ajax: { ajax: {
// TODO @芋艿:要不要 ele 和 antd 统一下;
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
const params: any = { const params: any = {
pageNo: page.currentPage, pageNo: page.currentPage,

View File

@@ -102,7 +102,6 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
/** 新增/修改的表单 */ /** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
// 隐藏 ID 字段
{ {
fieldName: 'id', fieldName: 'id',
component: 'Input', component: 'Input',
@@ -111,7 +110,6 @@ export function useFormSchema(): VbenFormSchema[] {
show: () => false, show: () => false,
}, },
}, },
// 活动名称
{ {
fieldName: 'name', fieldName: 'name',
label: '活动名称', label: '活动名称',
@@ -122,7 +120,6 @@ export function useFormSchema(): VbenFormSchema[] {
allowClear: true, allowClear: true,
}, },
}, },
// 活动时间
{ {
fieldName: 'startAndEndTime', fieldName: 'startAndEndTime',
label: '活动时间', label: '活动时间',
@@ -135,7 +132,6 @@ export function useFormSchema(): VbenFormSchema[] {
allowClear: true, allowClear: true,
}, },
}, },
// 条件类型
{ {
fieldName: 'conditionType', fieldName: 'conditionType',
label: '条件类型', label: '条件类型',
@@ -147,7 +143,6 @@ export function useFormSchema(): VbenFormSchema[] {
}, },
rules: z.number().default(PromotionConditionTypeEnum.PRICE.type), rules: z.number().default(PromotionConditionTypeEnum.PRICE.type),
}, },
// 活动范围
{ {
fieldName: 'productScope', fieldName: 'productScope',
label: '活动范围', label: '活动范围',
@@ -159,7 +154,6 @@ export function useFormSchema(): VbenFormSchema[] {
}, },
rules: z.number().default(PromotionProductScopeEnum.ALL.scope), rules: z.number().default(PromotionProductScopeEnum.ALL.scope),
}, },
// 备注
{ {
fieldName: 'remark', fieldName: 'remark',
label: '备注', label: '备注',
@@ -170,14 +164,12 @@ export function useFormSchema(): VbenFormSchema[] {
allowClear: true, allowClear: true,
}, },
}, },
// 优惠规则(自定义组件插槽)
{ {
fieldName: 'rules', fieldName: 'rules',
label: '优惠设置', label: '优惠设置',
component: 'Input', component: 'Input',
formItemClass: 'items-start', formItemClass: 'items-start',
}, },
// 商品范围选择(自定义组件插槽)
{ {
fieldName: 'productSpuIds', fieldName: 'productSpuIds',
label: '选择商品', label: '选择商品',

View File

@@ -3,6 +3,7 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity'; import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
import { CommonStatusEnum } from '@vben/constants';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
@@ -41,6 +42,7 @@ function handleEdit(row: MallRewardActivityApi.RewardActivity) {
/** 关闭满减送活动 */ /** 关闭满减送活动 */
async function handleClose(row: MallRewardActivityApi.RewardActivity) { async function handleClose(row: MallRewardActivityApi.RewardActivity) {
// TODO @puhui999这个国际化需要加下哈closing、closeSuccess
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.closing', [row.name]), content: $t('ui.actionMessage.closing', [row.name]),
duration: 0, duration: 0,
@@ -104,7 +106,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
<Page auto-content-height> <Page auto-content-height>
<FormModal @success="handleRefresh" /> <FormModal @success="handleRefresh" />
<Grid table-title="满减送活动"> <Grid table-title="满减送活动">
<!-- 工具栏按钮 -->
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[
@@ -118,8 +119,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
]" ]"
/> />
</template> </template>
<!-- 行操作按钮 -->
<template #actions="{ row }"> <template #actions="{ row }">
<TableAction <TableAction
:actions="[ :actions="[
@@ -136,7 +135,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
danger: true, danger: true,
icon: ACTION_ICON.CLOSE, icon: ACTION_ICON.CLOSE,
auth: ['promotion:reward-activity:close'], auth: ['promotion:reward-activity:close'],
ifShow: row.status === 0, ifShow: row.status === CommonStatusEnum.ENABLE,
popConfirm: { popConfirm: {
title: '确认关闭该满减送活动吗?', title: '确认关闭该满减送活动吗?',
confirm: handleClose.bind(null, row), confirm: handleClose.bind(null, row),

View File

@@ -1,5 +1,4 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { VbenFormProps } from '#/adapter/form';
import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity'; import type { MallRewardActivityApi } from '#/api/mall/promotion/reward/rewardActivity';
import { computed, nextTick, ref } from 'vue'; import { computed, nextTick, ref } from 'vue';
@@ -45,7 +44,7 @@ const [Form, formApi] = useVbenForm({
class: 'w-full', class: 'w-full',
}, },
labelWidth: 100, labelWidth: 100,
} as VbenFormProps['commonConfig'], },
layout: 'horizontal', layout: 'horizontal',
schema: useFormSchema(), schema: useFormSchema(),
showDefaultActions: false, showDefaultActions: false,
@@ -53,6 +52,7 @@ const [Form, formApi] = useVbenForm({
const rewardRuleRef = ref<InstanceType<typeof RewardRule>>(); const rewardRuleRef = ref<InstanceType<typeof RewardRule>>();
// TODO @芋艿:这里需要在简化下;
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
async onConfirm() { async onConfirm() {
const { valid } = await formApi.validate(); const { valid } = await formApi.validate();

View File

@@ -35,7 +35,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
/** 新增/编辑的表单 */ /** 新增/编辑的表单 */
export function useFormSchema(): VbenFormSchema[] { export function useFormSchema(): VbenFormSchema[] {
return [ return [
// 隐藏的 ID 字段
{ {
component: 'Input', component: 'Input',
fieldName: 'id', fieldName: 'id',