refactor(js): 提炼toast通用函数并保留toastSuccess封装
This commit is contained in:
@@ -546,7 +546,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function toastSuccess(text) {
|
function toast(type, text, ttlMs) {
|
||||||
try {
|
try {
|
||||||
var container = qs('[data-role="toast-container"]');
|
var container = qs('[data-role="toast-container"]');
|
||||||
if (!container) {
|
if (!container) {
|
||||||
@@ -554,7 +554,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var t = document.createElement('div');
|
var t = document.createElement('div');
|
||||||
t.className = 'toast toast-success';
|
t.className = 'toast toast-' + String(type || 'info');
|
||||||
t.setAttribute('role', 'status');
|
t.setAttribute('role', 'status');
|
||||||
|
|
||||||
var c = document.createElement('div');
|
var c = document.createElement('div');
|
||||||
@@ -564,11 +564,16 @@
|
|||||||
t.appendChild(c);
|
t.appendChild(c);
|
||||||
container.appendChild(t);
|
container.appendChild(t);
|
||||||
|
|
||||||
|
var ttl = Number(ttlMs || 2500);
|
||||||
|
if (!isFinite(ttl) || ttl <= 0) {
|
||||||
|
ttl = 2500;
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
try {
|
try {
|
||||||
container.removeChild(t);
|
container.removeChild(t);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}, 2500);
|
}, ttl);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -576,6 +581,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toastSuccess(text) {
|
||||||
|
return toast('success', text, 2500);
|
||||||
|
}
|
||||||
|
|
||||||
// 通用:按钮短暂反馈(已复制/复制失败)并自动恢复
|
// 通用:按钮短暂反馈(已复制/复制失败)并自动恢复
|
||||||
// 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。
|
// 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。
|
||||||
function tempButtonFeedback(btn, ok, origAttr) {
|
function tempButtonFeedback(btn, ok, origAttr) {
|
||||||
|
|||||||
20
tests/Feature/AdminJsToastHelperShouldExistTest.php
Normal file
20
tests/Feature/AdminJsToastHelperShouldExistTest.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminJsToastHelperShouldExistTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_admin_js_should_include_toast_helper_and_toast_success_wrapper(): void
|
||||||
|
{
|
||||||
|
$js = file_get_contents(public_path('js/admin.js'));
|
||||||
|
|
||||||
|
$this->assertIsString($js);
|
||||||
|
$this->assertStringContainsString('function toast(', $js);
|
||||||
|
$this->assertStringContainsString("toast('success'", $js);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user