更新记录
1.3.2(2026-08-26) 下载此版本
修复更多面板选单交互:
- 面板内行高/字间距/段前距/段后距选单不再收起更多面板(上版 togglePopover 误伤),面板保持展开供连续选择
- 四个选单改为锚点定位:出现在各自按钮正下方(原挂在面板底部右对齐,位置错乱)
- 移除废弃的 is-in-more 定位样式
平台兼容性
uni-app(5.24)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | √ | - | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
wc-editor 望潮富文本编辑器
基于 uni-app 官方 editor 组件 + editorContext API 封装的富文本编辑组件(easycom 自动注册)。双排工具栏 + 可收起的更多面板,只实现官方文档声明支持的能力。
官方文档:
- 组件:https://uniapp.dcloud.net.cn/component/editor.html
- API:https://uniapp.dcloud.net.cn/api/media/editor-context.html
数据源为 HTML 字符串(服务端
content字段即 HTML,展示端rich-text直接渲染)。 平台支持:mp-weixin(基础库 2.7.0+)/ H5 2.4.5+ / App-vue 2.0+。
依赖
wc-upload(图片上传默认适配器:选图 → OSS 直传 → 公网 URL)
工具栏图标为内联 SVG 图标集(Lucide 线性风格,24×24 / 2px 圆头描边),由 commons/icons.ts 生成 data URL,无字体文件、无第三方图标库依赖。
快速使用
<template>
<wc-editor
ref="editorRef"
v-model="content"
placeholder="请输入活动详情"
:min-height="500"
@ready="onReady"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const content = ref('')
const editorRef = ref()
// v-model 之外也可主动读取
async function save() {
const html = await editorRef.value?.getHTML()
}
</script>
v-model 绑定 HTML 字符串;编辑器内部对 change 事件做了 200ms 节流。
editorContext 获取方式(官方推荐)
uni.createSelectorQuery().in(this).select('#editor').context((res) => {
this.editorCtx = res.context
}).exec()
组件内部即按此方式获取(勿用 wx.createEditorContext / uni.createEditorContext,均非官方跨端方式)。
功能清单(与官方 format 白名单一一对应)
| 功能 | 底层调用 |
|---|---|
| 加粗 / 斜体 / 删除线 / 下划线 / 插入线 | format('bold' / 'italic' / 'strike' / 'underline' / 'ins') |
| 标题 1-6 / 正文 | format('header', 1~6 \| null) |
| 字号 12-32px | format('fontSize', 'Npx') |
| 文字颜色 / 背景色 | format('color' / 'backgroundColor', hex) |
| 左/中/右/两端对齐 | format('align', ...) |
| 无序 / 有序 / 待办列表 | format('list', 'bullet' / 'ordered' / 'check') |
| 上标 / 下标 | format('script', 'super' / 'sub') |
| 增加 / 减少缩进 | format('indent', '+1' / '-1') |
| 行高(1 / 1.5 / 2 / 2.5 / 3) | format('lineHeight', css值) |
| 字间距(0~0.3em) | format('letterSpacing', css值) |
| 段前距 / 段后距(10/20/30px) | format('marginTop' / 'marginBottom', css值) |
| 图片 | 适配器上传 → insertImage({ src, width: '100%' }) |
| 分割线 / 清除格式 / 撤销 / 重做 / 清空 | insertDivider / removeFormat / undo / redo / clear |
| 光标滚入可视区 | scrollIntoView()(键盘弹起遮挡光标时有用) |
待办列表为原生能力(list: check):正文中的 checkbox 可直接点击切换勾选状态。
官方不支持、组件未实现(依据官方 format 白名单与支持标签清单):
- 链接(link):
format支持的样式列表中没有link(<a>虽是编辑器支持的展示标签,但无法通过 format 命令创建) - 引用(blockquote)/ 代码块 / 表格:format 白名单与支持标签均无
- 视频 / 音频 / 文件直插:官方明确"不能直接插入",建议用图片占位 +
insertImage的data属性存元数据,预览时还原(V1.1 扩展方向)
Properties
| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
v-model |
string |
'' |
HTML 内容(prop 名 modelValue);外部变化会自动回显 |
placeholder |
string |
'请输入正文内容...' |
占位文案 |
readonly |
boolean |
false |
只读:隐藏工具栏,仅展示内容 |
min-height |
number |
400 |
编辑区最小高度(rpx) |
toolbar |
boolean |
true |
是否显示工具栏 |
toolbar-config |
Partial<WcEditorToolbarConfig> |
见下 | 工具栏功能开关(局部覆盖) |
color-options |
string[] |
预设 9 色 | 文字颜色色板 |
bg-color-options |
string[] |
预设 6 色(含"无") | 背景颜色色板(空串 = 无) |
upload-image |
() => Promise<string> |
wc-upload | 图片上传适配器,返回图片 URL |
show-img-size |
boolean |
false |
点击图片显示大小控件(官方同名属性透传) |
show-img-toolbar |
boolean |
false |
点击图片显示工具栏控件(官方同名属性透传) |
show-img-resize |
boolean |
false |
点击图片显示修改尺寸控件(官方同名属性透传) |
toolbarConfig 默认值
{
undo: true, redo: true, image: true,
bold: true, italic: true, list: true, align: true,
more: {
todo: true, divider: true, strike: true, underline: true,
ins: true, sub: true, super: true, indent: true,
lineHeight: true, letterSpacing: true, paragraphMargin: true, clearFormat: true,
},
}
Events
| 事件 | 载荷 | 说明 |
|---|---|---|
ready |
- | 编辑器初始化完成(context 已就绪) |
change |
{ html, text, delta } |
内容变化(200ms 节流;delta 为官方 Quill 原生格式) |
focus / blur |
原生事件 | 焦点变化 |
statuschange |
Record<string, unknown> |
选区格式状态(bold/header/align...) |
uploadstart |
{ type: 'image', taskId } |
图片开始上传 |
uploadsuccess |
{ type: 'image', url } |
图片上传成功 |
uploaderror |
{ type: 'image', error } |
图片上传失败(组件内已弹重试框) |
Methods(ref 调用)
| 方法 | 返回 | 说明 |
|---|---|---|
getHTML() |
Promise<string> |
获取 HTML 内容 |
getText() |
Promise<string> |
获取纯文本 |
getDelta() |
Promise<unknown> |
获取官方 Quill delta 内容 |
setValue(html) |
- | 回显内容 |
clear() |
- | 清空 |
blur() |
- | 失焦并收起键盘 |
scrollIntoView() |
- | 光标处滚动到可视区域 |
undo() / redo() |
- | 撤销 / 重做 |
insertText(text) |
- | 光标处插入文本 |
insertImage(src, options?) |
- | 光标处插入图片(默认 width 100%;options:alt 替代文本 / data 自定义元数据 / width) |
execCommand(name, value?) |
- | 统一命令入口(与内部工具栏同一路由) |
getSelectionText() |
Promise<string> |
当前选中文本 |
execCommand 支持的 name:undo redo bold italic underline strike ins script header fontSize color backgroundColor align list indent lineHeight letterSpacing marginTop marginBottom insertDivider insertText insertImage(字符串或 {src, alt, data, width} 对象)removeFormat scrollIntoView。
已知边界(官方行为)
- 图片先上传后插入:上传中显示遮罩,成功后插入远端 URL;插入统一
width: '100%'通栏。 - 导出 html 的渲染样式:在其它环境(如
rich-text)渲染编辑器导出的 html 时,官方说明需自行维护<ql-container><ql-editor>结构样式。 - 粘贴为纯文本:官方行为,粘贴仅保留文字。
- 插入非法标签会被清理:
setContents的 html 含不支持标签时会被编辑器规范化(div→p等)。
目录结构
wc-editor/
├── components/wc-editor/wc-editor.vue # easycom 组件
├── commons/config.ts # 默认色板 / 字号 / 段落 / 工具栏配置
├── package.json
├── readme.md
└── changelog.md

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 4
赞赏 0
下载 12533070
赞赏 1945
赞赏
京公网安备:11010802035340号