feat: mall diy

pull/152/head
xingyu4j 2025-06-20 14:53:18 +08:00
parent 6df938431e
commit 46527954d5
6 changed files with 714 additions and 44 deletions

View File

@ -0,0 +1,109 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
/** 表单配置 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'name',
label: '页面名称',
component: 'Input',
componentProps: {
placeholder: '请输入页面名称',
},
rules: 'required',
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
rows: 4,
},
},
{
fieldName: 'previewPicUrls',
component: 'ImageUpload',
label: '预览图',
componentProps: {
maxNumber: 10,
multiple: true,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '页面名称',
component: 'Input',
componentProps: {
placeholder: '请输入页面名称',
clearable: true,
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
placeholder: ['开始时间', '结束时间'],
clearable: true,
valueFormat: 'YYYY-MM-DD HH:mm:ss',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '编号',
minWidth: 80,
},
{
field: 'previewPicUrls',
title: '预览图',
minWidth: 120,
cellRender: {
name: 'CellImages',
},
},
{
field: 'name',
title: '页面名称',
minWidth: 150,
},
{
field: 'remark',
title: '备注',
minWidth: 200,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 200,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@ -1,29 +1,141 @@
<script lang="ts" setup>
import { DocAlert, Page } from '@vben/common-ui';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallDiyPageApi } from '#/api/mall/promotion/diy/page';
import { Button } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { deleteDiyPage, getDiyPagePage } from '#/api/mall/promotion/diy/page';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import DiyPageForm from './modules/form.vue';
defineOptions({ name: 'PromotionDiyPage' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: DiyPageForm,
destroyOnClose: true,
});
const { push } = useRouter();
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建DIY页面 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑DIY页面 */
function handleEdit(row: MallDiyPageApi.DiyPage) {
formModalApi.setData(row).open();
}
/** 装修页面 */
function handleDecorate(row: MallDiyPageApi.DiyPage) {
//
push({ name: 'DiyPageDecorate', params: { id: row.id } });
}
/** 删除DIY页面 */
async function handleDelete(row: MallDiyPageApi.DiyPage) {
await deleteDiyPage(row.id as number);
onRefresh();
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getDiyPagePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<MallDiyPageApi.DiyPage>,
});
</script>
<template>
<Page>
<DocAlert title="【营销】商城装修" url="https://doc.iocoder.cn/mall/diy/" />
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/diy/page/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/diy/page/index
代码pull request 贡献给我们
</Button>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【营销】商城装修"
url="https://doc.iocoder.cn/mall/diy/"
/>
</template>
<FormModal @success="onRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['装修页面']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['promotion:diy-page:create'],
onClick: handleCreate,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '装修',
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['promotion:diy-page:update'],
onClick: handleDecorate.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['promotion:diy-page:update'],
onClick: handleEdit.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link',
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['promotion:diy-page:delete'],
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,92 @@
<script lang="ts" setup>
import type { MallDiyPageApi } from '#/api/mall/promotion/diy/page';
import { computed, ref } from 'vue';
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import {
createDiyPage,
getDiyPage,
updateDiyPage,
} from '#/api/mall/promotion/diy/page';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<MallDiyPageApi.DiyPage>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['装修页面'])
: $t('ui.actionTitle.create', ['装修页面']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
labelWidth: 100,
},
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as MallDiyPageApi.DiyPage;
//
if (!data.previewPicUrls) {
data.previewPicUrls = [];
}
try {
await (formData.value?.id ? updateDiyPage(data) : createDiyPage(data));
//
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
//
const data = modalApi.getData<MallDiyPageApi.DiyPage>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getDiyPage(data.id as number);
// values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal class="w-2/5" :title="getTitle">
<Form />
</Modal>
</template>

View File

@ -0,0 +1,120 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { DICT_TYPE } from '#/utils/dict';
/** 表单配置 */
export function useFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'id',
component: 'Input',
dependencies: {
triggerFields: [''],
show: () => false,
},
},
{
fieldName: 'name',
label: '模板名称',
component: 'Input',
componentProps: {
placeholder: '请输入模板名称',
},
rules: 'required',
},
{
fieldName: 'remark',
label: '备注',
component: 'Textarea',
componentProps: {
placeholder: '请输入备注',
rows: 4,
},
},
{
fieldName: 'previewPicUrls',
component: 'ImageUpload',
label: '预览图',
componentProps: {
maxNumber: 10,
multiple: true,
},
},
];
}
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
fieldName: 'name',
label: '模板名称',
component: 'Input',
componentProps: {
placeholder: '请输入模板名称',
clearable: true,
},
},
{
fieldName: 'createTime',
label: '创建时间',
component: 'RangePicker',
componentProps: {
placeholder: ['开始时间', '结束时间'],
clearable: true,
valueFormat: 'YYYY-MM-DD HH:mm:ss',
},
},
];
}
/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '编号',
minWidth: 80,
},
{
field: 'previewPicUrls',
title: '预览图',
minWidth: 120,
cellRender: {
name: 'CellImages',
},
},
{
field: 'name',
title: '模板名称',
minWidth: 150,
},
{
field: 'used',
title: '是否使用',
width: 100,
cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
},
},
{
field: 'remark',
title: '备注',
minWidth: 200,
},
{
field: 'createTime',
title: '创建时间',
width: 180,
formatter: 'formatDateTime',
},
{
title: '操作',
width: 250,
fixed: 'right',
slots: { default: 'actions' },
},
];
}

View File

