diff --git a/public/js/admin.js b/public/js/admin.js index 44040f5..073ad0c 100644 --- a/public/js/admin.js +++ b/public/js/admin.js @@ -22,6 +22,27 @@ } } + // 通用:表单提交后禁用按钮,避免运营重复点击造成重复请求 + // 用法:form 标记 data-action="disable-on-submit"。 + (function () { + var forms = document.querySelectorAll('form[data-action="disable-on-submit"]'); + if (!forms || forms.length === 0) { + return; + } + + forms.forEach(function (form) { + form.addEventListener('submit', function () { + try { + var btns = form.querySelectorAll('button, input[type="submit"]'); + btns.forEach(function (b) { + b.disabled = true; + // 尽量不改文案(避免影响断言/文案口径);只做禁用 + }); + } catch (e) {} + }); + }); + })(); + // 续费缺订阅治理:订单详情页“绑定订阅ID”输入框,小交互增强: // - 输入后按 Enter 直接提交 // - 自动聚焦,减少点击 diff --git a/resources/views/admin/site_subscriptions/index.blade.php b/resources/views/admin/site_subscriptions/index.blade.php index f6520d3..0576276 100644 --- a/resources/views/admin/site_subscriptions/index.blade.php +++ b/resources/views/admin/site_subscriptions/index.blade.php @@ -315,7 +315,7 @@ $attachBack = $back; } @endphp -
+ @csrf @if($attachBack !== '') diff --git a/tests/Feature/AdminSiteSubscriptionIndexAttachOrderIdShouldMarkBindFormDisableOnSubmitTest.php b/tests/Feature/AdminSiteSubscriptionIndexAttachOrderIdShouldMarkBindFormDisableOnSubmitTest.php new file mode 100644 index 0000000..dd29720 --- /dev/null +++ b/tests/Feature/AdminSiteSubscriptionIndexAttachOrderIdShouldMarkBindFormDisableOnSubmitTest.php @@ -0,0 +1,67 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_index_should_mark_bind_form_disable_on_submit(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'sub_index_disable_on_submit_plan', + 'name' => '订阅列表绑定按钮防重复提交测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + SiteSubscription::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'status' => 'active', + 'source' => 'manual', + 'subscription_no' => 'SS_DISABLE_ON_SUBMIT_0001', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'amount' => 10, + 'starts_at' => now()->subDays(1), + 'ends_at' => now()->addDays(10), + 'snapshot' => [], + 'meta' => [], + ]); + + $orderId = 12345; + + $res = $this->get('/admin/site-subscriptions?attach_order_id=' . $orderId . '&attach_back=%2Fadmin%2Fplatform-orders%2F1'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + $this->assertStringContainsString('data-action="disable-on-submit"', $html); + } +}