From 982c97ab82f3beb1b4febcf014562eda34b9fc05 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期二, 29 九月 2026 17:59:41 +0800
Subject: [PATCH] feat(ui): 江苏商贸品牌视觉与首页/登录页改版
---
src/views/wxcp/notice/modules/form.vue | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/src/views/wxcp/notice/modules/form.vue b/src/views/wxcp/notice/modules/form.vue
new file mode 100644
index 0000000..cd835ac
--- /dev/null
+++ b/src/views/wxcp/notice/modules/form.vue
@@ -0,0 +1,116 @@
+<script lang="ts" setup>
+import type { WxCpNoticeApi } from '#/api/wxcp/notice';
+
+import type { NoticeFormType } from '../data';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+import { Button, message } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+import {
+ createNotice,
+ getNotice,
+ updateNotice,
+} from '#/api/wxcp/notice';
+
+import { useNoticeFormSchema } from '../data';
+
+defineOptions({ name: 'WxCpNoticeForm' });
+
+const emit = defineEmits<{ success: [] }>();
+
+const formType = ref<NoticeFormType>('create');
+const id = ref<number>();
+const submitting = ref(false);
+
+const isEdit = computed(() => formType.value !== 'detail');
+const title = computed(() => {
+ if (formType.value === 'detail') return '鏌ョ湅閫氱煡';
+ if (id.value) return '缂栬緫閫氱煡';
+ return '鏂板缓閫氱煡';
+});
+
+const [Form, formApi] = useVbenForm({
+ commonConfig: {
+ componentProps: { class: 'w-full' },
+ formItemClass: 'col-span-1',
+ labelWidth: 90,
+ },
+ layout: 'horizontal',
+ schema: [],
+ showDefaultActions: false,
+ wrapperClass: 'grid-cols-1',
+});
+
+const [Modal, modalApi] = useVbenModal({
+ async onOpenChange(isOpen: boolean) {
+ if (!isOpen) {
+ id.value = undefined;
+ return;
+ }
+ const data = modalApi.getData<{ formType: NoticeFormType; id?: number }>();
+ formType.value = data.formType;
+ id.value = data.id;
+ formApi.setState({ schema: useNoticeFormSchema(formType.value) });
+ formApi.setDisabled(formType.value === 'detail');
+ if (data.id) {
+ modalApi.lock();
+ try {
+ const detail = await getNotice(data.id);
+ await formApi.setValues(detail as unknown as Record<string, unknown>);
+ } finally {
+ modalApi.unlock();
+ }
+ } else {
+ await formApi.resetForm();
+ }
+ },
+});
+
+async function handleSubmit() {
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ submitting.value = true;
+ try {
+ const data = (await formApi.getValues()) as WxCpNoticeApi.Notice;
+ if (id.value) {
+ await updateNotice({ ...data, id: id.value });
+ message.success('淇敼鎴愬姛');
+ } else {
+ await createNotice(data);
+ message.success('鍒涘缓鎴愬姛锛岃鍦ㄥ垪琛ㄤ腑鍙戝竷鍚庡啀鎺ㄩ��');
+ }
+ await modalApi.close();
+ emit('success');
+ } catch (error: unknown) {
+ message.error((error as Error)?.message || '鎻愪氦澶辫触');
+ } finally {
+ submitting.value = false;
+ }
+}
+</script>
+
+<template>
+ <Modal :title="title" class="w-3/5">
+ <Form class="mx-4" />
+
+ <template #footer>
+ <div class="flex justify-end gap-2">
+ <Button @click="modalApi.close()">鍙栨秷</Button>
+ <Button
+ v-if="isEdit"
+ type="primary"
+ :loading="submitting"
+ @click="handleSubmit"
+ >
+ 纭
+ </Button>
+ <Button v-else type="primary" @click="modalApi.close()">鍏抽棴</Button>
+ </div>
+ </template>
+ </Modal>
+</template>
--
Gitblit v1.9.3