Commit 22295de0 authored by liujiangnan's avatar liujiangnan

feat

parent 9d944887
我有一个JSON数据,字段解释如下:
```
{
"audio_points": {
"说明": "音频相关的信息",
"字段": {
"audio_url": "音频文件的URL地址",
"points": {
"说明": "音频断点信息数组",
"包含字段": {
"start": "该段音频的开始时间(秒)",
"end": "该段音频的结束时间(秒)",
"text": "该段音频对应的英文文本",
"words": {
"说明": "单词级别的时间轴信息",
"包含字段": {
"start": "单词开始时间",
"end": "单词结束时间",
"word": "具体单词"
}
}
}
}
}
},
"pages": {
"说明": "书籍页面信息数组",
"字段": {
"image_url": "页面图片的URL地址",
"page": "页码",
"start": "该页面内容在音频中的开始时间",
"end": "该页面内容在音频中的结束时间",
"groups": {
"说明": "页面中的文本组信息",
"包含字段": {
"sentence": "识别出的英文句子",
"sentence_cn": "对应的中文翻译",
"start": "句子在音频中的开始时间",
"end": "句子在音频中的结束时间",
"reason": "时间戳缺失或特殊情况的解释说明",
"group": {
"说明": "文本在图片中的位置信息",
"包含字段": {
"rect": {
"x": "文本框左上角的X坐标(相对值)",
"y": "文本框左上角的Y坐标(相对值)",
"width": "文本框的宽度(相对值)",
"height": "文本框的高度(相对值)"
},
"text": "实际文本内容"
}
}
}
}
}
}
}
```
# 需求
我希望你基于 ./form/index.htm ./form/index.css ./form/index.js 帮我实现上面数据的可视化编辑功能,主要包含如下:
一、对于音频
1、要展示出音频的波形图,波形图能横向的放大和缩小,方便我查看毫秒级的细节
2、要把音频断点信息都展示出来,还有断点区间、断点区间的文本
3、能够通过拖拽微调断点区间
4、能够播放音频,播放的时候有个标识同步显示到波形图的位置上
二、对于书籍页面
1、要能展示每一页,显示所有的页面索引,通过点击能够跳转到对应的页
2、当点击跳转到某一页时,音频也定位到对应的位置,开始时间和结束时间都缩放到能够直观看到的程度
3、要把位置信息通过矩形标注到图片的对应位置上,并且能够调整矩形的位置和大小,方便我进行手动修正
4、要有个编辑区,能够修改对应的英文句子、翻译、开始时间、结束时间
5、开始时间与结束时间要和对应的音频区间联动,就是手动调整音频区间,这个时间也要同步变
6、要能在页上新建矩形框,然后手动填写英文句子、翻译、开始时间、结束时间
7、要能删除矩形框,点击删除的话弹一个确认框,如果确认就连同矩形对应的数据都删除掉就行了
# 技术框架描述
vue2、element-ui 2.12、jQuery 1.12.3
都是通过CDN的方式引入好的,你就不要用组件的形式新建其他文件了,都在 ./form/index.js 通过new VUE()的方式 全部实现逻辑部分就好。
我还给你提供了一个真实的数据文件 ./form/defaultData.json
{
"audio_points": {
"audio_url": "https://staging-teach.cdn.ireadabc.com/23fdd207b9e3b382803c8cea33f939c0_l.mp3",
"points": [
{
"end": 5.31,
"text": "Baby Animals: Super Cute Reptiles.",
"start": 0.63,
"words": [
{
"end": 1.07,
"word": "Baby",
"start": 0.63
},
{
"end": 1.95,
"word": "Animals:",
"start": 1.25
},
{
"end": 3.22,
"word": "Super",
"start": 2.77
},
{
"end": 3.91,
"word": "Cute",
"start": 3.46
},
{
"end": 5.13,
"word": "Reptiles.",
"start": 4.19
}
]
},
{
"end": 7.93,
"text": "A Crabtree Roots Book.",
"start": 5.83,
"words": [
{
"end": 5.91,
"word": "A",
"start": 5.83
},
{
"end": 6.79,
"word": "Crabtree",
"start": 6.01
},
{
"end": 7.25,
"word": "Roots",
"start": 6.87
},
{
"end": 7.75,
"word": "Book.",
"start": 7.31
}
]
},
{
"end": 9.91,
"text": "By Amy Culliford.",
"start": 8.23,
"words": [
{
"end": 8.42,
"word": "By",
"start": 8.23
},
{
"end": 8.85,
"word": "Amy",
"start": 8.51
},
{
"end": 9.73,
"word": "Culliford.",
"start": 8.93
}
]
},
{
"end": 15.43,
"text": "There are many different kinds of baby reptiles.",
"start": 11.46,
"words": [
{
"end": 11.69,
"word": "There",
"start": 11.46
},
{
"end": 11.86,
"word": "are",
"start": 11.75
},
{
"end": 12.43,
"word": "many",
"start": 12.03
},
{
"end": 13,
"word": "different",
"start": 12.61
},
{
"end": 13.55,
"word": "kinds",
"start": 13.07
},
{
"end": 13.75,
"word": "of",
"start": 13.57
},
{
"end": 14.23,
"word": "baby",
"start": 13.81
},
{
"end": 15.25,
"word": "reptiles.",
"start": 14.29
}
]
},
{
"end": 21.62,
"text": "Some baby reptiles are big, and some are small.",
"start": 16.47,
"words": [
{
"end": 16.79,
"word": "Some",
"start": 16.47
},
{
"end": 17.22,
"word": "baby",
"start": 16.85
},
{
"end": 17.99,
"word": "reptiles",
"start": 17.26
},
{
"end": 18.23,
"word": "are",
"start": 18.07
},
{
"end": 18.84,
"word": "big,",
"start": 18.34
},
{
"end": 19.78,
"word": "and",
"start": 19.63
},
{
"end": 20.27,
"word": "some",
"start": 19.87
},
{
"end": 20.76,
"word": "are",
"start": 20.6
},
{
"end": 21.44,
"word": "small.",
"start": 20.81
}
]
},
{
"end": 29.65,
"text": "Some baby reptiles live on land, and some can live in water.",
"start": 23.43,
"words": [
{
"end": 23.85,
"word": "Some",
"start": 23.43
},
{
"end": 24.3,
"word": "baby",
"start": 23.92
},
{
"end": 25.13,
"word": "reptiles",
"start": 24.35
},
{
"end": 25.6,
"word": "live",
"start": 25.27
},
{
"end": 25.85,
"word": "on",
"start": 25.65
},
{
"end": 26.45,
"word": "land,",
"start": 25.92
},
{
"end": 27.34,
"word": "and",
"start": 27.13
},
{
"end": 27.81,
"word": "some",
"start": 27.37
},
{
"end": 28.11,
"word": "can",
"start": 27.97
},
{
"end": 28.55,
"word": "live",
"start": 28.19
},
{
"end": 28.86,
"word": "in",
"start": 28.71
},
{
"end": 29.47,
"word": "water.",
"start": 28.93
}
]
},
{
"end": 36.08,
"text": "Baby crocodiles live on land and in water.",
"start": 31.29,
"words": [
{
"end": 31.68,
"word": "Baby",
"start": 31.29
},
{
"end": 32.68,
"word": "crocodiles",
"start": 31.76
},
{
"end": 33.27,
"word": "live",
"start": 32.91
},
{
"end": 33.57,
"word": "on",
"start": 33.36
},
{
"end": 34.06,
"word": "land",
"start": 33.61
},
{
"end": 34.88,
"word": "and",
"start": 34.34
},
{
"end": 35.27,
"word": "in",
"start": 35.11
},
{
"end": 35.9,
"word": "water.",
"start": 35.36
}
]
},
{
"end": 40.74,
"text": "Most baby crocodiles are small.",
"start": 37.81,
"words": [
{
"end": 38.21,
"word": "Most",
"start": 37.81
},
{
"end": 38.61,
"word": "baby",
"start": 38.29
},
{
"end": 39.55,
"word": "crocodiles",
"start": 38.7
},
{
"end": 39.84,
"word": "are",
"start": 39.61
},
{
"end": 40.56,
"word": "small.",
"start": 39.93
}
]
},
{
"end": 43.99,
"text": "They can be green or gray.",
"start": 41.25,
"words": [
{
"end": 41.43,
"word": "They",
"start": 41.25
},
{
"end": 41.65,
"word": "can",
"start": 41.52
},
{
"end": 41.83,
"word": "be",
"start": 41.71
},
{
"end": 42.59,
"word": "green",
"start": 41.91
},
{
"end": 43.13,
"word": "or",
"start": 42.89
},
{
"end": 43.81,
"word": "gray.",
"start": 43.25
}
]
},
{
"end": 51.4,
"text": "All baby crocodiles have tails that help them move through water.",
"start": 45.45,
"words": [
{
"end": 45.93,
"word": "All",
"start": 45.45
},
{
"end": 46.43,
"word": "baby",
"start": 46.11
},
{
"end": 47.39,
"word": "crocodiles",
"start": 46.52
},
{
"end": 47.72,
"word": "have",
"start": 47.41
},
{
"end": 48.39,
"word": "tails",
"start": 47.79
},
{
"end": 48.88,
"word": "that",
"start": 48.75
},
{
"end": 49.19,
"word": "help",
"start": 48.93
},
{
"end": 49.47,
"word": "them",
"start": 49.23
},
{
"end": 50.15,
"word": "move",
"start": 49.63
},
{
"end": 50.56,
"word": "through",
"start": 50.29
},
{
"end": 51.22,
"word": "water.",
"start": 50.63
}
]
},
{
"end": 58.12,
"text": "Baby lizards can be big or small when they are young.",
"start": 52.87,
"words": [
{
"end": 53.27,
"word": "Baby",
"start": 52.87
},
{
"end": 54.03,
"word": "lizards",
"start": 53.37
},
{
"end": 54.4,
"word": "can",
"start": 54.25
},
{
"end": 54.56,
"word": "be",
"start": 54.45
},
{
"end": 55.09,
"word": "big",
"start": 54.63
},
{
"end": 55.68,
"word": "or",
"start": 55.37
},
{
"end": 56.39,
"word": "small",
"start": 55.77
},
{
"end": 56.95,
"word": "when",
"start": 56.79
},
{
"end": 57.18,
"word": "they",
"start": 57
},
{
"end": 57.31,
"word": "are",
"start": 57.19
},
{
"end": 57.94,
"word": "young.",
"start": 57.39
}
]
},
{
"end": 64.36,
"text": "Most baby lizards are green, yellow, or brown.",
"start": 59.71,
"words": [
{
"end": 60.13,
"word": "Most",
"start": 59.71
},
{
"end": 60.55,
"word": "baby",
"start": 60.19
},
{
"end": 61.25,
"word": "lizards",
"start": 60.63
},
{
"end": 61.45,
"word": "are",
"start": 61.29
},
{
"end": 62.1,
"word": "green,",
"start": 61.53
},
{
"end": 62.95,
"word": "yellow,",
"start": 62.41
},
{
"end": 63.45,
"word": "or",
"start": 63.29
},
{
"end": 64.18,
"word": "brown.",
"start": 63.55
}
]
},
{
"end": 69.17,
"text": "They can also be blue, red, or orange.",
"start": 65.04,
"words": [
{
"end": 65.18,
"word": "They",
"start": 65.04
},
{
"end": 65.37,
"word": "can",
"start": 65.23
},
{
"end": 65.76,
"word": "also",
"start": 65.4
},
{
"end": 66,
"word": "be",
"start": 65.86
},
{
"end": 66.59,
"word": "blue,",
"start": 66.08
},
{
"end": 67.66,
"word": "red,",
"start": 67.18
},
{
"end": 68.13,
"word": "or",
"start": 67.97
},
{
"end": 68.99,
"word": "orange.",
"start": 68.27
}
]
},
{
"end": 74.29,
"text": "All baby lizards have four legs.",
"start": 71.04,
"words": [
{
"end": 71.38,
"word": "All",
"start": 71.04
},
{
"end": 71.79,
"word": "baby",
"start": 71.45
},
{
"end": 72.43,
"word": "lizards",
"start": 71.87
},
{
"end": 72.69,
"word": "have",
"start": 72.5
},
{
"end": 73.19,
"word": "four",
"start": 72.79
},
{
"end": 74.11,
"word": "legs.",
"start": 73.43
}
]
},
{
"end": 81.82,
"text": "Baby snakes start out small, but can grow to be really long.",
"start": 75.95,
"words": [
{
"end": 76.33,
"word": "Baby",
"start": 75.95
},
{
"end": 77.08,
"word": "snakes",
"start": 76.45
},
{
"end": 77.63,
"word": "start",
"start": 77.36
},
{
"end": 77.87,
"word": "out",
"start": 77.65
},
{
"end": 78.54,
"word": "small,",
"start": 77.91
},
{
"end": 79.19,
"word": "but",
"start": 79.01
},
{
"end": 79.41,
"word": "can",
"start": 79.23
},
{
"end": 79.8,
"word": "grow",
"start": 79.43
},
{
"end": 80,
"word": "to",
"start": 79.86
},
{
"end": 80.18,
"word": "be",
"start": 80.04
},
{
"end": 80.81,
"word": "really",
"start": 80.31
},
{
"end": 81.64,
"word": "long.",
"start": 81.09
}
]
},
{
"end": 86.86,
"text": "Many baby snakes have scales.",
"start": 83.65,
"words": [
{
"end": 84,
"word": "Many",
"start": 83.65
},
{
"end": 84.44,
"word": "baby",
"start": 84.08
},
{
"end": 85.13,
"word": "snakes",
"start": 84.54
},
{
"end": 85.77,
"word": "have",
"start": 85.36
},
{
"end": 86.68,
"word": "scales.",
"start": 85.91
}
]
},
{
"end": 92.25,
"text": "Scales help baby snakes keep water in.",
"start": 88.58,
"words": [
{
"end": 89.23,
"word": "Scales",
"start": 88.58
},
{
"end": 89.54,
"word": "help",
"start": 89.27
},
{
"end": 90,
"word": "baby",
"start": 89.65
},
{
"end": 90.55,
"word": "snakes",
"start": 90.07
},
{
"end": 90.94,
"word": "keep",
"start": 90.65
},
{
"end": 91.67,
"word": "water",
"start": 91.01
},
{
"end": 92.07,
"word": "in.",
"start": 91.72
}
]
},
{
"end": 95.73,
"text": "They also help them to move around.",
"start": 92.97,
"words": [
{
"end": 93.11,
"word": "They",
"start": 92.97
},
{
"end": 93.47,
"word": "also",
"start": 93.15
},
{
"end": 93.77,
"word": "help",
"start": 93.54
},
{
"end": 94.22,
"word": "them",
"start": 93.79
},
{
"end": 94.41,
"word": "to",
"start": 94.22
},
{
"end": 94.81,
"word": "move",
"start": 94.43
},
{
"end": 95.55,
"word": "around.",
"start": 94.81
}
]
},
{
"end": 101.28,
"text": "All baby snakes say, Hiss!",
"start": 97.59,
"words": [
{
"end": 98.03,
"word": "All",
"start": 97.59
},
{
"end": 98.54,
"word": "baby",
"start": 98.18
},
{
"end": 99.18,
"word": "snakes",
"start": 98.63
},
{
"end": 99.73,
"word": "say,",
"start": 99.36
},
{
"end": 101.28,
"word": "Hiss!",
"start": 99.73
}
]
}
]
},
"pages": [
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0001_f738aca5ba90bf65172eb28f897f89f3@1080p.jpeg",
"page": "0",
"start": 0.63,
"end": 5.31,
"groups": [
{
"sentence": "L BABY ANIMALS SNPER CUT uapbila, AMY CULLIFORD",
"sentence_cn": "L 宝宝动物 SNPER 剪裁 uapbila,艾米·卡利福德",
"start": 0.63,
"end": 5.31,
"reason": "部分文本匹配音频内容中的'Baby Animals: Super Cute Reptiles.'('BABY ANIMALS SNPER CUT'可能是音频文本的变形/误识别)",
"group": [
{
"rect": {
"x": "0.094",
"y": "0.057",
"width": "0.129",
"height": "0.061"
},
"text": "L"
},
{
"rect": {
"x": "0.298",
"y": "0.053",
"width": "0.413",
"height": "0.043"
},
"text": "BABY ANIMALS"
},
{
"rect": {
"x": "0.365",
"y": "0.121",
"width": "0.256",
"height": "0.056"
},
"text": "SNPER CUT"
},
{
"rect": {
"x": "0.106",
"y": "0.161",
"width": "0.802",
"height": "0.235"
},
"text": "uapbila,"
},
{
"rect": {
"x": "0.429",
"y": "0.351",
"width": "0.208",
"height": "0.018"
},
"text": "AMY CULLIFORD"
}
]
},
{
"sentence": "N Crabtree Roots",
"sentence_cn": "N 克拉布特里·鲁茨",
"start": null,
"end": null,
"reason": "未在音频内容中找到匹配文本,可能是未朗读的页码/标题/作者信息(如'Crabtree'为出版社名)",
"group": [
{
"rect": {
"x": "0.783",
"y": "0.855",
"width": "0.074",
"height": "0.045"
},
"text": "N"
},
{
"rect": {
"x": "0.783",
"y": "0.898",
"width": "0.081",
"height": "0.015"
},
"text": "Crabtree"
},
{
"rect": {
"x": "0.766",
"y": "0.911",
"width": "0.117",
"height": "0.026"
},
"text": "Roots"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0002_4db89af97bf7aab0cb4116a4364033eb@1080p.jpeg",
"page": "1",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0003_418b75dce5a3834b0dd6aec54dd2780d@1080p.jpeg",
"page": "2",
"start": 5.83,
"end": 7.93,
"groups": [
{
"sentence": "BABY ANMALS SNPER CUT eeptta, AMY CULLIFORD",
"sentence_cn": "幼崽动物 SNPER 切割 eeptta,艾米·卡利福德",
"start": null,
"end": null,
"reason": "音频内容中不存在与文本中'BABY ANMALS SNPER CUT eeptta'或'AMY CULLIFORD'相关的任何单词或短语,可能为页码、标注或未朗读的乱码内容",
"group": [
{
"rect": {
"x": "0.272",
"y": "0.061",
"width": "0.417",
"height": "0.044"
},
"text": "BABY ANMALS"
},
{
"rect": {
"x": "0.339",
"y": "0.130",
"width": "0.259",
"height": "0.055"
},
"text": "SNPER CUT"
},
{
"rect": {
"x": "0.077",
"y": "0.172",
"width": "0.807",
"height": "0.233"
},
"text": "eeptta,"
},
{
"rect": {
"x": "0.379",
"y": "0.373",
"width": "0.222",
"height": "0.019"
},
"text": "AMY CULLIFORD"
}
]
},
{
"sentence": "A Crabtree Roots Plus Book",
"sentence_cn": "一本克拉布特里根源加强版书籍",
"start": 5.83,
"end": 7.75,
"reason": "文本'A Crabtree Roots Book'与音频文本高度匹配(仅差'Plus'一词),推测为同一句子,可能因音频版本差异或文本更新导致微小不同",
"group": [
{
"rect": {
"x": "0.167",
"y": "0.763",
"width": "0.702",
"height": "0.037"
},
"text": "A Crabtree Roots Plus Book"
}
]
},
{
"sentence": "Crabtree Publishing crabtreebooks.",
"sentence_cn": "克拉布特里出版社 crabtreebooks.",
"start": null,
"end": null,
"reason": "音频中未包含'Publishing'或'crabtreebooks'相关内容,可能为版权声明或未朗读的出版信息",
"group": [
{
"rect": {
"x": "0.400",
"y": "0.897",
"width": "0.232",
"height": "0.023"
},
"text": "Crabtree Publishing"
},
{
"rect": {
"x": "0.431",
"y": "0.926",
"width": "0.133",
"height": "0.013"
},
"text": "crabtreebooks."
}
]
},
{
"sentence": "com",
"sentence_cn": "com",
"start": null,
"end": null,
"reason": "音频中未包含'com'相关内容,可能为网址后缀或未朗读的文本元素",
"group": [
{
"rect": {
"x": "0.564",
"y": "0.926",
"width": "0.035",
"height": "0.013"
},
"text": "com"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0004_f492001043b24fc5c208593b16ce5de5@1080p.jpeg",
"page": "3",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0005_b6ac0b13c5d81e282838d9bfa5362829@1080p.jpeg",
"page": "4",
"start": 11.46,
"end": 15.43,
"groups": [
{
"sentence": "There are many different kinds of baby reptiles.",
"sentence_cn": "有许多不同种类的幼年爬行动物。",
"start": 11.46,
"end": 15.43,
"reason": null,
"group": [
{
"rect": {
"x": "0.108",
"y": "0.722",
"width": "0.819",
"height": "0.045"
},
"text": "There are many different"
},
{
"rect": {
"x": "0.106",
"y": "0.789",
"width": "0.755",
"height": "0.048"
},
"text": "kinds of baby reptiles."
}
]
},
{
"sentence": "3",
"sentence_cn": "3",
"start": null,
"end": null,
"reason": "音频数据中未找到文本内容为'3'的对应句子,可能是页码标记或非朗读内容",
"group": [
{
"rect": {
"x": "0.900",
"y": "0.919",
"width": "0.032",
"height": "0.033"
},
"text": "3"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0006_53360e590ecd6e80b8aebcd4b35dbb6f@1080p.jpeg",
"page": "5",
"start": 16.47,
"end": 21.62,
"groups": [
{
"sentence": "Some baby reptiles are big, and some are small.",
"sentence_cn": "有些幼年爬行动物体型很大,有些则很小。",
"start": 16.47,
"end": 21.62,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.085",
"width": "0.648",
"height": "0.053"
},
"text": "Some baby reptiles"
},
{
"rect": {
"x": "0.091",
"y": "0.153",
"width": "0.628",
"height": "0.048"
},
"text": "are big, and some"
},
{
"rect": {
"x": "0.092",
"y": "0.223",
"width": "0.324",
"height": "0.041"
},
"text": "are small."
}
]
},
{
"sentence": "A",
"sentence_cn": "A",
"start": null,
"end": null,
"reason": "该句子可能为页码标记/段落标记/非朗读内容,音频数据中未包含此短句的发音时间戳",
"group": [
{
"rect": {
"x": "0.454",
"y": "0.601",
"width": "0.207",
"height": "0.108"
},
"text": "A"
}
]
},
{
"sentence": "4",
"sentence_cn": "4",
"start": null,
"end": null,
"reason": "该句子可能为页码标记/段落标记/非朗读内容,音频数据中未包含此短句的发音时间戳",
"group": [
{
"rect": {
"x": "0.071",
"y": "0.921",
"width": "0.033",
"height": "0.030"
},
"text": "4"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0007_1fa7be9fa8ec38be5ff551a3c1cd05c8@1080p.jpeg",
"page": "6",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0008_ebe0483eabdf5e10e75927e039dc8f52@1080p.jpeg",
"page": "7",
"start": 23.43,
"end": 29.65,
"groups": [
{
"sentence": "Some baby reptiles live on land, and some can live in water.",
"sentence_cn": "有些幼年爬行动物生活在陆地上,有些则可以生活在水里。",
"start": 23.43,
"end": 29.65,
"reason": null,
"group": [
{
"rect": {
"x": "0.083",
"y": "0.685",
"width": "0.774",
"height": "0.054"
},
"text": "Some baby reptiles live"
},
{
"rect": {
"x": "0.085",
"y": "0.756",
"width": "0.779",
"height": "0.042"
},
"text": "on land, and some can"
},
{
"rect": {
"x": "0.083",
"y": "0.825",
"width": "0.418",
"height": "0.039"
},
"text": "live in water."
}
]
},
{
"sentence": "6",
"sentence_cn": "6",
"start": null,
"end": null,
"reason": "未匹配到对应音频片段,可能原因为:1. 该内容为页码或非朗读元素;2. 音频数据未完整提供;3. 文本与音频实际内容存在差异(如标点/数字格式不一致)",
"group": [
{
"rect": {
"x": "0.069",
"y": "0.917",
"width": "0.037",
"height": "0.035"
},
"text": "6"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0009_61bb717ec881855b9f13ed91d6a95b05@1080p.jpeg",
"page": "8",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0010_478a6974d502fe9e3eed203f4df4d404@1080p.jpeg",
"page": "9",
"start": 31.29,
"end": 36.08,
"groups": [
{
"sentence": "Baby crocodiles live on land and in water.",
"sentence_cn": "幼年鳄鱼生活在陆地和水中。",
"start": 31.29,
"end": 36.08,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.742",
"width": "0.765",
"height": "0.048"
},
"text": "Baby crocodiles live on"
},
{
"rect": {
"x": "0.091",
"y": "0.812",
"width": "0.587",
"height": "0.038"
},
"text": "land and in water."
}
]
},
{
"sentence": "8",
"sentence_cn": "8",
"start": null,
"end": null,
"reason": "该句可能为未朗读的页码标记或非文本内容(如纯数字),音频数据中未包含对应时间信息",
"group": [
{
"rect": {
"x": "0.074",
"y": "0.922",
"width": "0.028",
"height": "0.028"
},
"text": "8"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0011_2a8fbb6eee171e7b0b119a46d69c079c@1080p.jpeg",
"page": "10",
"start": 37.81,
"end": 43.99,
"groups": [
{
"sentence": "Most baby crocodiles are small.",
"sentence_cn": "大多数小鳄鱼都很小。",
"start": 37.81,
"end": 40.74,
"reason": "",
"group": [
{
"rect": {
"x": "0.122",
"y": "0.667",
"width": "0.675",
"height": "0.049"
},
"text": "Most baby crocodiles"
},
{
"rect": {
"x": "0.125",
"y": "0.738",
"width": "0.312",
"height": "0.042"
},
"text": "are small."
}
]
},
{
"sentence": " They can be green or gray.",
"sentence_cn": "它们可以是绿色或灰色。",
"start": 41.25,
"end": 43.99,
"reason": "",
"group": [
{
"rect": {
"x": "0.428",
"y": "0.738",
"width": "0.431",
"height": "0.042"
},
"text": " They can be"
},
{
"rect": {
"x": "0.123",
"y": "0.809",
"width": "0.446",
"height": "0.043"
},
"text": "green or gray."
}
]
},
{
"sentence": "O",
"sentence_cn": "O",
"start": null,
"end": null,
"reason": "单个字母'O'可能是非朗读内容(如页码/口误/校对标记),且音频数据仅包含前两句话的时间轴",
"group": [
{
"rect": {
"x": "0.897",
"y": "0.917",
"width": "0.035",
"height": "0.034"
},
"text": "O"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0012_731fe3e0198a95b62e9d9d283619457e@1080p.jpeg",
"page": "11",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0013_8f032813da23758cfea30125729927fe@1080p.jpeg",
"page": "12",
"start": 45.45,
"end": 51.4,
"groups": [
{
"sentence": "All baby crocodiles have tails that help them move through water.",
"sentence_cn": "所有小鳄鱼都有尾巴,帮助它们在水中移动。",
"start": 45.45,
"end": 51.4,
"reason": null,
"group": [
{
"rect": {
"x": "0.161",
"y": "0.531",
"width": "0.637",
"height": "0.049"
},
"text": "All baby crocodiles"
},
{
"rect": {
"x": "0.158",
"y": "0.594",
"width": "0.673",
"height": "0.053"
},
"text": "have tails that help"
},
{
"rect": {
"x": "0.156",
"y": "0.664",
"width": "0.668",
"height": "0.050"
},
"text": "them move through"
},
{
"rect": {
"x": "0.158",
"y": "0.738",
"width": "0.198",
"height": "0.038"
},
"text": "water."
}
]
},
{
"sentence": "11",
"sentence_cn": "11",
"start": null,
"end": null,
"reason": "音频数据中未找到该句对应内容,可能为页面编码/非朗读内容/转录遗漏",
"group": [
{
"rect": {
"x": "0.895",
"y": "0.917",
"width": "0.041",
"height": "0.035"
},
"text": "11"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0014_b005f2cd36b7d6edfd1b9d0ce261350e@1080p.jpeg",
"page": "13",
"start": 52.87,
"end": 58.12,
"groups": [
{
"sentence": "Baby lizards can be big or small when they are young.",
"sentence_cn": "小蜥蜴在幼年时可能体型或大或小。",
"start": 52.87,
"end": 58.12,
"reason": null,
"group": [
{
"rect": {
"x": "0.089",
"y": "0.422",
"width": "0.686",
"height": "0.047"
},
"text": "Baby lizards can be"
},
{
"rect": {
"x": "0.086",
"y": "0.490",
"width": "0.617",
"height": "0.048"
},
"text": "big or small when"
},
{
"rect": {
"x": "0.084",
"y": "0.558",
"width": "0.527",
"height": "0.054"
},
"text": "they are young."
}
]
},
{
"sentence": "12",
"sentence_cn": "12",
"start": null,
"end": null,
"reason": "未在音频数据中找到匹配的文本段落。可能原因:该内容为页码/非朗读符号,或音频数据未完整提供。",
"group": [
{
"rect": {
"x": "0.059",
"y": "0.917",
"width": "0.056",
"height": "0.037"
},
"text": "12"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0015_6b2244c6c790546aa138c65485cabb5f@1080p.jpeg",
"page": "14",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0016_3361056206785f07924a0318da0f4f4e@1080p.jpeg",
"page": "15",
"start": 59.71,
"end": 69.17,
"groups": [
{
"sentence": "sa",
"sentence_cn": "sa",
"start": null,
"end": null,
"reason": "未找到匹配的音频片段,可能原因为非朗读内容(如页码、乱码或非文本标记)",
"group": [
{
"rect": {
"x": "0.520",
"y": "0.384",
"width": "0.108",
"height": "0.029"
},
"text": "sa"
}
]
},
{
"sentence": "Most baby lizards are green, yellow, or brown.",
"sentence_cn": "大多数幼年蜥蜴是绿色、黄色或棕色。",
"start": 59.71,
"end": 64.36,
"reason": null,
"group": [
{
"rect": {
"x": "0.088",
"y": "0.601",
"width": "0.683",
"height": "0.044"
},
"text": "Most baby lizards are"
},
{
"rect": {
"x": "0.087",
"y": "0.662",
"width": "0.744",
"height": "0.054"
},
"text": "green, yellow, or brown."
}
]
},
{
"sentence": "They can also be blue, red, or orange.",
"sentence_cn": "它们也可能是蓝色、红色或橙色。",
"start": 65.04,
"end": 69.17,
"reason": null,
"group": [
{
"rect": {
"x": "0.086",
"y": "0.733",
"width": "0.731",
"height": "0.049"
},
"text": "They can also be blue,"
},
{
"rect": {
"x": "0.084",
"y": "0.804",
"width": "0.468",
"height": "0.049"
},
"text": "red, or orange."
}
]
},
{
"sentence": "14",
"sentence_cn": "14",
"start": null,
"end": null,
"reason": "未找到匹配的音频片段,可能原因为非朗读内容(如页码或数字标记)",
"group": [
{
"rect": {
"x": "0.059",
"y": "0.919",
"width": "0.056",
"height": "0.035"
},
"text": "14"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0017_83a028f8e298c2370194efc29bf2828d@1080p.jpeg",
"page": "16",
"start": 71.04,
"end": 74.29,
"groups": [
{
"sentence": "o",
"sentence_cn": "o",
"start": null,
"end": null,
"reason": "文本内容为单个字母,可能是非朗读符号或错误内容,未在音频数据中找到匹配的时间信息",
"group": [
{
"rect": {
"x": "0.331",
"y": "0.188",
"width": "0.068",
"height": "0.039"
},
"text": "o"
}
]
},
{
"sentence": "All baby lizards have four legs.",
"sentence_cn": "所有小蜥蜴都有四条腿。",
"start": 71.04,
"end": 74.29,
"reason": null,
"group": [
{
"rect": {
"x": "0.123",
"y": "0.672",
"width": "0.699",
"height": "0.044"
},
"text": "All baby lizards have"
},
{
"rect": {
"x": "0.118",
"y": "0.736",
"width": "0.309",
"height": "0.052"
},
"text": "four legs."
}
]
},
{
"sentence": "15",
"sentence_cn": "15",
"start": null,
"end": null,
"reason": "文本内容为纯数字,可能是页码标注或非朗读内容,未在音频数据中找到匹配的时间信息",
"group": [
{
"rect": {
"x": "0.886",
"y": "0.916",
"width": "0.058",
"height": "0.038"
},
"text": "15"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0018_8de132cd02f5bcc720ddbccd2e876333@1080p.jpeg",
"page": "17",
"start": 75.95,
"end": 81.82,
"groups": [
{
"sentence": "Baby snakes start out small, but can grow to be really long!",
"sentence_cn": "小蛇刚开始很小,但可以长得非常长!",
"start": 75.95,
"end": 81.82,
"reason": null,
"group": [
{
"rect": {
"x": "0.091",
"y": "0.083",
"width": "0.751",
"height": "0.047"
},
"text": "Baby snakes start out"
},
{
"rect": {
"x": "0.091",
"y": "0.152",
"width": "0.529",
"height": "0.042"
},
"text": "small, but can "
},
{
"rect": {
"x": "0.607",
"y": "0.155",
"width": "0.255",
"height": "0.044"
},
"text": "grow to"
},
{
"rect": {
"x": "0.090",
"y": "0.219",
"width": "0.480",
"height": "0.047"
},
"text": "be really long!"
}
]
},
{
"sentence": "16",
"sentence_cn": "16",
"start": null,
"end": null,
"reason": "音频数据中未包含此句,可能原因:1.页码数字属于非朗读内容 2.音频文件被剪辑过 3.原始字幕数据不完整",
"group": [
{
"rect": {
"x": "0.058",
"y": "0.917",
"width": "0.056",
"height": "0.036"
},
"text": "16"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0019_a7560afdee111308452201960219296a@1080p.jpeg",
"page": "18",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0020_473b9c57b8f81c9e4385335fc805068a@1080p.jpeg",
"page": "19",
"start": 83.65,
"end": 86.86,
"groups": [
{
"sentence": "e",
"sentence_cn": "e",
"start": null,
"end": null,
"reason": "音频数据中无对应文本内容,可能为标点符号、页码或未朗读的乱码字符",
"group": [
{
"rect": {
"x": "0.592",
"y": "0.286",
"width": "0.096",
"height": "0.047"
},
"text": "e"
}
]
},
{
"sentence": "Many baby snakes have scales.",
"sentence_cn": "许多小蛇有鳞片。",
"start": 83.65,
"end": 86.86,
"reason": null,
"group": [
{
"rect": {
"x": "0.103",
"y": "0.739",
"width": "0.597",
"height": "0.048"
},
"text": "Many baby snakes"
},
{
"rect": {
"x": "0.103",
"y": "0.808",
"width": "0.422",
"height": "0.039"
},
"text": "have scales."
}
]
},
{
"sentence": "18",
"sentence_cn": "18",
"start": null,
"end": null,
"reason": "音频数据中无对应文本内容,可能为未朗读的页码或数字标记",
"group": [
{
"rect": {
"x": "0.058",
"y": "0.915",
"width": "0.058",
"height": "0.040"
},
"text": "18"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0021_f7edd49a52d34a41f3229980361446a9@1080p.jpeg",
"page": "20",
"start": 88.58,
"end": 95.73,
"groups": [
{
"sentence": "Scales help baby snakes keep water in.",
"sentence_cn": "鳞片帮助幼蛇保持体内水分。",
"start": 88.58,
"end": 92.25,
"reason": null,
"group": [
{
"rect": {
"x": "0.134",
"y": "0.292",
"width": "0.572",
"height": "0.044"
},
"text": "Scales help baby"
},
{
"rect": {
"x": "0.132",
"y": "0.361",
"width": "0.732",
"height": "0.043"
},
"text": "snakes keep water in."
}
]
},
{
"sentence": "They also help them to move around.",
"sentence_cn": "它们也帮助幼蛇四处移动。",
"start": 92.97,
"end": 95.73,
"reason": null,
"group": [
{
"rect": {
"x": "0.134",
"y": "0.429",
"width": "0.687",
"height": "0.042"
},
"text": "They also help them"
},
{
"rect": {
"x": "0.131",
"y": "0.498",
"width": "0.557",
"height": "0.034"
},
"text": "to move around."
}
]
},
{
"sentence": "19",
"sentence_cn": "19",
"start": null,
"end": null,
"reason": "音���数据中缺少对应文本内容,可能为页码/非朗读内容/乱码",
"group": [
{
"rect": {
"x": "0.884",
"y": "0.917",
"width": "0.057",
"height": "0.037"
},
"text": "19"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0022_0f2b0cc2018e917204cbd59cc141484b@1080p.jpeg",
"page": "21",
"start": 97.59,
"end": 101.28,
"groups": [
{
"sentence": "All baby snakes say, hiss!",
"sentence_cn": "所有的小蛇都会发出嘶嘶声!",
"start": 97.59,
"end": 101.28,
"reason": null,
"group": [
{
"rect": {
"x": "0.165",
"y": "0.374",
"width": "0.526",
"height": "0.045"
},
"text": "All baby snakes"
},
{
"rect": {
"x": "0.162",
"y": "0.442",
"width": "0.303",
"height": "0.045"
},
"text": "say, hiss!"
}
]
},
{
"sentence": "20",
"sentence_cn": "20",
"start": null,
"end": null,
"reason": "音频数据中未找到该句对应的内容,可能原因为:1.该句为页码或非朗读内容;2.音频预处理时被识别为乱码或非内容元素被过滤",
"group": [
{
"rect": {
"x": "0.056",
"y": "0.919",
"width": "0.065",
"height": "0.035"
},
"text": "20"
}
]
}
]
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0023_f997ec9433e18a4141f5f3b6baa63dc2@1080p.jpeg",
"page": "22",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0024_091aa527136dbdcbfbccd7693ad88862@1080p.jpeg",
"page": "23",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0025_2701a568543432a44b7211b2b4476f78@1080p.jpeg",
"page": "24",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0026_01af8d1e9303a70cd78f4108766e8eb7@1080p.jpeg",
"page": "25",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0027_4db89af97bf7aab0cb4116a4364033eb@1080p.jpeg",
"page": "26",
"start": null,
"end": null,
"groups": []
},
{
"image_url": "https://staging-teach.cdn.ireadabc.com/0028_fce2597fd32eb582ffe7cb8c76314189@1080p.jpeg",
"page": "27",
"start": null,
"end": null,
"groups": []
}
]
}
\ No newline at end of file
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
}
.edit-data{
#app {
height: 100vh;
}
.el-container {
height: 100%;
}
.el-main {
padding: 10px;
height: calc(100vh - 255px); /* 减去音频控制器和分页器的高度 */
display: flex;
flex-direction: column;
}
/* 主要内容区域 */
.el-row {
flex: 1;
display: flex;
flex-direction: row;
height: 100%;
}
.el-col {
display: flex;
flex-direction: column;
min-height: 0; /* 允许内容压缩 */
}
/* 卡片样式 */
.el-card {
display: flex;
flex-direction: column;
height: 100%;
}
.el-card__header {
padding: 10px;
min-height: 20px;
}
.el-card__body {
flex: 1;
padding: 10px;
overflow: hidden;
display: flex;
flex-direction: column;
}
/* 图片编辑区域 */
.image-editor {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
}
.image-editor .image-container {
flex: 1;
position: relative;
overflow: auto;
border: 2px dashed #dcdfe6;
border-radius: 4px;
padding: 10px;
background-color: #fff;
display: flex;
justify-content: center;
align-items: flex-start;
}
.image-editor img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
position: relative;
}
/* 图片包装器,用于定位矩形 */
.image-wrapper {
position: relative;
display: inline-block;
line-height: 0;
}
/* 文本编辑区域 */
.text-editor {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.text-editor .el-card__body {
overflow-y: auto;
}
.text-editor .el-table {
margin-bottom: 10px;
}
.text-editor .el-divider {
margin: 16px 0;
}
.text-editor .el-table .cell {
word-break: break-all;
}
/* 音频控制区域 */
.audio-control {
height: 200px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 1000;
margin: 0;
border-radius: 0;
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}
.audio-control .el-card__body {
padding: 10px 20px;
}
.waveform-container {
height: 100%;
display: flex;
flex-direction: column;
}
#waveform {
flex: 1;
min-height: 120px;
}
#wave-timeline {
height: 30px;
margin-bottom: 5px;
}
.audio-controls {
padding: 5px 0;
display: flex;
align-items: center;
}
/* 分页器样式 */
.pagination-container {
position: fixed;
bottom: 200px; /* 音频控制器的高度 */
left: 0;
right: 0;
z-index: 1000;
padding: 10px 0;
text-align: center;
background: rgba(255, 255, 255, 0.9);
border-top: 1px solid #EBEEF5;
}
/* 矩形框样式 */
.text-rect {
position: absolute;
border: 2px dashed #409EFF;
background-color: rgba(64, 158, 255, 0.1);
cursor: move;
transform-origin: top left;
user-select: none;
}
.text-rect.selected {
border-color: #67C23A;
background-color: rgba(103, 194, 58, 0.1);
z-index: 2;
}
.text-rect.highlighted {
border-color: #E6A23C;
background-color: rgba(230, 162, 60, 0.2);
z-index: 3;
}
.text-content {
position: absolute;
bottom: -20px;
left: 0;
width: 100%;
text-align: center;
font-size: 12px;
color: #606266;
background-color: rgba(255, 255, 255, 0.8);
padding: 2px 4px;
border-radius: 2px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.resize-handle {
position: absolute;
right: -5px;
bottom: -5px;
width: 10px;
height: 10px;
background-color: #fff;
border: 2px solid #409EFF;
cursor: se-resize;
z-index: 3;
}
.text-rect.selected .resize-handle {
border-color: #67C23A;
}
.text-rect .delete-rect-btn {
position: absolute;
right: -10px;
top: -10px;
padding: 4px;
opacity: 0;
transition: opacity 0.3s;
}
.text-rect:hover .delete-rect-btn {
opacity: 1;
}
.text-rect .delete-rect-btn i {
font-size: 12px;
}
/* Element UI 组件调整 */
.el-form-item {
margin-bottom: 10px;
}
.el-form-item__label {
line-height: 32px;
}
.el-input-number {
width: 100%;
}
.el-aside {
background-color: #f5f7fa;
padding: 20px;
}
.page-list {
height: 100%;
}
.image-container {
position: relative;
width: 100%;
overflow: hidden;
}
.image-container img {
width: 100%;
height: auto;
border-radius: 4px;
}
.line {
text-align: center;
line-height: 40px;
}
.wavesurfer-region {
z-index: 3 !important;
}
.wavesurfer-handle {
background-color: #409EFF !important;
width: 4px !important;
}
.app{
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
/* 新建矩形框按钮 */
.add-rect-btn {
position: absolute;
right: 15px;
bottom: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.add-rect-btn:hover {
opacity: 1;
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>h5-template-generator</title>
<title>音频文本编辑器</title>
<link href="./index.css" rel="stylesheet" >
<script type="text/javascript" src="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/jquery-1.12.3.min.js"></script>
<script type="text/javascript" src="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
......@@ -13,13 +13,193 @@
<link href="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/element-ui/theme-chalk/index.css" rel="stylesheet">
<!-- 引入组件库 -->
<script src="//teach.cdn.ireadabc.com/h5template/h5-static-lib/js/element-ui/index.js"></script>
<!-- 引入波形图组件 -->
<script src="https://unpkg.com/wavesurfer.js@2.0.4/dist/wavesurfer.min.js"></script>
<script src="https://unpkg.com/wavesurfer.js@2.0.4/dist/plugin/wavesurfer.regions.min.js"></script>
<script src="https://unpkg.com/wavesurfer.js@2.0.4/dist/plugin/wavesurfer.timeline.min.js"></script>
<style>
.text-editor {
padding: 20px;
border: 2px dashed #dcdfe6;
border-radius: 4px;
height: calc(100vh - 40px);
overflow-y: auto;
}
</style>
</head>
<body>
<div class="edit-data">
<!-- 简单的例子,一个输入框+一个按钮,保存输入框的信息 -->
test: <input type="text" name="test" />
<input id="save" type="button" value="保存" >
</div>
<div id="app" v-loading.fullscreen.lock="loading">
<el-container>
<!-- 主要内容区域 -->
<el-main>
<el-row :gutter="20">
<!-- 左侧图片编辑区域 -->
<el-col :span="12">
<div class="image-editor" v-if="currentPage">
<div class="image-container" ref="imageContainer">
<div class="image-wrapper">
<img :src="currentPage.image_url" ref="pageImage" @load="handleImageLoad">
<template v-for="(group, groupIndex) in currentPage.groups">
<div
v-for="(item, itemIndex) in group.group"
:key="groupIndex + '-' + itemIndex"
class="text-rect"
:class="{
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style="getRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<div class="text-content">{{ item.text }}</div>
<el-button
class="delete-rect-btn"
type="danger"
size="mini"
circle
@click.stop="deleteRect(groupIndex, itemIndex)">
<i class="el-icon-delete"></i>
</el-button>
</div>
</template>
</div>
<el-button
class="add-rect-btn"
type="primary"
circle
size="small"
@click="addNewRect">
<i class="el-icon-plus"></i>
</el-button>
</div>
</div>
</el-col>
<!-- 右侧文本编辑区域 -->
<el-col :span="12">
<div class="text-editor">
<!-- 页面时间范围 -->
<el-form label-width="70px" v-if="currentPage" style="padding: 10px;">
<el-form-item label="页面时间">
<el-col :span="11">
<el-input-number
v-model="currentPage.start"
:precision="2"
:step="0.1"
placeholder="开始时间">
</el-input-number>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-input-number
v-model="currentPage.end"
:precision="2"
:step="0.1"
placeholder="结束时间">
</el-input-number>
</el-col>
</el-form-item>
</el-form>
<!-- 选中组的编辑区域 -->
<template v-if="currentPage && selectedGroup !== null && currentGroup">
<el-divider>组编辑</el-divider>
<el-form label-width="100px">
<el-form-item label="英文句子">
<el-input v-model="currentGroup.sentence"></el-input>
</el-form-item>
<el-form-item label="中文翻译">
<el-input v-model="currentGroup.sentence_cn"></el-input>
</el-form-item>
<el-form-item label="时间范围">
<el-col :span="11">
<el-input-number
v-model="currentGroup.start"
:precision="2"
:step="0.1"
@change="updateAudioRegion">
</el-input-number>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-input-number
v-model="currentGroup.end"
:precision="2"
:step="0.1"
@change="updateAudioRegion">
</el-input-number>
</el-col>
</el-form-item>
<el-form-item label="矩形列表">
<el-table
:data="currentGroup.group"
size="mini"
border
highlight-current-row
@current-change="handleRectRowClick">
<el-table-column prop="text" label="文本内容"></el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
type="danger"
size="mini"
icon="el-icon-delete"
circle
@click="deleteRectFromGroup(selectedGroup, scope.$index)">
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
<el-form-item>
<el-button type="danger" @click="deleteGroup">删除整组</el-button>
</el-form-item>
</el-form>
</template>
</div>
</el-col>
</el-row>
</el-main>
</el-container>
<!-- 分页器 -->
<div class="pagination-container" v-if="currentPage">
<el-pagination
background
@current-change="handlePageChange"
:current-page.sync="currentPageIndex"
:page-size="1"
layout="prev, pager, next"
:total="pages.length">
</el-pagination>
</div>
<!-- 音频控制区域 -->
<el-card class="audio-control" v-loading="audioLoading">
<div class="waveform-container">
<div id="waveform"></div>
<div id="wave-timeline"></div>
<div class="audio-controls">
<el-button-group>
<el-button size="small" @click="playAudio" :disabled="audioLoading">
<i :class="isPlaying ? 'el-icon-video-pause' : 'el-icon-video-play'"></i>
</el-button>
<el-button size="small" @click="stopAudio" :disabled="audioLoading">
<i class="el-icon-video-stop"></i>
</el-button>
</el-button-group>
<el-slider
v-model="zoomLevel"
:min="1"
:max="500"
@change="handleZoom"
:disabled="audioLoading"
style="width: 200px; margin-left: 20px;">
</el-slider>
</div>
</div>
</el-card>
</div>
</body>
<script src="./index.js"></script>
</html>
\ No newline at end of file
new Vue({
el: '#app',
data: {
// 音频相关
wavesurfer: null,
isPlaying: false,
zoomLevel: 50,
audioRegions: {},
// 数据相关
audioPoints: null,
pages: [],
currentPage: null,
currentPageIndex: 0,
// 编辑相关
selectedGroup: null,
currentGroup: null,
isDragging: false,
isResizing: false,
dragStartX: 0,
dragStartY: 0,
originalRect: null,
selectedItemIndex: null,
// 加载状态
loading: false,
audioLoading: false,
currentProgress: null,
imageWidth: 0,
imageHeight: 0,
imageLoaded: false,
imageRect: null
},
mounted() {
this.$nextTick(() => {
// 先加载数据
this.loadDefaultData().then(() => {
// 数据加载成功后初始化波形图
this.initWavesurfer();
});
// 添加全局事件监听
document.addEventListener('mousemove', this.handleMouseMove);
document.addEventListener('mouseup', this.handleMouseUp);
});
},
methods: {
// 加载默认数据
async loadDefaultData() {
this.loading = true;
this.$message.info('正在加载数据...');
try {
const response = await fetch('./defaultData.json');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
this.audioPoints = data.audio_points;
this.pages = data.pages;
this.currentPageIndex = 1;
this.currentPage = this.pages[0];
this.loading = false;
this.$message.success('数据加载成功');
} catch (error) {
console.error('Error loading data:', error);
this.$message.error('数据加载失败');
this.loading = false;
throw error;
}
},
// 初始化波形图
initWavesurfer() {
if (!this.audioPoints || !this.audioPoints.audio_url) {
console.warn('No audio data available');
return;
}
try {
this.wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: '#A8DBA8',
progressColor: '#3B8686',
cursorColor: '#0B486B',
height: 128,
minPxPerSec: 0,
fillParent: true, // 初始状态填充父容器
scrollParent: false, // 初始状态不显示滚动条
responsive: true, // 响应容器大小变化
normalize: true, // 波形归一化
pixelRatio: 1, // 像素比
autoCenter: true, // 自动居中
cursorWidth: 2, // 光标宽度
interact: true, // 允许交互
plugins: [
WaveSurfer.regions.create(),
WaveSurfer.timeline.create({
container: '#wave-timeline',
height: 20,
notchPercentHeight: 50,
primaryFontColor: '#666',
secondaryFontColor: '#888',
primaryColor: '#666',
secondaryColor: '#888'
})
]
});
// 监听事件
this.wavesurfer.on('ready', () => {
this.audioLoading = false;
console.log('WaveSurfer ready');
// 音频加载完成后,创建区域并显示第一页
this.createAllAudioRegions();
// 重置缩放级别为1,显示完整波形
this.zoomLevel = 1;
this.wavesurfer.zoom(1);
});
// 添加点击波形定位事件
this.wavesurfer.on('click', (e, progress) => {
// 保存当前位置作为后续缩放的锚点
this.currentProgress = progress;
});
this.wavesurfer.on('error', (err) => {
console.error('WaveSurfer error:', err);
this.$message.error('音频加载失败');
this.audioLoading = false;
});
this.wavesurfer.on('region-updated', this.handleRegionUpdated);
// 加载音频
this.audioLoading = true;
this.wavesurfer.load(this.audioPoints.audio_url);
} catch (err) {
console.error('WaveSurfer initialization error:', err);
this.$message.error('波形图初始化失败');
}
},
// 创建所有页面的音频区域
createAllAudioRegions() {
if (!this.wavesurfer || !this.wavesurfer.isReady) {
console.warn('WaveSurfer not ready yet');
return;
}
// 清除现有的区域
this.wavesurfer.clearRegions();
this.audioRegions = {};
// 为每个页面创建区域
this.pages.forEach((page, pageIndex) => {
if (page.groups) {
page.groups.forEach((group, groupIndex) => {
if (group.start !== null && group.end !== null) {
const regionId = `${pageIndex}-${groupIndex}`;
const isCurrentPage = pageIndex === this.currentPageIndex - 1;
try {
this.audioRegions[regionId] = this.wavesurfer.addRegion({
id: regionId,
start: group.start,
end: group.end,
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage
});
} catch (err) {
console.error(`Error creating region ${regionId}:`, err);
}
}
});
}
});
},
// 处理音频区域更新
handleRegionUpdated(region) {
if (!this.currentPage || !region) return;
const [pageIndex, groupIndex] = region.id.split('-').map(Number);
if (pageIndex !== this.currentPageIndex - 1) return;
const group = this.currentPage.groups[groupIndex];
if (group) {
group.start = region.start;
group.end = region.end;
// 如果当前选中的就是这个组,更新编辑器中的值
if (this.selectedGroup === groupIndex) {
this.currentGroup = group;
}
}
},
// 音频控制
playAudio() {
if (!this.wavesurfer) return;
try {
this.wavesurfer.playPause();
this.isPlaying = !this.isPlaying;
// 播放时保存当前位置作为缩放锚点
if (this.isPlaying) {
this.currentProgress = this.wavesurfer.getCurrentTime() / this.wavesurfer.getDuration();
}
} catch (err) {
console.error('Error playing audio:', err);
this.$message.error('播放失败');
}
},
stopAudio() {
if (!this.wavesurfer) return;
try {
this.wavesurfer.stop();
this.isPlaying = false;
} catch (err) {
console.error('Error stopping audio:', err);
this.$message.error('停止失败');
}
},
handleZoom(value) {
if (!this.wavesurfer) return;
try {
// 保存当前位置
const currentTime = this.wavesurfer.getCurrentTime();
const duration = this.wavesurfer.getDuration();
const progress = currentTime / duration;
// 更新缩放设置
if (value === 1) {
// 最小缩放级别时,填充父容器
this.wavesurfer.params.fillParent = true;
this.wavesurfer.params.scrollParent = false;
} else {
// 放大时,启用滚动
this.wavesurfer.params.fillParent = false;
this.wavesurfer.params.scrollParent = true;
}
// 应用缩放
this.wavesurfer.zoom(value);
// 重新定位到之前的位置
if (value > 1) {
// 使用保存的进度或当前进度作为锚点
const targetProgress = this.currentProgress || progress;
this.wavesurfer.seekTo(targetProgress);
// 确保波形图滚动到正确位置
const scrollWidth = this.wavesurfer.drawer.wrapper.scrollWidth;
const containerWidth = this.wavesurfer.drawer.wrapper.clientWidth;
const scrollPosition = Math.max(0, (targetProgress * scrollWidth) - (containerWidth / 2));
this.wavesurfer.drawer.wrapper.scrollLeft = scrollPosition;
} else {
// 缩小到原始大小时,重置滚动位置
this.wavesurfer.drawer.wrapper.scrollLeft = 0;
this.currentProgress = null;
}
// 重绘以确保显示正确
this.wavesurfer.drawBuffer();
} catch (err) {
console.error('Error zooming:', err);
}
},
// 页面选择
handlePageChange(page) {
if (!this.wavesurfer) return;
try {
const index = page - 1;
this.currentPage = this.pages[index];
this.selectedGroup = null;
this.currentGroup = null;
// 更新所有区域的样式
Object.keys(this.audioRegions).forEach(regionId => {
const [pageIndex, groupIndex] = regionId.split('-').map(Number);
const region = this.audioRegions[regionId];
const isCurrentPage = pageIndex === index;
region.update({
color: isCurrentPage ? 'rgba(64, 158, 255, 0.2)' : 'rgba(144, 147, 153, 0.1)',
drag: isCurrentPage,
resize: isCurrentPage
});
});
// 定位到当前页面的时间范围,但不自动缩放
if (this.currentPage) {
const pageGroups = this.currentPage.groups || [];
if (pageGroups.length > 0) {
const pageStart = Math.min(...pageGroups.map(g => g.start));
this.wavesurfer.seekTo(pageStart / this.wavesurfer.getDuration());
}
}
} catch (err) {
console.error('Error changing page:', err);
}
},
// 计算合适的缩放级别
calculateZoomLevel(start, end) {
const duration = end - start;
// 降低默认缩放倍数
return Math.min(500, Math.max(1, Math.floor(100 / duration)));
},
// 图片加载完成后的处理
handleImageLoad() {
const img = this.$refs.pageImage;
if (!img) return;
/*
// 获取图片在页面上的实际渲染尺寸和位置
this.imageRect = img.getBoundingClientRect();
this.imageWidth = this.imageRect.width;
this.imageHeight = this.imageRect.height;
this.imageLoaded = true;
window.courseware.getData(callback,key); //用于获取数据
window.courseware.setData(data,callback,key); //用于存储数据
var uploadUrl = window.courseware.uploadUrl(); //上传文件的路径
var uploadData = window.courseware.uploadData(); //上传文件必须要的参数
console.log('Image loaded:', {
width: this.imageWidth,
height: this.imageHeight,
rect: this.imageRect
});
},
// 获取矩形样式
getRectStyle(rect) {
if (!rect || !this.imageLoaded || !this.imageRect) return { display: 'none' };
*/
// 将字符串转换为数值
const x = parseFloat(rect.x);
const y = parseFloat(rect.y);
const width = parseFloat(rect.width);
const height = parseFloat(rect.height);
//对应模板的名称,这个可以不写,但是最好是能写上,同时开发多个模板的情况下如果不写这个,本地缓存可能会存在混乱
var key = "h5_test";
// 计算实际的像素位置
const actualX = x * this.imageWidth;
const actualY = y * this.imageHeight;
const actualWidth = width * this.imageWidth;
const actualHeight = height * this.imageHeight;
$(function(){
window.courseware.getData(function(data){
//数据加载完,才算页面加载完成
//获取数据
if(data&&data.test){
$("[name='test']").val(data.test);
}
console.log('Rectangle position:', {
normalized: { x, y, width, height },
actual: { x: actualX, y: actualY, width: actualWidth, height: actualHeight },
image: { width: this.imageWidth, height: this.imageHeight }
});
//绑定点击事件
$('#save').on('click',function(){
var test = $("[name='test']").val();
return {
position: 'absolute',
left: actualX + 'px',
top: actualY + 'px',
width: actualWidth + 'px',
height: actualHeight + 'px'
};
},
// 选择文本组
selectGroup(index) {
if (!this.currentPage || !this.currentPage.groups) return;
// 如果点击已选中的组,则取消选中
if (this.selectedGroup === index) {
this.selectedGroup = null;
this.currentGroup = null;
} else {
this.selectedGroup = index;
this.currentGroup = this.currentPage.groups[index];
}
},
// 开始拖拽
startDrag(event, groupIndex, itemIndex) {
if (event.target.classList.contains('resize-handle') || !this.imageLoaded) return;
this.isDragging = true;
this.dragStartX = event.clientX;
this.dragStartY = event.clientY;
this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex];
this.selectedItemIndex = itemIndex;
this.originalRect = this.currentGroup.group[itemIndex].rect ? { ...this.currentGroup.group[itemIndex].rect } : null;
event.preventDefault();
event.stopPropagation(); // 阻止事件冒泡
},
// 开始调整大小
startResize(event, groupIndex, itemIndex) {
if (!this.imageLoaded) return;
this.isResizing = true;
this.dragStartX = event.clientX;
this.dragStartY = event.clientY;
this.selectedGroup = groupIndex;
this.currentGroup = this.currentPage.groups[groupIndex];
this.selectedItemIndex = itemIndex;
this.originalRect = this.currentGroup.group[itemIndex].rect ? { ...this.currentGroup.group[itemIndex].rect } : null;
console.log('Start resizing:', {
startX: this.dragStartX,
startY: this.dragStartY,
originalRect: this.originalRect,
groupIndex,
itemIndex
});
event.preventDefault();
},
// 处理鼠标移动
handleMouseMove(event) {
if ((!this.isDragging && !this.isResizing) || !this.currentGroup || !this.originalRect || !this.imageLoaded) return;
const currentRect = this.currentGroup.group[this.selectedItemIndex].rect;
if (!currentRect || !this.imageRect) return;
// 计算鼠标移动的相对距离
const deltaX = (event.clientX - this.dragStartX) / this.imageWidth;
const deltaY = (event.clientY - this.dragStartY) / this.imageHeight;
if (this.isDragging) {
// 计算新位置,确保不超出图片边界
currentRect.x = Math.max(0, Math.min(1 - currentRect.width, this.originalRect.x + deltaX));
currentRect.y = Math.max(0, Math.min(1 - currentRect.height, this.originalRect.y + deltaY));
console.log('Dragging:', {
x: currentRect.x,
y: currentRect.y,
deltaX,
deltaY,
itemIndex: this.selectedItemIndex
});
} else if (this.isResizing) {
// 计算新尺寸,确保不超出图片边界
currentRect.width = Math.max(0.1, Math.min(1 - currentRect.x, this.originalRect.width + deltaX));
currentRect.height = Math.max(0.1, Math.min(1 - currentRect.y, this.originalRect.height + deltaY));
console.log('Resizing:', {
width: currentRect.width,
height: currentRect.height,
deltaX,
deltaY,
itemIndex: this.selectedItemIndex
});
}
},
// 处理鼠标松开
handleMouseUp(event) {
// 如果是拖拽或调整大小操作,阻止后续的 click 事件
if (this.isDragging || this.isResizing) {
event.preventDefault();
event.stopPropagation();
}
this.isDragging = false;
this.isResizing = false;
},
// 更新音频区域
updateAudioRegion() {
if (!this.currentGroup || this.selectedGroup === null) return;
try {
const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`;
const region = this.audioRegions[regionId];
if (region) {
region.update({
start: this.currentGroup.start,
end: this.currentGroup.end
});
}
} catch (err) {
console.error('Error updating audio region:', err);
}
},
// 添加新矩形框
addNewRect() {
if (!this.currentPage || !this.imageLoaded) return;
try {
// 创建新的分组
const newGroup = {
sentence: '',
sentence_cn: '',
start: 0,
end: 0,
group: [{
rect: {
x: 0.2,
y: 0.2,
width: 0.2,
height: 0.2
},
text: ''
}]
};
// 添加到当前页面
if (!this.currentPage.groups) {
this.currentPage.groups = [];
}
const newIndex = this.currentPage.groups.length;
this.currentPage.groups.push(newGroup);
// 创建对应的音频区域
const regionId = `${this.currentPageIndex - 1}-${newIndex}`;
this.audioRegions[regionId] = this.wavesurfer.addRegion({
id: regionId,
start: 0,
end: 0,
color: 'rgba(64, 158, 255, 0.2)',
drag: true,
resize: true
});
// 选中新创建的分组
this.selectGroup(newIndex);
} catch (err) {
console.error('Error adding new rectangle:', err);
this.$message.error('添加新矩形框失败');
}
},
// 从组中删除矩形框
deleteRectFromGroup(groupIndex, itemIndex) {
if (!this.currentPage || !this.currentPage.groups[groupIndex]) return;
const group = this.currentPage.groups[groupIndex];
if (!group.group[itemIndex]) return;
this.$confirm('确认删除该文本框吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
try {
// 删除矩形框
group.group.splice(itemIndex, 1);
// 如果组内没有矩形框了,删除整个组
if (group.group.length === 0) {
// 删除音频区域
const regionId = `${this.currentPageIndex - 1}-${groupIndex}`;
if (this.audioRegions[regionId]) {
this.audioRegions[regionId].remove();
delete this.audioRegions[regionId];
}
// 删除分组数据
this.currentPage.groups.splice(groupIndex, 1);
this.selectedGroup = null;
this.currentGroup = null;
// 重新创建所有区域以更新索引
this.createAllAudioRegions();
} else {
// 更新句子文本
const texts = group.group.map(item => item.text).filter(Boolean);
group.sentence = texts.join(' ');
}
this.$message.success('删除成功');
} catch (err) {
console.error('Error deleting rectangle from group:', err);
this.$message.error('删除失败');
}
}).catch(() => {});
},
// 删除整个分组
deleteGroup() {
if (this.selectedGroup === null || !this.currentPage) return;
this.$confirm('确认删除该组及其所有矩形框吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
try {
// 删除音频区域
const regionId = `${this.currentPageIndex - 1}-${this.selectedGroup}`;
if (this.audioRegions[regionId]) {
this.audioRegions[regionId].remove();
delete this.audioRegions[regionId];
}
// 删除分组数据
this.currentPage.groups.splice(this.selectedGroup, 1);
this.selectedGroup = null;
this.currentGroup = null;
// 重新创建所有区域以更新索引
this.createAllAudioRegions();
this.$message.success('删除成功');
} catch (err) {
console.error('Error deleting group:', err);
this.$message.error('删除失败');
}
}).catch(() => {});
},
// 处理矩形列表行点击
handleRectRowClick(row, oldRow) {
if (!row) {
this.selectedItemIndex = null;
return;
}
//保存新增或修改的数据
window.courseware.setData({test: test},function(){
//保存数据也是异步的
alert("保存成功!");
},key);
// 找到点击行对应的索引
this.selectedItemIndex = this.currentGroup.group.findIndex(item => item === row);
})
},key);
})
\ No newline at end of file
// 如果矩形在可视区域外,滚动到可视区域
this.$nextTick(() => {
const rect = this.currentGroup.group[this.selectedItemIndex].rect;
if (rect) {
const imageContainer = this.$refs.imageContainer;
if (imageContainer) {
const actualY = parseFloat(rect.y) * this.imageHeight;
imageContainer.scrollTop = Math.max(0, actualY - 100); // 向上偏移100px,更容易看到
}
}
});
}
},
beforeDestroy() {
// 清理事件监听
document.removeEventListener('mousemove', this.handleMouseMove);
document.removeEventListener('mouseup', this.handleMouseUp);
// 销毁波形图
if (this.wavesurfer) {
try {
this.wavesurfer.destroy();
} catch (err) {
console.error('Error destroying wavesurfer:', err);
}
}
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment