From b1ccdb760b9c16200831a2617caf9318b1be86b3 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期四, 27 六月 2024 08:11:09 +0800
Subject: [PATCH] 重构用户管理

---
 HTML/js/public.js |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/HTML/js/public.js b/HTML/js/public.js
index a15a788..4f657ef 100644
--- a/HTML/js/public.js
+++ b/HTML/js/public.js
@@ -55,13 +55,12 @@
     success: function (res, status, xhr) {
       // console.log(res);
       // console.log(status);
-
       callbackFun(res);
     },
     error: function (res, status, error) {  
       // console.log(res);
       // console.log(status);
-      callbackFun(res, status, error);
+      callbackFun(res.responseJSON, status, error);
       // layer.msg(res.statusText, {
       //   icon: 2,
       //   time: 2000 //2绉掑叧闂紙濡傛灉涓嶉厤缃紝榛樿鏄�3绉掞級
@@ -282,4 +281,55 @@
       });
     });
   }  
+}
+//娣辨嫹璐�
+function deepClone(source) {
+  if (typeof source !== 'object' || source == null) {
+    return source;
+  }
+  const target = Array.isArray(source) ? [] : {};
+  for (const key in source) {
+    if (Object.prototype.hasOwnProperty.call(source, key)) {
+      if (typeof source[key] === 'object' && source[key] !== null) {
+        target[key] = deepClone(source[key]);
+      } else {
+        target[key] = source[key];
+      }
+    }
+  }
+  return target;
+} 
+/**
+ * 灏嗚〃鍗曡祴鍊间负鎸囧畾鐨勫璞�
+ * @param {Object} data - 鍖呭惈琛ㄥ崟鏁版嵁鐨勫璞�
+ * @param {String} formSelector - 琛ㄥ崟鐨勯�夋嫨鍣紝渚嬪 '#myForm' 鎴� '.myForm'
+ */
+function setFormData(data, formSelector) {
+  var $form = $(formSelector);
+
+  $.each(data, function(key, value) {
+      var $field = $form.find('[name=' + key + ']');
+
+      if ($field.length > 0) {
+          var fieldType = $field.attr('type');
+
+          switch (fieldType) {
+              case 'checkbox':
+                  if (Array.isArray(value)) {
+                      $field.each(function() {
+                          $(this).prop('checked', value.includes($(this).val()));
+                      });
+                  } else {
+                      $field.prop('checked', value);
+                  }
+                  break;
+              case 'radio':
+                  $field.filter('[value=' + value + ']').prop('checked', true);
+                  break;
+              default:
+                  $field.val(value);
+                  break;
+          }
+      }
+  });
 }
\ No newline at end of file

--
Gitblit v1.8.0