tianyunperfect 4 kuukautta sitten
vanhempi
commit
9f90a9adc5
1 muutettua tiedostoa jossa 24 lisäystä ja 20 poistoa
  1. 24 20
      simple-demo/content_all.html

+ 24 - 20
simple-demo/content_all.html

@@ -12,9 +12,11 @@
             margin-right: 20px; /* 调整间隔 */
             vertical-align: top;
         }
+
         .item a {
             margin-right: 10px; /* 链接和按钮之间的间隔 */
         }
+
         .delete-btn {
             font-size: 10px; /* 设置字体大小 */
             color: #f44336; /* 红色 */
@@ -24,6 +26,7 @@
             padding: 0;
             margin-left: 5px; /* 调整叉号与链接之间的间隔 */
         }
+
         .delete-btn:hover {
             color: #d32f2f; /* 悬停时颜色加深 */
         }
@@ -52,13 +55,15 @@
                     let version = data[i].version;
                     // share_id
                     let share_id = data[i].share_id;
-                    let url='';
+                    let url = '';
                     if (type === "mind-map") {
                         url = `https://map.tianyunperfect.cn/?id=${a}&share_id=${share_id}`;
-                    }else if(type === "excel"){
+                    } else if (type === "excel") {
                         url = `https://excel.tianyunperfect.cn/?id=${a}&share_id=${share_id}`;
-                    }else if (type === "html"){
+                    } else if (type === "html") {
                         url = `https://do.tianyunperfect.cn/?id=${a}&share_id=${share_id}`;
+                    } else {
+                        continue;
                     }
                     listHtml += `<div class="item">
                         <a href="${url}" target="_blank">${title}</a>
@@ -72,7 +77,7 @@
                     if (confirm(`确认要删除 "${title}" 吗?`)) { // 在确认框中包含标题
                         let id = $(this).data('id');
                         let version = $(this).data('version');
-                        deleteData(id, version);
+                        deleteData(id, version, $(this).closest('.item')); // 传递对应的DOM元素
                     }
                 });
             } else {
@@ -80,23 +85,22 @@
             }
         });
 
-        function deleteData(id, version) {
-            if (type === "mind-map") {
-                $.ajax({
-                    url: 'https://web_history.tianyunperfect.cn/content/deleteById?id=' + id + '&version=' + version,
-                    type: 'DELETE',
-                    success: function (result) {
-                        if (result.code === 200) {
-                            location.reload();
-                        } else {
-                            alert(result.message);
-                        }
-                    },
-                    error: function () {
-                        alert('删除失败');
+        function deleteData(id, version, element) {
+            $.ajax({
+                url: 'https://web_history.tianyunperfect.cn/content/deleteById?id=' + id + '&version=' + version,
+                type: 'DELETE',
+                success: function (result) {
+                    if (result.code === 200) {
+                        // 删除对应的DOM元素
+                        element.remove();
+                    } else {
+                        alert(result.message);
                     }
-                });
-            }
+                },
+                error: function () {
+                    alert('删除失败');
+                }
+            });
         }
     });
 </script>