refactor(js): 复制失败toast文案收敛为toastCopyFailed并更新护栏
This commit is contained in:
@@ -608,6 +608,19 @@
|
|||||||
return toastSuccess(msg);
|
return toastSuccess(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toastCopyFailed(label, detail) {
|
||||||
|
var l = String(label || '').trim();
|
||||||
|
var d = String(detail || '').trim();
|
||||||
|
var msg = '复制失败';
|
||||||
|
if (l) {
|
||||||
|
msg += '(' + l + ')';
|
||||||
|
}
|
||||||
|
if (d) {
|
||||||
|
msg += ':' + d;
|
||||||
|
}
|
||||||
|
return toastError(msg);
|
||||||
|
}
|
||||||
|
|
||||||
// 通用:按钮短暂反馈(已复制/复制失败)并自动恢复
|
// 通用:按钮短暂反馈(已复制/复制失败)并自动恢复
|
||||||
// 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。
|
// 说明:用于复制 run_id / 复制治理链接,避免两套口径漂移。
|
||||||
function tempButtonFeedback(btn, ok, origAttr) {
|
function tempButtonFeedback(btn, ok, origAttr) {
|
||||||
@@ -655,7 +668,7 @@
|
|||||||
toastCopied('run_id', runId);
|
toastCopied('run_id', runId);
|
||||||
}).catch(function(){
|
}).catch(function(){
|
||||||
markCopiedRunId(false);
|
markCopiedRunId(false);
|
||||||
if (toastError('复制失败,请手动复制 run_id:' + runId)) {
|
if (toastCopyFailed('run_id', '请手动复制:' + runId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try { window.alert('复制失败,请手动复制 run_id:' + runId); } catch (e) {}
|
try { window.alert('复制失败,请手动复制 run_id:' + runId); } catch (e) {}
|
||||||
@@ -696,7 +709,7 @@
|
|||||||
toastCopied(label + '链接', '');
|
toastCopied(label + '链接', '');
|
||||||
}).catch(function(){
|
}).catch(function(){
|
||||||
markCopied(btn, false);
|
markCopied(btn, false);
|
||||||
if (toastError('复制失败,请手动复制' + label + '链接')) {
|
if (toastCopyFailed(label + '链接', '请手动复制')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {}
|
try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ class AdminJsCopyFailuresShouldUseToastErrorFirstTest extends TestCase
|
|||||||
$this->assertIsString($js);
|
$this->assertIsString($js);
|
||||||
|
|
||||||
// 复制失败时应优先 toastError(alert 作为降级)
|
// 复制失败时应优先 toastError(alert 作为降级)
|
||||||
$this->assertStringContainsString("toastError('复制失败", $js);
|
// 允许通过 wrapper(toastCopyFailed)间接调用 toastError。
|
||||||
|
$this->assertTrue(
|
||||||
|
str_contains($js, "toastError('复制失败") || str_contains($js, 'toastCopyFailed('),
|
||||||
|
'copy failures should use toastError (directly or via toastCopyFailed wrapper)'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminJsToastCopyFailedHelperShouldExistTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_admin_js_should_include_toast_copy_failed_helper(): void
|
||||||
|
{
|
||||||
|
$js = file_get_contents(public_path('js/admin.js'));
|
||||||
|
$this->assertIsString($js);
|
||||||
|
|
||||||
|
$this->assertStringContainsString('function toastCopyFailed', $js);
|
||||||
|
$this->assertStringContainsString("msg = '复制失败'", $js);
|
||||||
|
$this->assertStringContainsString("return toastError(msg)", $js);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user