Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
bbb-leaferjs-mini-demo
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
曾哲
bbb-leaferjs-mini-demo
Commits
3e5fefd7
提交
3e5fefd7
authored
10月 28, 2025
作者:
Gorvey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: update docs
上级
0e354bfb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
196 行增加
和
11 行删除
+196
-11
README.md
README.md
+196
-11
没有找到文件。
README.md
浏览文件 @
3e5fefd7
#
leafjs-d
emo
#
Leafer.js 教学批注系统 D
emo
## Project setup
## 结构
```
src/
├── api/ # Mock 数据文件
│ ├── marklist.json # 标记区域数据
│ ├── pageinfo.json # 页面基础信息
│ ├── point.json # 笔画数据点
│ └── page-point.json # 页面笔画数据
├── pages/leafer/ # Leafer.js 相关组件
│ ├── index.vue # 主页面组件
│ ├── leafer.js # Leafer 核心逻辑
│ └── leafer-util.js # 工具函数
└── main.js # 应用入口
```
## Mock 数据说明
### 1. 页面信息 (pageinfo.json)
包含页面的基础信息:
```
json
{
"id"
:
"页面唯一标识"
,
"bookName"
:
"教材名称"
,
"pageID"
:
80261
,
"pageNumber"
:
1
,
"pageTotal"
:
14
,
"url"
:
"页面图片URL地址"
,
"markCount"
:
45
}
```
### 2. 标记区域数据 (marklist.json)
定义页面上的矩形标记区域,用于标注题目区域、答案区域等:
```
json
{
"id"
:
"标记唯一标识"
,
"top"
:
{
"x"
:
1831.49
,
"y"
:
365.62
},
//
左上角坐标
"bottom"
:
{
"x"
:
1968.24
,
"y"
:
396.70
},
//
右下角坐标
"questionID"
:
0
,
//
题目ID
"childQuestionID"
:
"ai-practice"
,
//
子题目类型
"pageID"
:
80261
,
//
页面ID
"createTime"
:
1751254686
//
创建时间戳
}
```
**常见标记类型:**
-
`ai-practice`
- AI 练习
-
`kp-analyze`
- 知识点分析
-
`q-dictation`
- 题目听写
-
`ai-grade`
- AI 评分
-
`q-analyze`
- 题目分析
-
`q-collect`
- 题目收藏
### 3. 笔画数据 (point.json / page-point.json)
存储手写笔画的轨迹数据,每个笔画包含一系列坐标点和笔画属性:
```
json
{
"pageId"
:
82412
,
"strokes"
:
"x1,y1,pressure1,isStart,isEnd,timestamp1;x2,y2,pressure2,isStart,isEnd,timestamp2;..."
,
"isSaved"
:
false
,
"isDraw"
:
false
}
```
**笔画数据格式说明:**
-
`x, y`
- 坐标位置
-
`pressure`
- 压感值 (0-1)
-
`isStart`
- 是否为笔画起点
-
`isEnd`
- 是否为笔画终点
-
`timestamp`
- 时间戳
## 使用示例
### 基本用法
```
vue
<
template
>
<div>
<div
class=
"leafer-container"
id=
"leafer-container"
></div>
</div>
</
template
>
<
script
>
import
{
createLeaferAnnotate
}
from
'./leafer'
import
pageinfo
from
'../../api/pageinfo.json'
import
markList
from
'../../api/marklist.json'
import
pagePoints
from
'../../api/page-point.json'
export
default
{
async
mounted
()
{
this
.
instance
=
await
createLeaferAnnotate
({
view
:
'leafer-container'
,
pageUrl
:
pageinfo
.
url
,
marks
:
markList
,
points
:
pagePoints
,
})
}
}
</
script
>
```
pnpm install
### 初始化 Leafer 实例
```
javascript
import
{
createLeaferAnnotate
}
from
'./leafer'
const
instance
=
await
createLeaferAnnotate
({
view
:
'container-id'
,
// 容器元素ID
pageUrl
:
'image-url'
,
// 页面图片URL
marks
:
[...],
// 标记区域数组
points
:
[...]
// 笔画数据数组
})
```
### Compiles and hot-reloads for development
## 核心功能实现
### 1. 图片加载与渲染
```
javascript
// 加载图片并获取尺寸信息
let
{
url
,
width
,
height
}
=
await
loadImage
(
pageUrl
)
// 创建页面框架
this
.
pageFrame
=
new
Frame
({
width
:
width
,
height
:
height
,
})
// 添加图片到框架
this
.
pageFrame
.
add
(
new
Image
({
url
:
url
},
width
,
height
))
```
pnpm run serve
### 2. 标记区域渲染
```
javascript
// 根据坐标数据创建矩形标记
const
rect
=
new
Rect
({
x
:
left
,
y
:
top
,
width
:
right
-
left
,
height
:
bottom
-
top
,
fill
:
'transparent'
,
stroke
:
'#ff0000'
,
strokeWidth
:
1
})
```
### Compiles and minifies for production
### 3. 手写笔画渲染
```
javascript
// 将笔画数据转换为 SVG 路径
const
path
=
optimizedCreatePathsFromStrokes
(
strokesStr
,
scaleX
,
scaleY
)
// 创建路径元素
const
pathElement
=
new
Path
({
path
:
path
,
stroke
:
'#000000'
,
strokeWidth
:
3
,
fill
:
null
,
strokeCap
:
'round'
,
strokeJoin
:
'round'
})
```
pnpm run build
## 安装与运行
### 环境要求
-
Node.js >= 14.0.0
-
npm 或 yarn 或 pnpm
### 安装依赖
```
bash
npm
install
```
### Lints and fixes files
### 启动开发服务器
```
bash
npm run serve
```
pnpm run lint
### 构建生产版本
```
bash
npm run build
```
### Customize configuration
See
[
Configuration Reference
](
https://cli.vuejs.org/config/
)
.
## 相关资源
-
[
Leafer.js 官方文档
](
https://www.leaferjs.com/
)
## 许可证
本项目仅供学习和参考使用。
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论