feat:【ele】【mall】diy/page 代码优化

pull/240/head
YunaiV 2025-10-25 19:51:04 +08:00
parent 6d3afd8ccf
commit 900671babd
3 changed files with 23 additions and 41 deletions

View File

@ -1,6 +1,8 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { getRangePickerDefaultProps } from '#/utils';
/** 表单配置 */
export function useFormSchema(): VbenFormSchema[] {
return [
@ -59,9 +61,8 @@ export function useGridFormSchema(): VbenFormSchema[] {
label: '创建时间',
component: 'RangePicker',
componentProps: {
placeholder: ['开始时间', '结束时间'],
clearable: true,
valueFormat: 'YYYY-MM-DD HH:mm:ss',
...getRangePickerDefaultProps(),
allowClear: true,
},
},
];

View File

@ -4,7 +4,7 @@ import type { MallDiyPageApi } from '#/api/mall/promotion/diy/page';
import { onMounted, ref, unref } from 'vue';
import { useRoute } from 'vue-router';
import { ElMessage } from 'element-plus';
import { ElLoading, ElMessage } from 'element-plus';
import * as DiyPageApi from '#/api/mall/promotion/diy/page';
import { DiyEditor, PAGE_LIBS } from '#/views/mall/promotion/components';
@ -12,63 +12,50 @@ import { DiyEditor, PAGE_LIBS } from '#/views/mall/promotion/components';
/** 装修页面表单 */
defineOptions({ name: 'DiyPageDecorate' });
const formLoading = ref(false); // 12
const formData = ref<MallDiyPageApi.DiyPage>();
const formRef = ref(); // Ref
const route = useRoute();
//
const formData = ref<MallDiyPageApi.DiyPage>();
/** 获取详情 */
async function getPageDetail(id: any) {
formLoading.value = true;
const loadingInstance = ElLoading.service({
text: '加载中...',
});
try {
formData.value = await DiyPageApi.getDiyPageProperty(id);
} finally {
formLoading.value = false;
loadingInstance.close();
}
}
//
/** 提交表单 */
async function submitForm() {
//
if (!formRef.value) return;
//
formLoading.value = true;
const loadingInstance = ElLoading.service({
text: '保存中...',
});
try {
await DiyPageApi.updateDiyPageProperty(unref(formData)!);
ElMessage.success('保存成功');
} finally {
formLoading.value = false;
loadingInstance.close();
}
}
//
function resetForm() {
formData.value = {
id: undefined,
templateId: undefined,
name: '',
remark: '',
previewPicUrls: [],
property: '',
} as MallDiyPageApi.DiyPage;
formRef.value?.resetFields();
}
/** 初始化 */
const route = useRoute();
onMounted(() => {
resetForm();
if (!route.params.id) {
ElMessage.warning('参数错误,页面编号不能为空!');
return;
}
formData.value = {} as MallDiyPageApi.DiyPage;
getPageDetail(route.params.id);
});
</script>
<template>
<DiyEditor
v-if="formData && !formLoading"
v-model="formData.property"
:title="formData.name"
v-if="formData?.id"
v-model="formData!.property"
:title="formData!.name"
:libs="PAGE_LIBS"
@save="submitForm"
/>

View File

@ -45,12 +45,6 @@ const [Modal, modalApi] = useVbenModal({
modalApi.lock();
//
const data = (await formApi.getValues()) as MallDiyPageApi.DiyPage;
//
if (!data.previewPicUrls) {
data.previewPicUrls = [];
}
try {
await (formData.value?.id ? updateDiyPage(data) : createDiyPage(data));
//
@ -84,7 +78,7 @@ const [Modal, modalApi] = useVbenModal({
</script>
<template>
<Modal class="w-2/5" :title="getTitle">
<Modal :title="getTitle" class="w-2/5">
<Form />
</Modal>
</template>