Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
9ec70060
提交
9ec70060
authored
3月 06, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
数据库操作添加日志
上级
3083522e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
40 行增加
和
19 行删除
+40
-19
controller.dart
lib/pages/book_detail/controller.dart
+2
-1
controller.dart
lib/pages/library/controller.dart
+1
-1
controller.dart
lib/pages/read_web/controller.dart
+10
-5
sql.dart
lib/utils/sql.dart
+26
-11
tools.dart
lib/utils/tools.dart
+1
-1
没有找到文件。
lib/pages/book_detail/controller.dart
浏览文件 @
9ec70060
...
...
@@ -84,7 +84,8 @@ class BookDetailController extends GetxController with GetSingleTickerProviderSt
void
getBookDetails
()
async
{
bookDetails
=
await
LibraryAPI
.
details
(
bookId:
bookId
);
// 将阅读最后章节写入到数据库
SqlManager
.
updateReadHistoryByBookId
(
int
.
parse
(
bookId
),
bookDetails
.
chapterId
!.
toInt
());
final
result
=
await
SqlManager
.
updateReadHistoryByBookId
(
int
.
parse
(
bookId
),
bookDetails
.
chapterId
!.
toInt
());
Console
.
log
(
'Sql-------存入数据库读到的章节----------------book_id:
$bookId
-----chapterId:
${bookDetails.chapterId!.toInt()}
---------result:
$result
--'
);
update
();
}
/// 收藏 与 取消收藏
...
...
lib/pages/library/controller.dart
浏览文件 @
9ec70060
...
...
@@ -246,7 +246,7 @@ class LibraryController extends GetxController with GetTickerProviderStateMixin{
void
upload
()
async
{
List
<
Map
<
String
,
dynamic
>>
data
=
await
SqlManager
.
queryNoUploadData
();
Console
.
log
(
'
查询到的数据-----------------------------
-----------------------
$data
'
);
Console
.
log
(
'
Sql-----查询到的数据
-----------------------
$data
'
);
if
(
data
.
isNotEmpty
){
for
(
Map
<
String
,
dynamic
>
temp
in
data
){
...
...
lib/pages/read_web/controller.dart
浏览文件 @
9ec70060
...
...
@@ -103,10 +103,13 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
netStatus
=
await
Tools
.
checkCurrentNetStatus
();
final
exist
=
await
_isExistFile
(
bookId
);
// chapterId = await SqlManager.queryReadHistoryByBookId(int.parse(bookId));
// Console.log('数据库中得到最后阅读的章节----------------------$chapterId----------');
if
(!
netStatus
&&
exist
){
// 1、从数据库中获取读到那个章节
chapterId
=
await
SqlManager
.
queryReadHistoryByBookId
(
int
.
parse
(
bookId
));
Console
.
log
(
'Sql-----------数据库中得到最后阅读的章节----------------------
$chapterId
----------'
);
chapterName
=
getChapterName
(
chapterId
);
// 2、通过 chapterId 获取 对应离线的 html路径
String
toReadHtmlPath
=
await
getLocalReadHtml
(
chapterId
);
...
...
@@ -607,24 +610,26 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
// 从缓存中获取 ZIP 文件
var
file
=
await
DefaultCacheManager
().
getSingleFile
(
url
);
if
(
file
!=
null
)
{
Toast
.
show
(
'离线成功'
);
// 读取 ZIP 文件内容
Uint8List
bytes
=
await
file
.
readAsBytes
();
// 解压缩 ZIP 文件
Archive
archive
=
ZipDecoder
().
decodeBytes
(
bytes
);
// 获取设备上的临时目录
Directory
?
tempDir
=
await
getExternalStorage
Directory
();
String
tempPath
=
await
Tools
.
get
Directory
();
// 将解压缩后的文件保存到临时目录中
for
(
var
file
in
archive
)
{
if
(
file
.
isFile
)
{
String
fileName
=
file
.
name
;
String
filePath
=
'
$
{tempDir!.path}
/
$bookId
/
$fileName
'
;
String
filePath
=
'
$
tempPath
/
$bookId
/
$fileName
'
;
File
(
filePath
)
..
createSync
(
recursive:
true
)
..
writeAsBytesSync
(
file
.
content
as
List
<
int
>);
(
'解压缩文件:
$fileName
,保存路径:
$filePath
'
);
Console
.
log
(
'解压缩文件:
$fileName
,保存路径:
$filePath
'
);
}
}
Toast
.
show
(
'离线成功'
);
final
exit
=
await
_isExistFile
(
bookId
);
update
();
}
else
{
Console
.
log
(
'未找到缓存中的文件或文件不存在'
);
...
...
@@ -651,7 +656,7 @@ class ReadController extends FullLifeCycleController with GetSingleTickerProvide
}
Future
<
String
>
getLocalReadHtml
(
String
chapterId
)
async
{
String
docPath
=
await
_
getDirectory
();
String
docPath
=
await
Tools
.
getDirectory
();
String
filePath
=
'
$docPath
/
$bookId
'
;
Directory
directory
=
Directory
(
filePath
);
// 获取目录下的所有文件
...
...
lib/utils/sql.dart
浏览文件 @
9ec70060
...
...
@@ -16,7 +16,7 @@ class SqlManager {
var
databasesPath
=
await
getDatabasesPath
();
// var databasesPath = await Tools.getDirectory();
String
dbName
=
_name
;
Console
.
log
(
'databasesPath---------
$databasesPath
'
);
Console
.
log
(
'
Sql-----------
databasesPath---------
$databasesPath
'
);
if
(
databasesPath
!=
null
)
{
String
path
=
databasesPath
+
dbName
;
if
(
Platform
.
isIOS
)
{
...
...
@@ -72,29 +72,44 @@ class SqlManager {
where:
'upload = ?'
,
whereArgs:
[
0
],
);
Console
.
log
(
'
更新数据---------------
----------------
$result
'
);
Console
.
log
(
'
Sql---------------更新数据
----------------
$result
'
);
}
// 根据 book_id 查询当前读到的 章节
static
Future
<
String
>
queryReadHistoryByBookId
(
int
bookId
)
async
{
List
<
Map
<
String
,
dynamic
>>
results
=
await
_database
!.
query
(
'read_history'
,
where:
'book_id = ?'
,
whereArgs:
[
bookId
],
);
return
results
.
isNotEmpty
?
results
.
first
[
'chapter_id'
]
:
0
;
return
results
.
isNotEmpty
?
results
.
first
[
'chapter_id'
]
.
toString
()
:
''
;
}
// 根据 book_id 写入当前读到的 章节
static
Future
<
int
>
updateReadHistoryByBookId
(
int
bookId
,
int
chapterId
)
async
{
final
result
=
await
_database
!.
update
(
'members_book_notes'
,
{
'chapter_id'
:
chapterId
},
where:
'book_id = ?'
,
whereArgs:
[
bookId
],
);
return
result
;
final
queryResult
=
await
queryReadHistoryByBookId
(
bookId
);
if
(
queryResult
.
isEmpty
){
Console
.
log
(
'Sql----------没有当前书籍的数据----------------------'
);
final
result
=
await
_database
!.
insert
(
'read_history'
,
{
'chapter_id'
:
chapterId
,
'book_id'
:
bookId
},
conflictAlgorithm:
ConflictAlgorithm
.
replace
,
);
Console
.
log
(
'Sql----------插入数据结果:
$result
----------------------'
);
return
result
;
}
else
{
Console
.
log
(
'Sql----------有当前书籍的数据----------------------'
);
final
result
=
await
_database
!.
update
(
'read_history'
,
{
'chapter_id'
:
chapterId
},
where:
'book_id = ?'
,
whereArgs:
[
bookId
],
);
Console
.
log
(
'Sql----------更新数据结果:
$result
----------------------'
);
return
result
;
}
}
...
...
lib/utils/tools.dart
浏览文件 @
9ec70060
...
...
@@ -38,7 +38,7 @@ abstract class Tools {
static
Future
<
String
>
getDirectory
()
async
{
// getTemporaryDirectory
final
directory
=
await
get
ApplicationSupport
Directory
();
final
directory
=
await
get
ExternalStorage
Directory
();
return
directory
!.
path
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论