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/archive/category/modules/form.vue |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/src/views/archive/category/modules/form.vue b/src/views/archive/category/modules/form.vue
new file mode 100644
index 0000000..a9142c9
--- /dev/null
+++ b/src/views/archive/category/modules/form.vue
@@ -0,0 +1,98 @@
+<script lang="ts" setup>
+import type { ArchiveCategoryApi } from '#/api/archive/category';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { message } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+import {
+  createCategory,
+  getCategory,
+  updateCategory,
+} from '#/api/archive/category';
+import { $t } from '#/locales';
+
+import { useFormSchema } from '../data';
+
+defineOptions({ name: 'ArchiveCategoryForm' });
+
+const emit = defineEmits(['success']);
+
+const formData = ref<ArchiveCategoryApi.Category>();
+
+const getTitle = computed(() => {
+  if (formData.value?.id) {
+    return $t('ui.actionTitle.edit', ['妗f鍒嗙被']);
+  }
+  return formData.value?.parentId
+    ? '鏂板涓嬬骇鍒嗙被'
+    : $t('ui.actionTitle.create', ['妗f鍒嗙被']);
+});
+
+const [Form, formApi] = useVbenForm({
+  commonConfig: {
+    componentProps: {
+      class: 'w-full',
+    },
+    formItemClass: 'col-span-2',
+    labelWidth: 90,
+  },
+  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 ArchiveCategoryApi.Category;
+    try {
+      await (formData.value?.id
+        ? updateCategory({ ...data, id: formData.value.id })
+        : createCategory(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;
+    }
+    let data = modalApi.getData<ArchiveCategoryApi.Category>();
+    // 鏂板锛堥《绾� / 涓嬬骇锛夋椂鍙甫 parentId 浣滀负榛樿鍊�
+    if (!data || !data.id) {
+      formData.value = data ?? undefined;
+      await formApi.resetForm();
+      if (data?.parentId !== undefined) {
+        await formApi.setValues({ parentId: data.parentId });
+      }
+      return;
+    }
+    modalApi.lock();
+    try {
+      data = await getCategory(data.id);
+      formData.value = data;
+      await formApi.setValues(data);
+    } finally {
+      modalApi.unlock();
+    }
+  },
+});
+</script>
+
+<template>
+  <Modal class="w-2/5" :title="getTitle">
+    <Form class="mx-4" />
+  </Modal>
+</template>

--
Gitblit v1.9.3