Skip to content

MentionItem 提及项

MentionItem 用于配置编辑器里的提及能力,比如 @用户#话题 或业务对象选择。你可以通过 mentionItemAttr 把候选列表、过滤逻辑、选择回调与点击回调传给 PowerEditor

在下面的编辑器里输入 @,就能看到这组候选项直接挂在 power-editor 上的效果。

在下面的编辑器里输入 @ ,然后选择一个 mention 项。

Props

属性类型必填默认值说明
valuestring-当前输入值。
placeholderstringWrite something...输入占位文案。
mentionListarray | function[]候选项列表,或返回候选项列表的函数。
filterFuncfunction-自定义候选项过滤函数。
chooseItemCallbackfunction-选择候选项后触发。
mentionClickCallbackfunction-点击已插入的提及项时触发。
headerForegroundstring | functionrgba(0, 120, 212, 1)弹层头部前景色。
showPopperbooleanfalse是否显示候选弹层。
theme'light' | 'dark'light主题。

在 PowerEditor 中配置

mentionListfilterFuncchooseItemCallbackmentionClickCallbackheaderForeground 通常在初始化 PowerEditor 时通过 mentionItemAttr 传入。

vue
<script setup>
const mentionItemAttr = {
    mentionList: () => [
        { key: 0, name: "Mention Color", type: "header" },
        {
            key: 1,
            name: "Blue",
            color: "rgba(0, 120, 212, 1)",
            icon: "WindowsLogo",
            iconColor: "rgba(0, 153, 204, 1)",
        },
        {
            key: 2,
            name: "Purple",
            color: "#958DF1",
            icon: "DelveAnalyticsLogo",
            iconColor: "#958DF1",
        },
        { key: 3, name: "Mention Text", type: "header" },
        { key: 9, name: "", type: "divider" },
        { key: 5, name: "Text1" },
        { key: 6, name: "Text2" },
    ],
    filterFunc: (listItem, value) => {
        if (listItem.type === "header" || listItem.type === "divider") {
            return true;
        }

        return listItem.name.toLowerCase().includes(value.toLowerCase());
    },
    chooseItemCallback: (chooseItem, value) => {
        console.log("chooseItemCallback", chooseItem, value);
    },
    mentionClickCallback: (chooseItem, value) => {
        console.log("mentionClickCallback", chooseItem, value);
    },
    headerForeground: () => "#0078d4",
};
</script>

<template>
    <power-editor :mention-item-attr="mentionItemAttr" />
</template>

回调建议

filterFunc 只负责筛选候选项,尽量保持同步和轻量。需要远程搜索时,建议在 mentionList 中处理数据请求或提前缓存候选数据。

chooseItemCallback 适合记录选择行为、补充业务字段或触发联动;mentionClickCallback 更适合查看详情、打开卡片或跳转到业务对象页面。

MIT Licensed