Hai Lin 2 недель назад
Родитель
Сommit
aac747ee68
2 измененных файлов с 34 добавлено и 4 удалено
  1. 1 1
      app.py
  2. 33 3
      templates/add_member.html

+ 1 - 1
app.py

@@ -999,7 +999,7 @@ def get_member(member_id):
     conn = get_db_connection()
     conn = get_db_connection()
     try:
     try:
         with conn.cursor() as cursor:
         with conn.cursor() as cursor:
-            cursor.execute("SELECT id, name, name_word_generation FROM family_member_info WHERE id = %s", (member_id,))
+            cursor.execute("SELECT id, name, name_word_generation, source_record_id FROM family_member_info WHERE id = %s", (member_id,))
             member = cursor.fetchone()
             member = cursor.fetchone()
             if not member:
             if not member:
                 return jsonify({"success": False, "message": "成员不存在"}), 404
                 return jsonify({"success": False, "message": "成员不存在"}), 404

+ 33 - 3
templates/add_member.html

@@ -576,6 +576,17 @@
         {% endfor %}
         {% endfor %}
     ];
     ];
     let currentIndex = 0;
     let currentIndex = 0;
+    
+    // 初始化时根据source_record_id设置正确的扫描件
+    {% if source_record_id %}
+    // 在模板渲染时直接设置currentIndex
+    currentIndex = images.findIndex(img => img.id == {{ source_record_id }});
+    // 如果找不到,保持为0
+    if (currentIndex === -1) {
+        currentIndex = 0;
+    }
+    {% endif %}
+    
     let currentParsedPeople = [];
     let currentParsedPeople = [];
     
     
     // Image State
     // Image State
@@ -599,6 +610,12 @@
     const magnifierSwitch = document.getElementById('magnifierSwitch');
     const magnifierSwitch = document.getElementById('magnifierSwitch');
     const imageWrapper = document.getElementById('imageWrapper');
     const imageWrapper = document.getElementById('imageWrapper');
     
     
+    // 页面加载完成后更新显示
+    document.addEventListener('DOMContentLoaded', function() {
+        // 调用updateDisplay函数显示正确的扫描件
+        updateDisplay();
+    });
+    
     // Initialize Dragging and Zooming
     // Initialize Dragging and Zooming
     if (imageWrapper) {
     if (imageWrapper) {
         // Center initial position
         // Center initial position
@@ -997,7 +1014,12 @@
             // Update the source_record_id hidden field in the form
             // Update the source_record_id hidden field in the form
             const sourceRecordIdField = document.querySelector('input[name="source_record_id"]');
             const sourceRecordIdField = document.querySelector('input[name="source_record_id"]');
             if (sourceRecordIdField) {
             if (sourceRecordIdField) {
-                sourceRecordIdField.value = img.id;
+                // If we're editing a member, keep the existing source_record_id
+                // Otherwise, use the current image's ID
+                const isEditMode = {{ 'true' if member else 'false' }};
+                if (!isEditMode) {
+                    sourceRecordIdField.value = img.id;
+                }
             }
             }
             
             
             // Reset image state on switch
             // Reset image state on switch
@@ -1429,13 +1451,21 @@
     const sourceOssUrl = "{{ source_oss_url if source_oss_url else '' }}";
     const sourceOssUrl = "{{ source_oss_url if source_oss_url else '' }}";
     const sourceRecordId = "{{ source_record_id if source_record_id else '' }}";
     const sourceRecordId = "{{ source_record_id if source_record_id else '' }}";
 
 
-    if (prefilledContent && sourceOssUrl) {
+    if (prefilledContent && (sourceOssUrl || sourceRecordId)) {
         // We have prefilled content from DB, simulate "Recognize Image" success
         // We have prefilled content from DB, simulate "Recognize Image" success
         document.addEventListener('DOMContentLoaded', async () => {
         document.addEventListener('DOMContentLoaded', async () => {
             // Wait a bit for UI to settle
             // Wait a bit for UI to settle
             setTimeout(async () => {
             setTimeout(async () => {
                 // Find image index
                 // Find image index
-                const imgIndex = images.findIndex(img => img.url === sourceOssUrl);
+                let imgIndex = -1;
+                if (sourceRecordId) {
+                    //优先根据sourceRecordId查找
+                    imgIndex = images.findIndex(img => img.id == sourceRecordId);
+                }
+                if (imgIndex === -1 && sourceOssUrl) {
+                    //如果根据sourceRecordId没找到,再根据sourceOssUrl查找
+                    imgIndex = images.findIndex(img => img.url === sourceOssUrl);
+                }
                 if (imgIndex !== -1) {
                 if (imgIndex !== -1) {
                     currentIndex = imgIndex;
                     currentIndex = imgIndex;
                     updateDisplay();
                     updateDisplay();