فهرست منبع

Fixed node form bugs created in last updated.

Fixed table with model blade form submit bug
BrettonYe 1 سال پیش
والد
کامیت
9142845521
3فایلهای تغییر یافته به همراه32 افزوده شده و 17 حذف شده
  1. 3 3
      app/Observers/NodeObserver.php
  2. 27 12
      resources/views/admin/node/info.blade.php
  3. 2 2
      resources/views/admin/table_layouts.blade.php

+ 3 - 3
app/Observers/NodeObserver.php

@@ -22,7 +22,7 @@ class NodeObserver
             Log::error('节点生成-自动生成授权时出现错误,请稍后自行生成授权!');
         }
 
-        if ($node->is_ddns === '0' && $node->server && sysConfig('ddns_mode')) {
+        if (! $node->is_ddns && $node->server && sysConfig('ddns_mode')) {
             $newDNS = new DDNS($node->server);
             if ($node->ip) {
                 foreach ($node->ips() as $ip) {
@@ -39,7 +39,7 @@ class NodeObserver
 
     public function updated(Node $node): void
     {
-        if ($node->is_ddns === '0' && sysConfig('ddns_mode')) {
+        if (! $node->is_ddns && sysConfig('ddns_mode')) {
             $changes = $node->getChanges();
             if (Arr::hasAny($changes, ['ip', 'ipv6', 'server'])) {
                 $newDNS = new DDNS($node->server);
@@ -78,7 +78,7 @@ class NodeObserver
             }
         }
 
-        if ($node->type === '4') {
+        if ((int) $node->type === 4) {
             reloadNode::dispatch($node);
         }
     }

+ 27 - 12
resources/views/admin/node/info.blade.php

@@ -535,17 +535,21 @@
                 ['level', 'rule_group_id', 'country_code', 'relay_node_id'].forEach(prop => $(`#${prop}`).selectpicker('val', nodeData[prop]));
 
                 $('#labels').selectpicker('val', labels.map(label => label.id));
-                $('#next_renewal_date').datepicker('update', details.next_renewal_date ?? null);
-                if (details.subscription_term) {
+                if (details?.next_renewal_date) {
+                    $('#next_renewal_date').datepicker('update', details.next_renewal_date);
+                }
+                if (details?.subscription_term) {
                     setSubscriptionTerm(details.subscription_term)
                 }
-                $('#renewal_cost').val(details.renewal_cost ?? null);
+                if (details?.renewal_cost) {
+                    $('#renewal_cost').val(details.renewal_cost);
+                }
 
                 if (relay_node_id) {
                     $('#relay_port').val(port);
                 } else {
                     const typeHandlers = {
-                        0: () => $('#method').selectpicker('val', profile.method ?? null),
+                        0: () => $('#method').selectpicker('val', profile?.method || null),
                         1: setSSRValues,
                         2: setV2RayValues,
                         3: () => $('#trojan_port').val(port),
@@ -557,8 +561,8 @@
                 }
 
                 function setSSRValues() {
-                    ['protocol', 'obfs'].forEach(prop => $(`#${prop}`).selectpicker('val', profile[prop] ?? null));
-                    ['protocol_param', 'obfs_param'].forEach(prop => $(`#${prop}`).val(profile[prop] ?? null));
+                    ['protocol', 'obfs'].forEach(prop => $(`#${prop}`).selectpicker('val', profile[prop] || null));
+                    ['protocol_param', 'obfs_param'].forEach(prop => $(`#${prop}`).val(profile[prop] || null));
                     if (profile.passwd && port) {
                         $('#single').click();
                         $('#passwd').val(profile.passwd);
@@ -566,9 +570,9 @@
                 }
 
                 function setV2RayValues() {
-                    ['v2_alter_id', 'v2_host', 'v2_sni', 'v2_path'].forEach(prop => $(`#${prop}`).val(profile[prop] ?? null));
-                    ['v2_net', 'v2_type'].forEach(prop => $(`#${prop}`).selectpicker('val', profile[prop] ?? null));
-                    $('#v2_method').selectpicker('val', profile['method'] ?? null);
+                    ['v2_alter_id', 'v2_host', 'v2_sni', 'v2_path'].forEach(prop => $(`#${prop}`).val(profile[prop] || null));
+                    ['v2_net', 'v2_type'].forEach(prop => $(`#${prop}`).selectpicker('val', profile[prop] || null));
+                    $('#v2_method').selectpicker('val', profile['method'] || null);
 
                     $('#v2_port').val(port);
                     profile.v2_tls && $('#v2_tls').click();
@@ -591,8 +595,15 @@
         });
 
         function formSubmit(event) {
+            event.preventDefault(); // 阻止表单的默认提交行为
             const $form = $(event.target); // 获取触发事件的表单
-            const data = Object.fromEntries($form.serializeArray().map(item => [item.name, item.value]));
+
+            // 获取所有非 hidden 的表单数据
+            const data = Object.fromEntries(
+                $form.find('input:not([hidden]), select, textarea')
+                .serializeArray()
+                .map(item => [item.name, item.value])
+            );
 
             // 拼接 subscription_term
             const termValue = $('#subscription_term_value').val();
@@ -713,7 +724,9 @@
             const $path = $('#v2_path');
             $type.show();
             $host.show();
-            $path.val('/' + string);
+            if (!$path.val()) {
+                $path.val('/' + string);
+            }
             switch (net) {
                 case 'ws':
                 case 'http':
@@ -725,7 +738,9 @@
                     break;
                 case 'quic':
                     $typeOption.attr('disabled', false);
-                    $path.val(string);
+                    if (!$path.val()) {
+                        $path.val(string);
+                    }
                     break;
                 case 'kcp':
                 case 'tcp':

+ 2 - 2
resources/views/admin/table_layouts.blade.php

@@ -14,7 +14,7 @@
             window.location.href = window.location.href.split('?')[0];
         }
 
-        $('form').on('submit', function() {
+        $('form:not(.modal-body form)').on('submit', function() {
             $(this).find('input:not([type="submit"]), select').filter(function() {
                 return this.value === "";
             }).prop('disabled', true);
@@ -24,7 +24,7 @@
             }, 0);
         });
 
-        $('select').on('change', function() {
+        $('select').not('.modal-body select').on('change', function() {
             $(this).closest('form').trigger('submit');
         });
     </script>