From 6877c9caa25162e570a3e2a99a5b2ce3ef88368b Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期一, 13 四月 2026 13:48:37 +0800
Subject: [PATCH] #页面优化

---
 rsf-design/src/views/system/dict-type/modules/dict-type-dialog.vue |   63 +++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/rsf-design/src/views/system/dict-type/modules/dict-type-dialog.vue b/rsf-design/src/views/system/dict-type/modules/dict-type-dialog.vue
index 178ddc0..04e46cb 100644
--- a/rsf-design/src/views/system/dict-type/modules/dict-type-dialog.vue
+++ b/rsf-design/src/views/system/dict-type/modules/dict-type-dialog.vue
@@ -2,9 +2,11 @@
   <ElDialog
     :title="dialogTitle"
     :model-value="visible"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
     width="820px"
     align-center
-    @update:model-value="handleCancel"
+    @update:model-value="handleVisibleUpdate"
     @closed="handleClosed"
   >
     <ArtForm
@@ -29,6 +31,7 @@
 </template>
 
 <script setup>
+  import { ElMessageBox } from 'element-plus'
   import { useI18n } from 'vue-i18n'
   import ArtForm from '@/components/core/forms/art-form/index.vue'
   import { buildDictTypeDialogModel, createDictTypeFormState } from '../dictTypePage.helpers'
@@ -41,15 +44,20 @@
   const emit = defineEmits(['update:visible', 'submit'])
   const formRef = ref()
   const form = reactive(createDictTypeFormState())
+  const initialSnapshot = ref(createComparableSnapshot())
   const { t } = useI18n()
 
   const isEdit = computed(() => Boolean(form.id))
   const dialogTitle = computed(() =>
-    isEdit.value ? t('pages.system.dictType.dialog.titleEdit') : t('pages.system.dictType.dialog.titleCreate')
+    isEdit.value
+      ? t('pages.system.dictType.dialog.titleEdit')
+      : t('pages.system.dictType.dialog.titleCreate')
   )
 
   const rules = computed(() => ({
-    code: [{ required: true, message: t('pages.system.dictType.validation.code'), trigger: 'blur' }],
+    code: [
+      { required: true, message: t('pages.system.dictType.validation.code'), trigger: 'blur' }
+    ],
     name: [{ required: true, message: t('pages.system.dictType.validation.name'), trigger: 'blur' }]
   }))
 
@@ -110,11 +118,14 @@
 
   function resetForm() {
     Object.assign(form, createDictTypeFormState())
+    initialSnapshot.value = createComparableSnapshot()
     formRef.value?.clearValidate?.()
   }
 
   function loadFormData() {
-    Object.assign(form, buildDictTypeDialogModel(props.dictTypeData))
+    const nextForm = buildDictTypeDialogModel(props.dictTypeData)
+    Object.assign(form, nextForm)
+    initialSnapshot.value = createComparableSnapshot(nextForm)
   }
 
   async function handleSubmit() {
@@ -127,8 +138,23 @@
     }
   }
 
-  function handleCancel() {
+  function closeDialog() {
     emit('update:visible', false)
+  }
+
+  async function handleCancel() {
+    if (!(await confirmDiscardIfDirty())) {
+      return
+    }
+    closeDialog()
+  }
+
+  function handleVisibleUpdate(nextVisible) {
+    if (!nextVisible) {
+      handleCancel()
+      return
+    }
+    emit('update:visible', true)
   }
 
   function handleClosed() {
@@ -155,4 +181,31 @@
     },
     { deep: true }
   )
+
+  function createComparableSnapshot(source = form) {
+    return JSON.stringify({
+      ...createDictTypeFormState(),
+      ...source
+    })
+  }
+
+  function isDirty() {
+    return createComparableSnapshot() !== initialSnapshot.value
+  }
+
+  async function confirmDiscardIfDirty() {
+    if (!isDirty()) {
+      return true
+    }
+    try {
+      await ElMessageBox.confirm('褰撳墠鍐呭灏氭湭淇濆瓨锛岀‘瀹氳鍏抽棴鍚楋紵', '鏈繚瀛樻彁绀�', {
+        confirmButtonText: '鏀惧純淇敼',
+        cancelButtonText: '缁х画缂栬緫',
+        type: 'warning'
+      })
+      return true
+    } catch {
+      return false
+    }
+  }
 </script>

--
Gitblit v1.9.1