Merge branch 'main' into pages

This commit is contained in:
xiaoxian521
2025-11-13 10:10:47 +08:00
2 changed files with 37 additions and 1 deletions

View File

@@ -4,6 +4,13 @@ import { type MessageHandler, ElMessage } from "element-plus";
type messageStyle = "el" | "antd"; type messageStyle = "el" | "antd";
type messageTypes = "info" | "success" | "warning" | "error"; type messageTypes = "info" | "success" | "warning" | "error";
type messagePlacement =
| "top"
| "top-left"
| "top-right"
| "bottom"
| "bottom-left"
| "bottom-right";
interface MessageParams { interface MessageParams {
/** 消息类型,可选 `info` 、`success` 、`warning` 、`error` ,默认 `info` */ /** 消息类型,可选 `info` 、`success` 、`warning` 、`error` ,默认 `info` */
@@ -20,8 +27,10 @@ interface MessageParams {
duration?: number; duration?: number;
/** 是否显示关闭按钮,默认值 `false` */ /** 是否显示关闭按钮,默认值 `false` */
showClose?: boolean; showClose?: boolean;
/** `Message` 距离窗口顶部的偏移量,默认 `16` */ /** `Message` 消息距离窗口边缘的偏移量,默认 `16` */
offset?: number; offset?: number;
/** `Message` 消息放置位置,默认 `top` */
placement?: messagePlacement;
/** 设置组件的根元素,默认 `document.body` */ /** 设置组件的根元素,默认 `document.body` */
appendTo?: string | HTMLElement; appendTo?: string | HTMLElement;
/** 合并内容相同的消息,不支持 `VNode` 类型的消息,默认值 `false` */ /** 合并内容相同的消息,不支持 `VNode` 类型的消息,默认值 `false` */
@@ -56,6 +65,7 @@ const message = (
duration = 2000, duration = 2000,
showClose = false, showClose = false,
offset = 16, offset = 16,
placement = "top",
appendTo = document.body, appendTo = document.body,
grouping = false, grouping = false,
repeatNum = 1, repeatNum = 1,
@@ -71,6 +81,7 @@ const message = (
duration, duration,
showClose, showClose,
offset, offset,
placement,
appendTo, appendTo,
grouping, grouping,
repeatNum, repeatNum,

View File

@@ -199,6 +199,31 @@ defineOptions({
<el-divider /> <el-divider />
<h4 class="mb-4!">
控制消息出现的位置消息可以显示在窗口的顶部(默认) 或其他位置
</h4>
<el-space wrap>
<el-button @click="message('顶部中间')"> 顶部中间 </el-button>
<el-button @click="message('顶部左侧', { placement: 'top-left' })">
顶部左侧
</el-button>
<el-button @click="message('顶部右侧', { placement: 'top-right' })">
顶部右侧
</el-button>
<el-button @click="message('底部中间', { placement: 'bottom' })">
底部中间
</el-button>
<el-button @click="message('底部左侧', { placement: 'bottom-left' })">
底部左侧
</el-button>
<el-button @click="message('底部右侧', { placement: 'bottom-right' })">
底部右侧
</el-button>
</el-space>
<el-divider />
<el-button @click="closeAllMessage"> 关闭所有消息提示 </el-button> <el-button @click="closeAllMessage"> 关闭所有消息提示 </el-button>
</el-card> </el-card>
</template> </template>