@ -1,29 +1,167 @@
<script lang="ts" setup>
import { DocAlert, Page } from '@vben/common-ui';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallDiyTemplateApi } from '#/api/mall/promotion/diy/template';
import { Button } from 'ant-design-vue';
import { useRouter } from 'vue-router';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteDiyTemplate,
getDiyTemplatePage,
useDiyTemplate,
} from '#/api/mall/promotion/diy/template';
import { $t } from '#/locales';
import { useGridColumns, useGridFormSchema } from './data';
import DiyTemplateForm from './modules/form.vue';
defineOptions({ name: 'PromotionDiyTemplate' });
const [FormModal, formModalApi] = useVbenModal({
connectedComponent: DiyTemplateForm,
destroyOnClose: true,
});
const router = useRouter();
/** 刷新表格 */
function onRefresh() {
gridApi.query();
}
/** 创建DIY模板 */
function handleCreate() {
formModalApi.setData(null).open();
}
/** 编辑DIY模板 */
function handleEdit(row: MallDiyTemplateApi.DiyTemplate) {
formModalApi.setData(row).open();
}
/** 装修模板 */
function handleDecorate(row: MallDiyTemplateApi.DiyTemplate) {
//
router.push({ name: 'DiyTemplateDecorate', params: { id: row.id } });
}
/** 使用模板 */
async function handleUse(row: MallDiyTemplateApi.DiyTemplate) {
confirm({
content: `是否使用模板"${row.name}"?`,
}).then(async () => {
//
await useDiyTemplate(row.id as number);
message.success('使用成功');
onRefresh();
});
}
/** 删除DIY模板 */
async function handleDelete(row: MallDiyTemplateApi.DiyTemplate) {
await deleteDiyTemplate(row.id as number);
onRefresh();
}
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
},
gridOptions: {
columns: useGridColumns(),
height: 'auto',
keepSource: true,
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
return await getDiyTemplatePage({
pageNo: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
isHover: true,
},
toolbarConfig: {
refresh: { code: 'query' },
search: true,
},
} as VxeTableGridOptions<MallDiyTemplateApi.DiyTemplate>,
});
</script>
<template>
<Page>
<DocAlert title="【营销】商城装修" url="https://doc.iocoder.cn/mall/diy/" />
<Button
danger
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3"
>
该功能支持 Vue3 + element-plus 版本
</Button>
<br />
<Button
type="link"
target="_blank"
href="https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/diy/template/index"
>
可参考
https://github.com/yudaocode/yudao-ui-admin-vue3/blob/master/src/views/mall/promotion/diy/template/index
代码pull request 贡献给我们
</Button>
<Page auto-content-height>
<template #doc>
<DocAlert
title="【营销】商城装修"
url="https://doc.iocoder.cn/mall/diy/"
/>
</template>
<FormModal @success="onRefresh" />
<Grid table-title="">
<template #toolbar-tools>
<TableAction
:actions="[
{
label: $t('ui.actionTitle.create', ['装修模板']),
type: 'primary',
icon: ACTION_ICON.ADD,
auth: ['promotion:diy-template:create'],
onClick: handleCreate,
},
]"
/>
</template>
<template #actions="{ row }">
<TableAction
:actions="[
{
label: '装修',
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['promotion:diy-template:update'],
onClick: handleDecorate.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
icon: ACTION_ICON.EDIT,
auth: ['promotion:diy-template:update'],
onClick: handleEdit.bind(null, row),
},
{
label: '使用',
type: 'link' as const,
auth: ['promotion:diy-template:use'],
ifShow: !row.used,
onClick: handleUse.bind(null, row),
},
{
label: $t('common.delete'),
type: 'link' as const,
danger: true,
icon: ACTION_ICON.DELETE,
auth: ['promotion:diy-template:delete'],
ifShow: !row.used,
popConfirm: {
title: $t('ui.actionMessage.deleteConfirm', [row.name]),
confirm: handleDelete.bind(null, row),
},
},
]"
/>
</template>
</Grid>
</Page>
</template>

View File

@ -0,0 +1,99 @@
<script lang="ts" setup>
import type { MallDiyTemplateApi } from '#/api/mall/promotion/diy/template';
import { computed, ref } from 'vue';
import { useVbenForm, useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import {
createDiyTemplate,
getDiyTemplate,
updateDiyTemplate,
} from '#/api/mall/promotion/diy/template';
import { $t } from '#/locales';
import { useFormSchema } from '../data';
/** 提交表单 */
const emit = defineEmits(['success']);
const formData = ref<MallDiyTemplateApi.DiyTemplate>();
const getTitle = computed(() => {
return formData.value?.id
? $t('ui.actionTitle.edit', ['装修模板'])
: $t('ui.actionTitle.create', ['装修模板']);
});
const [Form, formApi] = useVbenForm({
commonConfig: {
componentProps: {
class: 'w-full',
},
labelWidth: 100,
},
layout: 'horizontal',
schema: useFormSchema(),
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) {
return;
}
modalApi.lock();
//
const data = (await formApi.getValues()) as MallDiyTemplateApi.DiyTemplate;
//
if (!data.previewPicUrls) {
data.previewPicUrls = [];
}
if (data.used === undefined) {
data.used = false;
}
try {
await (formData.value?.id
? updateDiyTemplate(data)
: createDiyTemplate(data));
//
await modalApi.close();
emit('success');
message.success($t('ui.actionMessage.operationSuccess'));
} finally {
modalApi.unlock();
}
},
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
formData.value = undefined;
return;
}
//
const data = modalApi.getData<MallDiyTemplateApi.DiyTemplate>();
if (!data || !data.id) {
return;
}
modalApi.lock();
try {
formData.value = await getDiyTemplate(data.id as number);
// values
if (formData.value) {
await formApi.setValues(formData.value);
}
} finally {
modalApi.unlock();
}
},
});
</script>
<template>
<Modal class="w-2/5" :title="getTitle">
<Form />
</Modal>
</template>