Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
ba817a94
提交
ba817a94
authored
4月 02, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
离线逻辑
上级
9100bb68
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
118 行增加
和
71 行删除
+118
-71
global.dart
lib/global.dart
+1
-1
controller.dart
lib/pages/read_web/controller.dart
+26
-25
view.dart
lib/pages/read_web/view.dart
+56
-36
view_offline.dart
lib/pages/read_web/view_offline.dart
+2
-2
constants.dart
lib/utils/constants.dart
+2
-1
sql.dart
lib/utils/sql.dart
+31
-6
没有找到文件。
lib/global.dart
浏览文件 @
ba817a94
...
...
@@ -18,7 +18,7 @@ class Global {
// print('本地服务器已成功启动,根目录为: $documentRoot');
SqlManager
.
init
();
WidgetsBinding
.
instance
?.
addObserver
(
AppLifecycleObserver
());
//
WidgetsBinding.instance?.addObserver(AppLifecycleObserver());
await
Future
.
wait
([
// 配置存储
...
...
lib/pages/read_web/controller.dart
浏览文件 @
ba817a94
...
...
@@ -114,20 +114,7 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
_getChapters
();
netStatus
=
await
Tools
.
checkCurrentNetStatus
();
final
exist
=
await
_isExistFile
(
bookId
);
if
(!
netStatus
&&
exist
){
// 1、通过 chapterId 获取 对应离线的 html路径
String
toReadHtmlPath
=
await
getLocalReadHtml
(
chapterId
);
// 2、开始读书
read
(
toReadHtmlPath
);
// 获取当前 文件名称
currentHtmlName
=
path
.
basename
(
toReadHtmlPath
);
update
();
}
await
_isExistFile
(
bookId
);
super
.
onReady
();
}
...
...
@@ -750,6 +737,7 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
data
[
'chapter_name'
]
=
chapterName
;
// 1、根据当前章节id名称 获取内容
String
toReadHtmlPath
=
await
getLocalReadHtml
(
chapterId
);
currentHtmlName
=
path
.
basename
(
toReadHtmlPath
);
// 2、获取 离线文件的内容
final
enCodeContent
=
await
readHtmlFileContent
(
toReadHtmlPath
);
// 3、解密离线的内容
...
...
@@ -765,6 +753,7 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
String
upName
=
getChapterName
(
upId
);
upChapter
[
'name'
]
=
upName
;
upChapter
[
'id'
]
=
int
.
parse
(
upId
);
data
[
'up_chapter'
]
=
upChapter
;
}
// 5、获取下一章节信息
Map
<
String
,
dynamic
>
nextChapter
=
{};
...
...
@@ -776,20 +765,30 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
String
nextName
=
getChapterName
(
upId
);
nextChapter
[
'name'
]
=
nextName
;
nextChapter
[
'id'
]
=
int
.
parse
(
nextId
);
data
[
'next_chapter'
]
=
nextChapter
;
}
// 6、获取离线高亮和划线
final
Map
<
String
,
dynamic
>
temp
=
await
queryNewLocalNote
();
data
.
addAll
(
temp
);
data
[
'line_list'
]
=
temp
[
'line_list'
];
data
[
'color_line'
]
=
temp
[
'color_line'
];
// 7、 给前端参数
String
jsonStr
=
jsonEncode
(
data
);
webViewController
.
evaluateJavascript
(
source
:
'offlineCallbackInFlutterComponent(
$jsonStr
)'
);
Console
.
log
(
'callbackInFlutterComponent--------------------------------
$jsonStr
'
);
// webViewController.reload();
webViewController
.
evaluateJavascript
(
source
:
'callbackInFlutterComponent(
$jsonStr
)'
);
final
result
=
await
SqlManager
.
updateReadHistoryByBookId
(
int
.
parse
(
bookId
),
int
.
parse
(
chapterId
));
Console
.
log
(
'Sql----readread---存入数据库读到的章节----------------book_id:
$bookId
-----chapterId:
$chapterId
---------result:
$result
--'
);
// webViewController.reload();
}
// 获取上一章节或下一章节 id
Future
<
String
>
getChapterId
({
required
int
type
})
async
{
String
docPath
=
await
_
getDirectory
();
String
docPath
=
await
Tools
.
getDirectory
();
String
filePath
=
'
$docPath
/
$bookId
'
;
Directory
directory
=
Directory
(
filePath
);
// 获取目录下的所有文件
...
...
@@ -799,7 +798,7 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
if
(
type
==
0
){
findIndex
--;
if
(
findIndex
<
0
){
Toast
.
show
(
'前面已没有章节'
);
//
Toast.show('前面已没有章节');
// 已到最前
return
''
;
}
...
...
@@ -920,29 +919,31 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
void
queryLocalNote
()
async
{
final
result
=
await
SqlManager
.
queryLocalNote
(
bookId:
int
.
parse
(
bookId
),
chapterId:
int
.
parse
(
chapterId
));
Console
.
log
(
'前端-----------queryLocalNote---------------------
$result
'
);
webViewController
.
evaluateJavascript
(
source
:
'querySuccessCallBack(
$result
)'
);
//
webViewController.evaluateJavascript(source: 'querySuccessCallBack($result)');
}
// 本地添加划线高亮笔记
void
addLocalNote
(
Map
<
String
,
dynamic
>
data
)
async
{
data
[
'book_id'
]
=
int
.
parse
(
bookId
);
data
[
'chapter_id'
]
=
int
.
parse
(
chapterId
);
// data['del'] = 0;
final
result
=
await
SqlManager
.
addLocalNote
(
data
);
Console
.
log
(
'前端-----------addLocalNote---------------------
$result
'
);
webViewController
.
evaluateJavascript
(
source
:
'addSuccessCallBack(
$result
)'
);
}
// 本地删除划线高亮笔记
void
delLocalNote
({
required
int
id
})
async
{
final
result
=
await
SqlManager
.
delLocalNote
(
id:
id
);
void
delLocalNote
({
required
int
noteId
,
required
int
id
})
async
{
final
result
=
await
SqlManager
.
delLocalNote
(
noteId:
noteId
,
id:
id
);
Console
.
log
(
'前端-----------delLocalNote---------------------
$result
'
);
webViewController
.
evaluateJavascript
(
source
:
'delSuccessCallBack(
$result
)'
);
//
webViewController.evaluateJavascript(source: 'delSuccessCallBack($result)');
}
// 修改本地划线高亮笔记
void
updateLocalNote
({
required
int
id
,
required
Map
<
String
,
dynamic
>
data
})
async
{
final
result
=
await
SqlManager
.
updateLocalNote
(
id:
id
,
data:
data
);
void
updateLocalNote
({
required
int
notesId
,
required
int
id
,
required
Map
<
String
,
dynamic
>
data
})
async
{
final
result
=
await
SqlManager
.
updateLocalNote
(
notesId:
notesId
,
id:
id
,
data:
data
);
Console
.
log
(
'前端-----------updateLocalNote---------------------
$result
'
);
webViewController
.
evaluateJavascript
(
source
:
'updateSuccessCallBack(
$result
)'
);
//
webViewController.evaluateJavascript(source: 'updateSuccessCallBack($result)');
}
//获取存储目录
Future
<
String
>
_getDirectory
()
async
{
// getTemporaryDirectory
...
...
lib/pages/read_web/view.dart
浏览文件 @
ba817a94
...
...
@@ -45,15 +45,15 @@ class _ReadPageState extends State<ReadPage> {
),
centerTitle:
false
,
actions:
[
//
GestureDetector(
//
onTap: () {
//
readController.getBookDown();
//
},
//
child: Text(
//
readController.existDownFile == true?'':'离线阅读',
//
style: TextStyle(
//
fontSize: 14.w, color: Colours.c3),
//
))
GestureDetector
(
onTap:
()
{
readController
.
getBookDown
();
},
child:
Text
(
readController
.
existDownFile
==
true
?
''
:
'离线阅读'
,
style:
TextStyle
(
fontSize:
14
.
w
,
color:
Colours
.
c3
),
))
],
),
resizeToAvoidBottomInset:
false
,
...
...
@@ -72,8 +72,8 @@ class _ReadPageState extends State<ReadPage> {
children:
[
InAppWebView
(
initialUrlRequest:
URLRequest
(
// url: Uri.parse(kReadBook),
url:
readController
.
localHtml5Path
.
isNotEmpty
?
WebUri
.
uri
(
Uri
.
parse
(
readController
.
localHtml5Path
)):
WebUri
.
uri
(
Uri
.
parse
(
kReadBook
))
url:
readController
.
existDownFile
&&
!
readController
.
netStatus
?
WebUri
.
uri
(
Uri
.
parse
(
kReadTestUnderLineBook
)):
WebUri
.
uri
(
Uri
.
parse
(
kReadBook
))
//
url: readController.localHtml5Path.isNotEmpty?WebUri.uri(Uri.parse(readController.localHtml5Path)): WebUri.uri(Uri.parse(kReadBook))
// url: Uri.parse("/storage/emulated/0/Android/data/com.zijin.book.flutter_book/files/174/7-325.html"),
),
initialSettings:
InAppWebViewSettings
(
...
...
@@ -105,14 +105,18 @@ class _ReadPageState extends State<ReadPage> {
// CustomToast.dismiss();
// flutter 主动给 js 传参数
Map
<
String
,
dynamic
>
param
=
{
'book_id'
:
readController
.
bookId
,
'chapter_id'
:
readController
.
chapterId
,
'token'
:
UserStore
.
to
.
token
//
'book_id': readController.bookId,
//
'chapter_id': readController.chapterId,
//
'token':UserStore.to.token
};
String
str
=
'
$kServerUrl
,
${readController.bookId}
,
${readController.chapterId}
,
${UserStore.to.token}
,
${readController.noteId}
,
${readController.sModel.bookId =='0'?'':readController.sModel.combinedContent}
'
;
Console
.
log
(
'传给前端的参数--------------------------------
$str
'
);
controller
.
evaluateJavascript
(
source
:
'callbackInFlutterComponent("
$str
");'
);
// Console.log('传给前端的参数--------------------------------$str');
// String jsonStr = jsonEncode(param);
// controller.evaluateJavascript(source: 'callbackInFlutterComponent($jsonStr)');
if
(
readController
.
existDownFile
&&
!
readController
.
netStatus
){
readController
.
getOffLineInfo
();
}
// 添加单击事件
controller
.
evaluateJavascript
(
source
:
'''
document.addEventListener('
click
', function() {
...
...
@@ -205,6 +209,8 @@ class _ReadPageState extends State<ReadPage> {
ChapterModel
chapterModel
=
ChapterModel
(
id:
int
.
parse
(
chapterId
),
name:
chapterName
);
// readController.setChapterInfo(id: chapterId, name: chapterName ?? '');
readController
.
selectChapter
(
chapterModel
);
readController
.
getOffLineInfo
();
Console
.
log
(
'监听 上一节 下一节------------------------------------------------
$args
'
);
});
...
...
@@ -278,40 +284,54 @@ class _ReadPageState extends State<ReadPage> {
// 添加高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineAddNoteCallBack'
,
callback:
(
args
){
Map
<
String
,
dynamic
>
data
=
{};
Console
.
log
(
'添加笔记回调------------------------------------------
${args[0]}
'
);
Map
<
String
,
dynamic
>
data
=
args
[
0
];
readController
.
addLocalNote
(
data
);
});
// 删除高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineDelNoteCallBack'
,
callback:
(
args
){
Console
.
log
(
'删除笔记回调------------------------------------------
${args[0]}
'
);
Map
<
String
,
dynamic
>
data
=
args
[
0
];
int
notesId
=
data
[
'notes_id'
];
int
id
=
0
;
readController
.
delLocalNote
(
id:
id
);
if
(
data
.
keys
.
contains
(
'id'
)){
id
=
data
[
'id'
];
}
readController
.
delLocalNote
(
noteId:
notesId
,
id:
id
);
});
// 更新高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineUpdateNoteCallBack'
,
callback:
(
args
){
Console
.
log
(
'更新笔记回调------------------------------------------
${args[0]}
'
);
// int id = 0;
// Map<String, dynamic> data = {};
Map
<
String
,
dynamic
>
data
=
args
[
0
];
int
notesId
=
data
[
'notes_id'
];
int
id
=
0
;
Map
<
String
,
dynamic
>
data
=
{};
readController
.
updateLocalNote
(
id:
id
,
data:
data
);
if
(
data
.
keys
.
contains
(
'id'
)){
id
=
data
[
'id'
];
}
readController
.
updateLocalNote
(
notesId:
notesId
,
id:
id
,
data:
data
);
});
// 查询高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineQueryNoteCallBack'
,
callback:
(
args
){
});
// 上一节下一节
controller
.
addJavaScriptHandler
(
handlerName:
'offlineReadNoteCallBack'
,
callback:
(
args
){
int
type
=
0
;
// 上一节
if
(
type
==
0
){
readController
.
readChapter
(
type:
0
);
}
// 下一节
else
{
readController
.
readChapter
(
type:
1
);
}
// controller.addJavaScriptHandler(handlerName: 'offlineQueryNoteCallBack', callback: (args){
//
// });
});
// // 上一节下一节
// controller.addJavaScriptHandler(handlerName: 'offlineReadNoteCallBack', callback: (args){
// int type = 0;
// // 上一节
// if (type == 0){
// readController.readChapter(type: 0);
// }
// // 下一节
// else{
// readController.readChapter(type: 1);
// }
//
// });
},
),
...
...
lib/pages/read_web/view_offline.dart
浏览文件 @
ba817a94
...
...
@@ -240,14 +240,14 @@ class _ReadOfflinePageState extends State<ReadPage> {
// 删除高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineDelNoteCallBack'
,
callback:
(
args
){
int
id
=
0
;
readController
.
delLocalNote
(
id:
id
);
//
readController.delLocalNote(id: id);
});
// 更新高亮划线笔记
controller
.
addJavaScriptHandler
(
handlerName:
'offlineUpdateNoteCallBack'
,
callback:
(
args
){
int
id
=
0
;
Map
<
String
,
dynamic
>
data
=
{};
readController
.
updateLocalNote
(
id:
id
,
data:
data
);
//
readController.updateLocalNote(id: id,data: data);
});
// 查询高亮划线笔记
...
...
lib/utils/constants.dart
浏览文件 @
ba817a94
...
...
@@ -21,7 +21,8 @@ const String kUserRechargeAgreement = '/html/agreement/rec_agreement.html';
// 错题详情页 html
const
String
kUserWrongDes
=
'
$kHtmlBaseServer
/evaluating_wrong.html'
;
// 阅读页 html
const
String
kReadTestUnderLineBook
=
'
$kHtmlBaseServer
/read-unline.html'
;
String
kReadTestUnderLineBook
=
'
$kHtmlBaseServer
/read_unline.html?t=
${DateTime.now().millisecondsSinceEpoch}
'
;
const
String
kReadBook
=
'
$kHtmlBaseServer
/read.html'
;
// 答题页
const
String
kAnswer
=
'
$kHtmlBaseServer
/evaluating.html'
;
...
...
lib/utils/sql.dart
浏览文件 @
ba817a94
...
...
@@ -32,9 +32,9 @@ class SqlManager {
"types INTEGER, "
"book_id INTEGER, "
"chapter_id INTEGER, "
"no
de
_id INTEGER, "
"no
tes
_id INTEGER, "
"is_open INTEGER, "
"del INTEGER, "
"del INTEGER
DEFAULT 0
, "
"color TEXT, "
"content TEXT, "
"upload INTEGER, "
...
...
@@ -72,14 +72,16 @@ class SqlManager {
// 划线
List
<
Map
<
String
,
dynamic
>>?
lineResult
=
await
db
?.
query
(
'members_book_notes'
,
columns:
[
'types'
,
'chapter_id'
,
'positioning'
,
'content'
,
'color'
],
where:
'book_id = ? and chapter_id = ? and types = ? and del = ?'
,
whereArgs:
[
bookId
,
chapterId
,
2
,
0
],
whereArgs:
[
bookId
,
chapterId
,
1
,
0
],
);
// 高亮
List
<
Map
<
String
,
dynamic
>>?
colorResult
=
await
db
?.
query
(
'members_book_notes'
,
columns:
[
'types'
,
'chapter_id'
,
'positioning'
,
'content'
,
'color'
],
where:
'book_id = ? and chapter_id = ? and types = ? and del = ?'
,
whereArgs:
[
bookId
,
chapterId
,
3
,
0
],
whereArgs:
[
bookId
,
chapterId
,
2
,
0
],
);
returnMap
[
'line_list'
]
=
lineResult
;
returnMap
[
'color_line'
]
=
colorResult
;
...
...
@@ -99,8 +101,9 @@ class SqlManager {
}
// 删除划线高亮笔记
static
Future
<
int
>
delLocalNote
({
required
int
id
})
async
{
static
Future
<
int
>
delLocalNote
({
required
int
noteId
,
required
int
id
})
async
{
Database
?
db
=
await
SqlManager
.
getCurrentDatabase
();
if
(
noteId
==
0
){
final
result
=
await
db
?.
update
(
'members_book_notes'
,
{
'del'
:
1
},
...
...
@@ -109,10 +112,22 @@ class SqlManager {
);
return
result
??
0
;
}
else
{
final
result
=
await
db
?.
update
(
'members_book_notes'
,
{
'del'
:
1
},
where:
'notes_id = ?'
,
whereArgs:
[
noteId
],
);
return
result
??
0
;
}
}
// 修改划线高亮笔记
static
Future
<
int
>
updateLocalNote
({
required
int
id
,
required
Map
<
String
,
dynamic
>
data
})
async
{
static
Future
<
int
>
updateLocalNote
({
required
int
notesId
,
required
int
id
,
required
Map
<
String
,
dynamic
>
data
})
async
{
Database
?
db
=
await
SqlManager
.
getCurrentDatabase
();
if
(
notesId
==
0
){
final
result
=
await
db
?.
update
(
'members_book_notes'
,
data
,
...
...
@@ -121,6 +136,16 @@ class SqlManager {
);
return
result
??
0
;
}
else
{
final
result
=
await
db
?.
update
(
'members_book_notes'
,
data
,
where:
'notes_id = ?'
,
whereArgs:
[
notesId
],
);
return
result
??
0
;
}
}
// 查询所有没有上传的数据
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论