提交 9100bb68 authored 作者: yueweilu's avatar yueweilu

离线给 html 准备数据

上级 d193df1c
......@@ -743,6 +743,89 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
queryLocalNote();
}
// 获取离线数据
void getOffLineInfo() async {
Map<String, dynamic> data = {};
data['chapter_name'] = chapterName;
// 1、根据当前章节id名称 获取内容
String toReadHtmlPath = await getLocalReadHtml(chapterId);
// 2、获取 离线文件的内容
final enCodeContent = await readHtmlFileContent(toReadHtmlPath);
// 3、解密离线的内容
String deCodeContent = EncryptUtil.aesDecrypt(enCodeContent!);
data['content'] = deCodeContent;
// 4、获取上一章节信息
Map<String, dynamic> upChapter = {};
final upId = await getChapterId(type: 0);
if(upId.isEmpty) {
data['up_chapter'] = '';
}
else{
String upName = getChapterName(upId);
upChapter['name'] = upName;
upChapter['id'] = int.parse(upId);
}
// 5、获取下一章节信息
Map<String, dynamic> nextChapter = {};
final nextId = await getChapterId(type: 1);
if(nextId.isEmpty) {
data['next_chapter'] = '';
}
else{
String nextName = getChapterName(upId);
nextChapter['name'] = nextName;
nextChapter['id'] = int.parse(nextId);
}
// 6、获取离线高亮和划线
final Map<String, dynamic> temp = await queryNewLocalNote();
data.addAll(temp);
// 7、 给前端参数
String jsonStr = jsonEncode(data);
webViewController.evaluateJavascript(source: 'offlineCallbackInFlutterComponent($jsonStr)');
}
// 获取上一章节或下一章节 id
Future<String> getChapterId({required int type}) async{
String docPath = await _getDirectory();
String filePath = '$docPath/$bookId';
Directory directory = Directory(filePath);
// 获取目录下的所有文件
List<FileSystemEntity> files = directory.listSync(recursive: true);
int findIndex = int.parse(currentHtmlName.split('-').first);
if(type == 0){
findIndex--;
if(findIndex <0){
Toast.show('前面已没有章节');
// 已到最前
return '';
}
}
else{
findIndex++;
if(findIndex >files.length -1){
// 已到最后
return '';
}
}
for (var file in files) {
if (file is File && file.path.toLowerCase().endsWith('.html')) {
String fileName = path.basenameWithoutExtension(file.path);
if (int.parse(fileName.split('-').first) == findIndex){
Console.log('HTML File--------------------------------${file.path}');
String chapterId = fileName.split('-').last;
return chapterId;
}
}
}
return '';
}
// 本地阅读 读取上一章节 或 下一章节
// 0 上一章节
// 1 下一章节
......@@ -828,6 +911,11 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
return '';
}
Future<Map<String,dynamic>> queryNewLocalNote() async {
final result = await SqlManager.queryLocalNote(bookId: int.parse(bookId), chapterId: int.parse(chapterId));
return result;
}
// 查询本地划线高亮笔记
void queryLocalNote() async {
final result = await SqlManager.queryLocalNote(bookId: int.parse(bookId), chapterId: int.parse(chapterId));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论