diff --git a/examples/sites/demos/apis/modal.js b/examples/sites/demos/apis/modal.js index 22b4567d48..af20897aff 100644 --- a/examples/sites/demos/apis/modal.js +++ b/examples/sites/demos/apis/modal.js @@ -379,10 +379,10 @@ export default { { name: 'top', type: 'number | string', - defaultValue: '80', + defaultValue: '80px', desc: { - 'zh-CN': "消息距离顶部的位置,仅当 type 为 'message' 时有效", - 'en-US': "The position of the message from the top, only valid when type is 'message'" + 'zh-CN': '模态框距离顶部的位置', + 'en-US': 'The position of the modal from the top' }, mode: ['pc', 'mobile-first'], pcDemo: 'message-top', diff --git a/examples/sites/demos/pc/app/modal/message-top.vue b/examples/sites/demos/pc/app/modal/message-top.vue index fb34dc3674..7d82d36ef9 100644 --- a/examples/sites/demos/pc/app/modal/message-top.vue +++ b/examples/sites/demos/pc/app/modal/message-top.vue @@ -1,7 +1,9 @@ @@ -14,7 +16,21 @@ export default { TinyButton: Button }, methods: { - btnClick() { + btnClick1() { + Modal.alert({ + status: 'info', + message: '提示弹窗距离顶部 300px', + top: 300 + }) + }, + btnClick2() { + Modal.confirm({ + status: 'info', + message: '确认弹窗距离顶部 50vh', + top: '50vh' + }) + }, + btnClick3() { Modal.message({ status: 'info', message: '自定义消息的内容距离顶部 500px', diff --git a/examples/sites/demos/pc/app/modal/webdoc/modal.js b/examples/sites/demos/pc/app/modal/webdoc/modal.js index c0e32d961c..7a618fcb3b 100644 --- a/examples/sites/demos/pc/app/modal/webdoc/modal.js +++ b/examples/sites/demos/pc/app/modal/webdoc/modal.js @@ -301,12 +301,12 @@ export default { { demoId: 'message-top', name: { - 'zh-CN': '消息距离顶部位置', + 'zh-CN': '模态框距离顶部位置', 'en-US': 'Position from top' }, desc: { - 'zh-CN': '通过top属性设置消息距离顶部的位置,单位为 px', - 'en-US': `Use the top property to set the distance from the top of the message in units of px. ` + 'zh-CN': '通过top属性设置模态框距离顶部的位置', + 'en-US': 'Use the top property to set the distance from the top of the modal.' }, codeFiles: ['message-top.vue'] }, diff --git a/packages/renderless/src/modal/index.ts b/packages/renderless/src/modal/index.ts index ff56aa19a3..7b00875ae2 100644 --- a/packages/renderless/src/modal/index.ts +++ b/packages/renderless/src/modal/index.ts @@ -61,9 +61,14 @@ export const computedBoxStyle = return {} } + let top = '' let width: string | number = '' let height: string | number = '' + if (props.type === 'alert' || props.type === 'confirm') { + top = typeof props.top === 'number' ? `${props.top}px` : props.top + } + if (props.width) { width = isNaN(props.width as number) ? props.width : `${props.width}px` } @@ -72,7 +77,7 @@ export const computedBoxStyle = height = isNaN(props.height as number) ? props.height : `${props.height}px` } - return { width, height } + return { top, width, height } } export const watchValue =