更新记录
0.1.0(2026-09-02)
新版本发布,后续增加ios版本
0.1.0(2026-09-02)
- 首次发布。
- 支持打开 TXT 文本和本地 TXT 文件。
- 支持多种翻页效果、阅读样式配置和章节/页面导航。
- 支持页面变化和加载错误事件。
平台兼容性
uni-app(5.0)
| Vue2 | Vue2插件版本 | Vue3 | Vue3插件版本 | Chrome | Safari | app-vue | app-nvue | app-nvue插件版本 | Android | Android插件版本 | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | 0.1.0 | √ | 0.1.0 | × | × | × | √ | 0.1.0 | 5.0 | 0.1.0 | × | × |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
yzj-read-view
基于 libreadview 0.0.5 的 Android TXT 原生阅读组件,支持覆盖、滑动、滚动和仿真翻页。
平台支持
| 平台 | 支持情况 |
|---|---|
| uni-app App-Android nvue | 支持,Android 5.0(API 21)及以上 |
| uni-app App-Android vue | 不支持 |
| App-iOS、Web、小程序 | 不支持 |
插件不申请存储权限。使用 openFile 时,请传入应用本身有权读取的本地文件路径。
基础示例
以下示例适用于 pages 目录下的 App-Android nvue 页面。
<template>
<view class="page">
<yzj-read-view
ref="reader"
class="reader"
effect="cover"
:title-text-size="18"
:content-text-size="16"
:title-text-color="0xff333333"
:content-text-color="0xff333333"
:header-and-footer-text-color="0xff888888"
:page-background-color="0xfffffdf8"
:page-padding="16"
:content-padding="0"
@pagechange="onPageChange"
@error="onError"
/>
<view class="actions">
<button @click="openText">打开文本</button>
<button @click="nextPage">下一页</button>
</view>
</view>
</template>
<script>
const BOOK_TEXT = `第一章 开始阅读
这里是需要显示的 TXT 文本内容。
第二章 更多内容
阅读器会根据组件尺寸自动分页。`
export default {
onReady() {
this.openText()
},
methods: {
openText() {
const reader = this.$refs.reader
if (reader != null) {
reader.openText(BOOK_TEXT)
}
},
openFile() {
const reader = this.$refs.reader
if (reader != null) {
reader.openFile('/storage/emulated/0/Download/book.txt', 'UTF-8', 1, 1)
}
},
nextPage() {
const reader = this.$refs.reader
if (reader != null) {
reader.nextPage()
}
},
onPageChange(payload) {
const progress = JSON.parse(payload)
console.log(`第 ${progress.chapterIndex} 章,第 ${progress.pageIndex} 页`)
},
onError(payload) {
const error = JSON.parse(payload)
console.error(error.code, error.message)
}
}
}
</script>
<style>
.reader {
width: 750px;
height: 900px;
}
.actions {
display: flex;
flex-direction: row;
}
</style>
openText 与 openFile 连续调用时,最后一次调用生效。
属性
属性变化后会自动同步到原生阅读视图。
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
effect |
string |
cover |
翻页效果,见效果参数 |
titleTextSize |
number |
18 |
标题文字大小,单位为 Android sp |
contentTextSize |
number |
16 |
正文文字大小,单位为 Android sp |
titleTextColor |
number |
0xff333333 |
标题 ARGB 颜色值,如 0xffff0000 |
contentTextColor |
number |
0xff333333 |
正文 ARGB 颜色值 |
headerAndFooterTextColor |
number |
0xff333333 |
页眉、页脚 ARGB 颜色值 |
pageBackgroundColor |
number |
0xffffffff |
阅读页 ARGB 背景颜色值 |
pagePadding |
number |
16 |
阅读页四周内边距,单位 px |
contentPadding |
number |
0 |
正文区域四周内边距,单位 px |
效果参数
effect 值 |
说明 |
|---|---|
none |
无动画翻页 |
cover |
覆盖翻页 |
slide |
左右滑动翻页 |
scroll |
上下滚动翻页 |
curl |
仿真翻页 |
ibook-curl |
iBook 仿真翻页 |
ibook-slide |
iBook 滑动翻页 |
传入其他值时自动使用 cover。
方法
| 方法 | 参数 | 返回值 | 说明 |
|---|---|---|---|
openText(text) |
text: string |
void |
打开字符串形式的 TXT 内容,按 UTF-8 解析;空字符串会触发 error |
openFile(path, encoding, chapterIndex, pageIndex) |
path: stringencoding: string = 'UTF-8'chapterIndex: number = 1pageIndex: number = 1 |
void |
打开本地 TXT 文件;章节和页码从 1 开始 |
updateEffect(effect) |
effect: string |
void |
更新翻页效果 |
updateTitleTextSize(size) |
size: number |
void |
更新标题字号 |
updateContentTextSize(size) |
size: number |
void |
更新正文字号 |
updateTitleTextColor(color) |
color: number |
void |
更新标题颜色 |
updateContentTextColor(color) |
color: number |
void |
更新正文颜色 |
updateHeaderAndFooterTextColor(color) |
color: number |
void |
更新页眉、页脚颜色 |
updatePageBackgroundColor(color) |
color: number |
void |
更新页面背景颜色 |
updatePagePadding(padding) |
padding: number |
void |
更新页面内边距 |
updateContentPadding(padding) |
padding: number |
void |
更新正文内边距 |
nextPage() |
无 | boolean |
跳转下一页;无法跳转时返回 false |
previousPage() |
无 | boolean |
跳转上一页;无法跳转时返回 false |
nextChapter() |
无 | boolean |
跳转下一章;无法跳转时返回 false |
previousChapter() |
无 | boolean |
跳转上一章;无法跳转时返回 false |
事件
原生事件参数是 JSON 字符串,使用前通过 JSON.parse 解析。
| 事件 | 数据 | 说明 |
|---|---|---|
pagechange |
chapterIndex: numberpageIndex: numberchapterPageCount: numberchapterCount: number |
当前页变化。章节与页码均从 1 开始 |
error |
code: numbermessage: string |
打开内容失败。1001 为无效文本、路径、编码或页码;1004 为加载失败 |
注意事项
- 组件必须设置明确的宽度和高度,否则原生阅读视图无法分页。
openFile支持普通绝对路径和file://URI,不支持content://URI。ibook-curl在 Android 5.0、5.1 上存在上游兼容性风险,不建议在 API 21、22 设备启用。- 当前版本只读取 TXT 文本,不提供 EPUB、书签、阅读进度持久化等能力。
- 同一页面可创建多个组件实例,各实例事件和资源相互隔离。

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 43
赞赏 0
下载 12555186
赞赏 1948
赞赏
京公网安备:11010802035340号