Merge branch 'dev' of https://gitee.com/yudaocode/yudao-ui-admin-vben into dev
This commit is contained in:
@@ -234,7 +234,9 @@ async function handleSubmit() {
|
||||
// 校验表单
|
||||
if (!formRef.value) return;
|
||||
const valid = await formRef.value.validate();
|
||||
if (!valid) return;
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交请求
|
||||
submitLoading.value = true;
|
||||
|
||||
@@ -2,4 +2,4 @@ export { default as SpuAndSkuList } from './spu-and-sku-list.vue';
|
||||
export { default as SpuSkuSelect } from './spu-sku-select.vue';
|
||||
|
||||
export type * from './types';
|
||||
|
||||
// TODO @puhui999:这个要不要也放到 product/spu/components 下?相当于各种商品的 select 能力,统一由 spu 提供组件化能力!
|
||||
|
||||
@@ -15,14 +15,10 @@ import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { SkuList } from '#/views/mall/product/spu/form';
|
||||
|
||||
interface SpuAndSkuListProps {
|
||||
/** SPU 列表 */
|
||||
spuList: T[];
|
||||
/** 规则配置 */
|
||||
ruleConfig: RuleConfig[];
|
||||
/** SPU 属性列表 */
|
||||
spuPropertyList: SpuProperty<T>[];
|
||||
/** 是否可删除 */
|
||||
deletable?: boolean;
|
||||
spuList: T[]; // SPU 列表
|
||||
ruleConfig: RuleConfig[]; // 规则配置
|
||||
spuPropertyList: SpuProperty<T>[]; // SPU 属性列表
|
||||
deletable?: boolean; // 是否可删除
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<SpuAndSkuListProps>(), {
|
||||
@@ -33,13 +29,11 @@ const emit = defineEmits<{
|
||||
delete: [spuId: number];
|
||||
}>();
|
||||
|
||||
// 内部数据
|
||||
const spuData = ref<MallSpuApi.Spu[]>([]);
|
||||
const spuPropertyListData = ref<SpuProperty<T>[]>([]);
|
||||
const expandedRowKeys = ref<number[]>([]);
|
||||
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
||||
|
||||
// 列配置(动态计算)
|
||||
const columns = computed<VxeGridProps['columns']>(() => {
|
||||
const cols: VxeGridProps['columns'] = [
|
||||
{
|
||||
@@ -103,7 +97,6 @@ const columns = computed<VxeGridProps['columns']>(() => {
|
||||
return cols;
|
||||
});
|
||||
|
||||
// 初始化表格
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: columns.value,
|
||||
@@ -121,14 +114,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 删除 SPU
|
||||
*/
|
||||
/** 删除 SPU */
|
||||
async function handleDelete(row: MallSpuApi.Spu) {
|
||||
// TODO @puhui999:可以使用 TableAction 的 popConfirm 哈?
|
||||
await confirm({
|
||||
content: `是否删除商品编号为 ${row.id} 的数据?`,
|
||||
});
|
||||
|
||||
const index = spuData.value.findIndex((item) => item.id === row.id);
|
||||
if (index !== -1) {
|
||||
spuData.value.splice(index, 1);
|
||||
@@ -138,6 +129,7 @@ async function handleDelete(row: MallSpuApi.Spu) {
|
||||
|
||||
/**
|
||||
* 获取所有 SKU 活动配置
|
||||
*
|
||||
* @param extendedAttribute 在 SKU 上扩展的属性名称
|
||||
*/
|
||||
function getSkuConfigs(extendedAttribute: string) {
|
||||
@@ -157,32 +149,36 @@ function getSkuConfigs(extendedAttribute: string) {
|
||||
return configs;
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
getSkuConfigs,
|
||||
});
|
||||
|
||||
// 监听 spuList 变化
|
||||
/** 监听 spuList 变化 */
|
||||
watch(
|
||||
() => props.spuList,
|
||||
(data) => {
|
||||
if (!data) return;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
spuData.value = data as MallSpuApi.Spu[];
|
||||
// 更新表格列配置和数据
|
||||
gridApi.grid.reloadData(spuData.value);
|
||||
gridApi.grid.reloadColumn(columns.value);
|
||||
gridApi.grid.reloadColumn(columns.value as any[]);
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
// 监听 spuPropertyList 变化
|
||||
/** 监听 spuPropertyList 变化 */
|
||||
watch(
|
||||
() => props.spuPropertyList,
|
||||
(data) => {
|
||||
if (!data) return;
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
spuPropertyListData.value = data as SpuProperty<T>[];
|
||||
|
||||
// 延迟展开所有行,确保 SKU 列表正确渲染
|
||||
// TODO @puhui999:只能 setTimeout 么?await 之类可以么?
|
||||
setTimeout(() => {
|
||||
expandedRowKeys.value = data.map((item) => item.spuId);
|
||||
// 手动展开每一行
|
||||
@@ -222,7 +218,6 @@ watch(
|
||||
</SkuList>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template
|
||||
v-if="props.deletable && props.spuList.length > 1"
|
||||
|
||||
@@ -18,10 +18,8 @@ import { getRangePickerDefaultProps } from '#/utils';
|
||||
import { getPropertyList, SkuList } from '#/views/mall/product/spu/form';
|
||||
|
||||
interface SpuSkuSelectProps {
|
||||
/** 是否选择 SKU */
|
||||
isSelectSku?: boolean;
|
||||
/** 是否单选 SKU */
|
||||
radio?: boolean;
|
||||
isSelectSku?: boolean; // 是否选择 SKU
|
||||
radio?: boolean; // 是否单选 SKU
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<SpuSkuSelectProps>(), {
|
||||
@@ -33,33 +31,17 @@ const emit = defineEmits<{
|
||||
confirm: [spuId: number, skuIds?: number[]];
|
||||
}>();
|
||||
|
||||
// 单选:选中的 SPU ID
|
||||
const selectedSpuId = ref<number>();
|
||||
// 选中的 SKU ID 列表
|
||||
const selectedSkuIds = ref<number[]>([]);
|
||||
// SKU 列表数据
|
||||
const selectedSpuId = ref<number>(); // 单选:选中的 SPU ID
|
||||
const selectedSkuIds = ref<number[]>([]); // 选中的 SKU ID 列表
|
||||
const spuData = ref<MallSpuApi.Spu>();
|
||||
const propertyList = ref<any[]>([]);
|
||||
const isExpand = ref(false);
|
||||
const expandRowKeys = ref<number[]>([]);
|
||||
const skuListRef = ref<InstanceType<typeof SkuList>>();
|
||||
|
||||
// 分类列表(扁平)
|
||||
const categoryList = ref<any[]>([]);
|
||||
// 分类树
|
||||
const categoryTreeList = ref<any[]>([]);
|
||||
const categoryList = ref<any[]>([]); // 分类列表(扁平)
|
||||
const categoryTreeList = ref<any[]>([]); // 分类树
|
||||
|
||||
// 初始化分类数据
|
||||
onMounted(async () => {
|
||||
try {
|
||||
categoryList.value = await getCategoryList({});
|
||||
categoryTreeList.value = handleTree(categoryList.value, 'id', 'parentId');
|
||||
} catch (error) {
|
||||
console.error('加载分类数据失败:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// 搜索表单配置
|
||||
const formSchema = computed<VbenFormSchema[]>(() => {
|
||||
return [
|
||||
{
|
||||
@@ -100,10 +82,8 @@ const formSchema = computed<VbenFormSchema[]>(() => {
|
||||
];
|
||||
});
|
||||
|
||||
// 列配置
|
||||
const gridColumns = computed<VxeGridProps['columns']>(() => {
|
||||
const columns: VxeGridProps['columns'] = [];
|
||||
|
||||
// 如果需要选择 SKU,添加展开列
|
||||
if (props.isSelectSku) {
|
||||
columns.push({
|
||||
@@ -112,7 +92,6 @@ const gridColumns = computed<VxeGridProps['columns']>(() => {
|
||||
slots: { content: 'expand-content' },
|
||||
});
|
||||
}
|
||||
|
||||
// 单选列
|
||||
columns.push(
|
||||
{
|
||||
@@ -152,11 +131,9 @@ const gridColumns = computed<VxeGridProps['columns']>(() => {
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
return columns;
|
||||
});
|
||||
|
||||
// 初始化表格
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions: {
|
||||
schema: formSchema.value,
|
||||
@@ -175,6 +152,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
ajax: {
|
||||
async query({ page }: any, formValues: any) {
|
||||
try {
|
||||
// TODO @puhui999:1)try catch 可以去掉?;2)params 直接放到 getSpuPage 里哇?
|
||||
const params = {
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
@@ -200,23 +178,21 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
},
|
||||
});
|
||||
|
||||
// 单选:处理选中 SPU
|
||||
/** 单选:处理选中 SPU */
|
||||
async function handleSingleSelected(row: MallSpuApi.Spu) {
|
||||
selectedSpuId.value = row.id;
|
||||
|
||||
// 如果需要选择 SKU,展开行
|
||||
if (props.isSelectSku) {
|
||||
await expandChange(row, [row]);
|
||||
}
|
||||
}
|
||||
|
||||
// 选择 SKU
|
||||
/** 选择 SKU */
|
||||
function selectSku(skus: MallSpuApi.Sku[]) {
|
||||
if (!selectedSpuId.value) {
|
||||
message.warning('请先选择商品再选择相应的规格!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (skus.length === 0) {
|
||||
selectedSkuIds.value = [];
|
||||
return;
|
||||
@@ -226,7 +202,7 @@ function selectSku(skus: MallSpuApi.Sku[]) {
|
||||
: (selectedSkuIds.value = skus.map((sku) => sku.id!));
|
||||
}
|
||||
|
||||
// 展开行,加载 SKU 列表
|
||||
/** 展开行,加载 SKU 列表 */
|
||||
async function expandChange(
|
||||
row: MallSpuApi.Spu,
|
||||
expandedRows?: MallSpuApi.Spu[],
|
||||
@@ -237,7 +213,6 @@ async function expandChange(
|
||||
expandRowKeys.value = [selectedSpuId.value];
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果已经展开且是同一个 SPU,不重复加载
|
||||
if (isExpand.value && spuData.value?.id === row.id) {
|
||||
return;
|
||||
@@ -247,7 +222,6 @@ async function expandChange(
|
||||
spuData.value = undefined;
|
||||
propertyList.value = [];
|
||||
isExpand.value = false;
|
||||
|
||||
if (!expandedRows || expandedRows.length === 0) {
|
||||
expandRowKeys.value = [];
|
||||
return;
|
||||
@@ -261,13 +235,12 @@ async function expandChange(
|
||||
expandRowKeys.value = [row.id!];
|
||||
}
|
||||
|
||||
// 确认选择
|
||||
/** 确认选择 */
|
||||
function handleConfirm() {
|
||||
if (!selectedSpuId.value) {
|
||||
message.warning('没有选择任何商品');
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.isSelectSku && selectedSkuIds.value.length === 0) {
|
||||
message.warning('没有选择任何商品属性');
|
||||
return;
|
||||
@@ -279,12 +252,10 @@ function handleConfirm() {
|
||||
selectedSpuId.value,
|
||||
props.isSelectSku ? selectedSkuIds.value : undefined,
|
||||
);
|
||||
|
||||
// 关闭弹窗
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 初始化弹窗
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
onConfirm: handleConfirm,
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
@@ -307,6 +278,11 @@ defineExpose({
|
||||
open: modalApi.open,
|
||||
close: modalApi.close,
|
||||
});
|
||||
/** 初始化分类数据 */
|
||||
onMounted(async () => {
|
||||
categoryList.value = await getCategoryList({});
|
||||
categoryTreeList.value = handleTree(categoryList.value, 'id', 'parentId');
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -5,11 +5,7 @@ import type { PropertyAndValues } from '#/views/mall/product/spu/form';
|
||||
* 用于活动商品选择中,关联 SPU 和其属性列表
|
||||
*/
|
||||
export interface SpuProperty<T = any> {
|
||||
/** SPU ID */
|
||||
spuId: number;
|
||||
/** SPU 详情 */
|
||||
spuDetail: T;
|
||||
/** 属性列表 */
|
||||
propertyList: PropertyAndValues[];
|
||||
spuId: number; // SPU ID
|
||||
spuDetail: T; // SPU 详情
|
||||
propertyList: PropertyAndValues[]; // 属性列表
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
// 1. 导入类型
|
||||
import type { VbenFormSchema } from '#/adapter/form';
|
||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
|
||||
// 2. 导入 VBEN 常量和工具
|
||||
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
|
||||
import { getDictOptions } from '@vben/hooks';
|
||||
|
||||
// 3. 导入 Zod 用于高级验证
|
||||
import { z } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* @description: 列表的搜索表单
|
||||
*/
|
||||
// TODO @AI:注释
|
||||
export function useGridFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
{
|
||||
@@ -27,12 +22,9 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 列表的字段
|
||||
*/
|
||||
// TODO @AI:注释
|
||||
export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
{ type: 'checkbox', width: 40 },
|
||||
{
|
||||
field: 'id',
|
||||
title: '活动编号',
|
||||
@@ -77,20 +69,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
field: 'stock',
|
||||
title: '库存',
|
||||
minWidth: 80,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'totalStock',
|
||||
title: '总库存',
|
||||
minWidth: 80,
|
||||
align: 'center',
|
||||
},
|
||||
{
|
||||
field: 'redeemedQuantity',
|
||||
title: '已兑换数量',
|
||||
minWidth: 100,
|
||||
align: 'center',
|
||||
// 使用 formatter 计算已兑换数量
|
||||
|
||||
formatter: ({ row }) => {
|
||||
return (row.totalStock || 0) - (row.stock || 0);
|
||||
},
|
||||
@@ -99,7 +88,7 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
align: 'center',
|
||||
|
||||
formatter: 'formatDateTime',
|
||||
},
|
||||
{
|
||||
@@ -111,12 +100,9 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 新增/修改的表单
|
||||
*/
|
||||
// TODO @AI:注释下
|
||||
export function useFormSchema(): VbenFormSchema[] {
|
||||
return [
|
||||
// 隐藏的 ID 字段
|
||||
{
|
||||
component: 'Input',
|
||||
fieldName: 'id',
|
||||
@@ -131,7 +117,6 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
formItemClass: 'col-span-2',
|
||||
// 通过插槽实现自定义商品选择器
|
||||
renderComponentContent: () => ({
|
||||
default: () => null,
|
||||
}),
|
||||
|
||||
@@ -18,37 +18,42 @@ import Form from './modules/form.vue';
|
||||
|
||||
defineOptions({ name: 'PromotionPointActivity' });
|
||||
|
||||
// 1. 使用 useVbenModal 初始化弹窗
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
destroyOnClose: true,
|
||||
});
|
||||
|
||||
// 2. 定义业务操作函数
|
||||
// TODO @AI:增加注释
|
||||
function handleCreate() {
|
||||
formModalApi.setData(null).open();
|
||||
}
|
||||
|
||||
// TODO @AI:增加注释
|
||||
function handleEdit(row: any) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
// TODO @AI:增加注释
|
||||
async function handleClose(row: any) {
|
||||
await confirm({
|
||||
title: '提示',
|
||||
content: '确认关闭该积分商城活动吗?',
|
||||
});
|
||||
await closePointActivity(row.id);
|
||||
// TODO @AI:增加 loading
|
||||
message.success('关闭成功');
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
async function handleDelete(row: any) {
|
||||
await deletePointActivity(row.id);
|
||||
message.success($t('common.delSuccess'));
|
||||
message.success({
|
||||
content: $t('ui.actionMessage.deleteSuccess', [row.id]),
|
||||
});
|
||||
gridApi.query();
|
||||
}
|
||||
|
||||
// TODO @AI:增加注释
|
||||
function handleRefresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
@@ -80,18 +85,16 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- TODO @puhui999:不用 description 哈。 -->
|
||||
<Page
|
||||
description="积分商城活动,用于管理积分兑换商品的配置"
|
||||
doc-link="https://doc.iocoder.cn/mall/promotion-point/"
|
||||
title="积分商城活动"
|
||||
auto-content-height
|
||||
>
|
||||
<!-- 弹窗组件的注册 -->
|
||||
<FormModal @success="handleRefresh" />
|
||||
|
||||
<!-- 列表组件的渲染 -->
|
||||
<Grid table-title="积分商城活动列表">
|
||||
<!-- 工具栏按钮 -->
|
||||
<template #toolbar-tools>
|
||||
<TableAction
|
||||
:actions="[
|
||||
@@ -105,7 +108,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<!-- 操作列按钮 -->
|
||||
<template #actions="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
|
||||
@@ -33,7 +33,6 @@ const getTitle = computed(() =>
|
||||
isFormUpdate.value ? '编辑积分活动' : '新增积分活动',
|
||||
);
|
||||
|
||||
// 1. 使用 useVbenForm 初始化表单
|
||||
const [Form, formApi] = useVbenForm({
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
@@ -69,6 +68,7 @@ const spuPropertyList = ref<SpuProperty<any>[]>([]); // SPU 属性列表
|
||||
/**
|
||||
* 打开商品选择器
|
||||
*/
|
||||
// TODO @puhui999:spuSkuSelectRef.value.open is not a function
|
||||
function openSpuSelect() {
|
||||
spuSkuSelectRef.value.open();
|
||||
}
|
||||
@@ -140,9 +140,7 @@ async function getSpuDetails(
|
||||
|
||||
// ================= end =================
|
||||
|
||||
// 2. 使用 useVbenModal 定义弹窗行为
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
// "确认"按钮的回调
|
||||
async onConfirm() {
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
@@ -176,7 +174,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||
modalApi.unlock();
|
||||
}
|
||||
},
|
||||
// 弹窗打开时的回调
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
// 关闭时清理状态
|
||||
@@ -244,7 +241,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||
/>
|
||||
</template>
|
||||
</VxeColumn>
|
||||
|
||||
<VxeColumn align="center" min-width="168" title="可兑换次数">
|
||||
<template #default="{ row: sku }">
|
||||
<InputNumber
|
||||
@@ -254,7 +250,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||
/>
|
||||
</template>
|
||||
</VxeColumn>
|
||||
|
||||
<VxeColumn align="center" min-width="168" title="所需积分">
|
||||
<template #default="{ row: sku }">
|
||||
<InputNumber
|
||||
@@ -264,7 +259,6 @@ const [Modal, modalApi] = useVbenModal({
|
||||
/>
|
||||
</template>
|
||||
</VxeColumn>
|
||||
|
||||
<VxeColumn align="center" min-width="168" title="所需金额(元)">
|
||||
<template #default="{ row: sku }">
|
||||
<InputNumber
|
||||
|
||||
Reference in New Issue
Block a user