fix(web-admin): align product danger confirm layout with demo B.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-10-18 18:22:34 +08:00
1 parent d0b6320c0f
commit 5c791b00cb
4 files changed
+43 -15

No files matched your search

@@ -24,23 +24,26 @@ describe('buildProductConfirmOptions', () => {
title: '删除产品',
message: '确认删除该产品?删除后不可恢复。'
})
assert.equal(opts.title, '删除产品')
assert.equal(opts.title, '')
assert.equal(opts.allowHtml, true)
assert.equal(opts.className, 'mp-product-dialog mp-product-dialog--danger')
assert.equal(opts.confirmButtonText, '确认删除')
assert.equal(opts.confirmButtonColor, '#dc2626')
assert.match(String(opts.message), /mp-product-dialog__warn/)
assert.match(String(opts.message), /mp-product-dialog__title/)
assert.match(String(opts.message), /删除产品/)
assert.match(String(opts.message), /确认删除该产品?删除后不可恢复。/)
assert.doesNotMatch(String(opts.message), /<script/)
assert.equal(opts.theme, undefined)
})
it('escapes html in danger message body', () => {
it('escapes html in danger title and message body', () => {
const opts = buildProductConfirmOptions({
kind: 'danger',
title: '删除产品',
title: '删 <b>除</b>',
message: 'a <b>x</b> & "y"'
})
assert.match(String(opts.message), /删 &lt;b&gt;除&lt;\/b&gt;/)
assert.match(String(opts.message), /a &lt;b&gt;x&lt;\/b&gt; &amp; &quot;y&quot;/)
})
@@ -18,9 +18,11 @@ function escapeHtml(text: string): string {
.replace(/'/g, '&#39;')
}
function dangerMessageHtml(message: string): string {
/** 方案 B:图标在上、标题居中(对齐 Demo),故标题写入 message HTML,不走 Vant header */
function dangerMessageHtml(title: string, message: string): string {
return (
`<div class="mp-product-dialog__warn"><span class="mp-product-dialog__warn-icon">!</span></div>` +
`<div class="mp-product-dialog__title">${escapeHtml(title)}</div>` +
`<div class="mp-product-dialog__msg">${escapeHtml(message)}</div>`
)
}
@@ -28,8 +30,9 @@ function dangerMessageHtml(message: string): string {
export function buildProductConfirmOptions(input: BuildProductConfirmInput): DialogOptions {
const isDanger = input.kind === 'danger'
return {
title: input.title,
message: isDanger ? dangerMessageHtml(input.message) : input.message,
// 危险态用空 title,避免 Vant header 左对齐且排在图标上方
title: isDanger ? '' : input.title,
message: isDanger ? dangerMessageHtml(input.title, input.message) : input.message,
allowHtml: isDanger,
className: isDanger ? 'mp-product-dialog mp-product-dialog--danger' : 'mp-product-dialog',
confirmButtonText: input.confirmButtonText ?? (isDanger ? '确认删除' : '确认'),