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/user/modules/user-dialog.vue |   78 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/rsf-design/src/views/system/user/modules/user-dialog.vue b/rsf-design/src/views/system/user/modules/user-dialog.vue
index 72725a3..85a50be 100644
--- a/rsf-design/src/views/system/user/modules/user-dialog.vue
+++ b/rsf-design/src/views/system/user/modules/user-dialog.vue
@@ -2,7 +2,9 @@
   <ElDialog
     :title="dialogTitle"
     :model-value="visible"
-    @update:model-value="handleCancel"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    @update:model-value="handleVisibleUpdate"
     width="960px"
     align-center
     class="user-dialog"
@@ -31,6 +33,7 @@
 
 <script setup>
   import ArtForm from '@/components/core/forms/art-form/index.vue'
+  import { ElMessageBox } from 'element-plus'
   import { buildUserDialogModel, createUserFormState } from '../userPage.helpers'
 
   const props = defineProps({
@@ -44,6 +47,7 @@
   const emit = defineEmits(['update:visible', 'submit'])
   const formRef = ref()
   const form = reactive(createUserFormState())
+  const initialSnapshot = ref(createComparableSnapshot())
 
   const isEdit = computed(() => props.type === 'edit')
   const dialogTitle = computed(() => (isEdit.value ? '缂栬緫鐢ㄦ埛' : '鏂板鐢ㄦ埛'))
@@ -214,6 +218,27 @@
       }
     },
     {
+      label: '鍑虹敓鏃ユ湡',
+      key: 'birthday',
+      type: 'input',
+      props: {
+        placeholder: '璇疯緭鍏ュ嚭鐢熸棩鏈�',
+        clearable: true
+      }
+    },
+    {
+      label: '涓汉绠�浠�',
+      key: 'introduction',
+      type: 'input',
+      props: {
+        type: 'textarea',
+        rows: 3,
+        placeholder: '璇疯緭鍏ヤ釜浜虹畝浠�',
+        clearable: true
+      },
+      span: 24
+    },
+    {
       label: '鐘舵��',
       key: 'status',
       type: 'select',
@@ -242,11 +267,14 @@
 
   const resetForm = () => {
     Object.assign(form, createUserFormState())
+    initialSnapshot.value = createComparableSnapshot()
     formRef.value?.clearValidate?.()
   }
 
   const loadFormData = () => {
-    Object.assign(form, buildUserDialogModel(props.userData))
+    const nextForm = buildUserDialogModel(props.userData)
+    Object.assign(form, nextForm)
+    initialSnapshot.value = createComparableSnapshot(nextForm)
   }
 
   const handleSubmit = async () => {
@@ -259,8 +287,23 @@
     }
   }
 
-  const handleCancel = () => {
+  const closeDialog = () => {
     emit('update:visible', false)
+  }
+
+  const handleCancel = async () => {
+    if (!(await confirmDiscardIfDirty())) {
+      return
+    }
+    closeDialog()
+  }
+
+  const handleVisibleUpdate = (nextVisible) => {
+    if (!nextVisible) {
+      handleCancel()
+      return
+    }
+    emit('update:visible', true)
   }
 
   const handleClosed = () => {
@@ -298,4 +341,33 @@
       }
     }
   )
+
+  function createComparableSnapshot(source = form) {
+    return JSON.stringify({
+      ...createUserFormState(),
+      ...source,
+      roleIds: Array.isArray(source?.roleIds) ? [...source.roleIds] : [],
+      userRoleIds: Array.isArray(source?.userRoleIds) ? [...source.userRoleIds] : []
+    })
+  }
+
+  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