Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
ebcbb949
提交
ebcbb949
authored
1月 11, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
搜索界面接口调试与界面修正
上级
3b9e556c
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
104 行增加
和
28 行删除
+104
-28
common.dart
lib/apis/common.dart
+47
-0
controller.dart
lib/pages/search/controller.dart
+39
-11
index.dart
lib/pages/search/index.dart
+2
-0
view.dart
lib/pages/search/view.dart
+5
-5
history.dart
lib/pages/search/widgets/history.dart
+11
-12
没有找到文件。
lib/apis/common.dart
浏览文件 @
ebcbb949
...
...
@@ -85,5 +85,51 @@ abstract class CommonAPI {
return
false
;
}
/// 6、清除搜索记录
///
static
Future
<
bool
>
clear
()
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/book/Information/serachDel'
,
params:
{},
);
if
(
result
.
data
is
Map
&&
result
.
data
[
'is_success'
]
==
1
){
return
true
;
}
return
false
;
}
/// 7、搜索历史记录
///
static
Future
<
List
<
String
>>
searchRecords
()
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/book/Information/serachRecord'
,
params:
{},
);
if
(
result
.
data
is
!
Map
&&
result
.
data
[
'list'
]
is
!
List
)
return
[];
return
List
.
generate
(
result
.
data
[
'list'
].
length
,
(
index
){
return
result
.
data
[
'list'
][
index
][
'name'
];
});
}
/// 8、搜索书籍
static
Future
<
List
<
CourseModel
>>
searchBooks
({
int
page
=
1
,
int
limit
=
20
,
required
String
keyWord
})
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/book/Information/searchBook'
,
params:
{
'currentPage'
:
page
,
'pageSize'
:
limit
,
'keyword'
:
keyWord
},
);
if
(
result
.
data
is
!
Map
&&
result
.
data
[
'list'
]
is
!
List
)
return
[];
return
List
.
generate
(
result
.
data
[
'list'
].
length
,
(
index
){
return
CourseModel
.
fromJson
(
result
.
data
[
'list'
][
index
]);
});
}
}
\ No newline at end of file
lib/pages/search/controller.dart
浏览文件 @
ebcbb949
...
...
@@ -4,15 +4,47 @@ class SearchController extends GetxController {
late
TextEditingController
searchController
=
TextEditingController
();
final
int
_maxStorageNum
=
10
;
// 搜索记录数组
List
<
String
>
records
=
[];
// 书籍数组
List
<
CourseModel
>
books
=
[];
late
List
<
String
>
searchList
;
@override
void
onInit
()
{
searchList
=
_getHistory
();
super
.
onInit
();
void
onReady
()
{
_getSearchRecords
();
super
.
onReady
();
}
@override
void
onClose
()
{
searchController
.
dispose
();
super
.
onClose
();
}
/// 获取搜索记录
void
_getSearchRecords
()
async
{
records
=
await
CommonAPI
.
searchRecords
();
update
();
}
/// 清除搜索记录
void
clear
()
async
{
bool
result
=
await
CommonAPI
.
clear
();
if
(
result
)
{
_getSearchRecords
();
}
}
/// 搜索书籍
void
search
()
async
{
books
=
await
CommonAPI
.
searchBooks
(
keyWord:
searchController
.
text
);
_getSearchRecords
();
update
();
}
/// 本地搜索历史
/*
///获取搜索关键字数据
List<String> _getHistory(){
List <String>historys = [];
...
...
@@ -61,12 +93,9 @@ class SearchController extends GetxController {
update();
}
*/
@override
void
onClose
()
{
searchController
.
dispose
();
super
.
onClose
();
}
}
\ No newline at end of file
lib/pages/search/index.dart
浏览文件 @
ebcbb949
...
...
@@ -7,6 +7,8 @@ import 'package:get/get.dart';
import
'package:get/get_state_manager/src/simple/get_controllers.dart'
;
import
'package:go_router/go_router.dart'
;
import
'../../apis/index.dart'
;
import
'../../models/index.dart'
;
import
'../../services/index.dart'
;
import
'../../theme.dart'
;
import
'../../utils/index.dart'
;
...
...
lib/pages/search/view.dart
浏览文件 @
ebcbb949
...
...
@@ -17,7 +17,7 @@ class _SearchPageState extends State<SearchPage> {
automaticallyImplyLeading:
false
,
titleSpacing:
0
,
title:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
AppTheme
.
margin
),
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
AppTheme
.
margin
),
child:
CustomInputSearch
(
controller:
controller
.
searchController
,
readOnly:
false
,
...
...
@@ -26,7 +26,7 @@ class _SearchPageState extends State<SearchPage> {
// context.pushNamed(Routes.msgs);
},
onEditingComplete:
(){
controller
.
s
aveHistory
();
controller
.
s
earch
();
},
),
),
...
...
@@ -36,14 +36,14 @@ class _SearchPageState extends State<SearchPage> {
context
.
pop
();
},
child:
Container
(
padding:
EdgeInsets
.
only
(
left:
10
,
top:
10
,
bottom:
10
),
child:
Text
(
'取消'
,
style:
TextStyle
(
fontSize:
14
,
height:
1.5
,
color:
Colours
.
c3
),),
padding:
const
EdgeInsets
.
only
(
left:
10
,
top:
10
,
bottom:
10
),
child:
const
Text
(
'取消'
,
style:
TextStyle
(
fontSize:
14
,
height:
1.5
,
color:
Colours
.
c3
),),
// color: Colors.red,
),
)
],
),
body:
BuildHistory
(),
body:
BuildHistory
(
controller:
controller
),
),
);
}
...
...
lib/pages/search/widgets/history.dart
浏览文件 @
ebcbb949
part of
search
;
class
BuildHistory
extends
StatefulWidget
{
const
BuildHistory
({
super
.
key
});
final
SearchController
controller
;
const
BuildHistory
({
Key
?
key
,
required
this
.
controller
,
})
:
super
(
key:
key
);
@override
State
<
BuildHistory
>
createState
()
=>
_BuildHistoryState
();
...
...
@@ -9,13 +14,9 @@ class BuildHistory extends StatefulWidget {
class
_BuildHistoryState
extends
State
<
BuildHistory
>
{
// List<String> _searchList = [];
@override
Widget
build
(
BuildContext
context
)
{
return
GetBuilder
<
SearchController
>(
init:
SearchController
(),
builder:
(
controller
)=>
Container
(
return
Container
(
margin:
const
EdgeInsets
.
only
(
left:
13
,
top:
18
),
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
...
...
@@ -26,10 +27,10 @@ class _BuildHistoryState extends State<BuildHistory> {
const
Text
(
'搜索历史'
,
style:
TextStyle
(
fontSize:
14
,
height:
1.5
,
color:
Colours
.
c3
,
fontWeight:
Fonts
.
medium
),),
GestureDetector
(
onTap:
(){
controller
.
clearHistory
();
widget
.
controller
.
clear
();
},
child:
Container
(
padding:
EdgeInsets
.
all
(
10
),
padding:
const
EdgeInsets
.
all
(
10
),
// width: 10,
// height: 10,
// color: Colors.cyan,
...
...
@@ -45,19 +46,17 @@ class _BuildHistoryState extends State<BuildHistory> {
runSpacing:
10
,
alignment:
WrapAlignment
.
start
,
runAlignment:
WrapAlignment
.
start
,
children:
_buildItem
(
controller
.
searchList
),
children:
_buildItem
(
widget
.
controller
.
records
),
),
],
),
),
);
}
List
<
Widget
>
_buildItem
(
List
<
String
>
searchList
){
print
(
searchList
);
if
(
searchList
==
null
||
searchList
.
isEmpty
){
List
<
Widget
>
list
=
[
Container
(
const
SizedBox
(
width:
0
,
height:
0
,
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论