Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
book-app
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
book-app
Commits
7233760d
提交
7233760d
authored
1月 12, 2024
作者:
yueweilu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
书架界面 接口调试与数据绑定
上级
6b193aa0
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
204 行增加
和
33 行删除
+204
-33
shop.dart
lib/apis/shop.dart
+60
-2
course.dart
lib/models/course.dart
+36
-2
controller.dart
lib/pages/book_shop/controller.dart
+66
-2
index.dart
lib/pages/book_shop/index.dart
+6
-0
view.dart
lib/pages/book_shop/view.dart
+23
-15
book.dart
lib/pages/book_shop/widgets/book.dart
+12
-11
controller.dart
lib/pages/course/controller.dart
+1
-1
没有找到文件。
lib/apis/shop.dart
浏览文件 @
7233760d
part of
apis
;
\ No newline at end of file
part of
apis
;
abstract
class
ShopAPI
{
/// 1、加入书架
///
static
Future
<
bool
>
addCart
({
required
String
bookId
,
})
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/orders/Orders/addCart'
,
params:
{
'book_id'
:
bookId
,
},
);
if
(
result
.
data
is
Map
&&
result
.
data
[
'is_success'
]
==
1
){
return
true
;
}
return
false
;
}
/// 2、删除书架
///
static
Future
<
bool
>
delCart
({
required
String
cartId
,
})
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/orders/Orders/delCart'
,
params:
{
'cart_id'
:
cartId
,
},
);
if
(
result
.
data
is
Map
&&
result
.
data
[
'is_success'
]
==
1
){
return
true
;
}
return
false
;
}
/// 3、书架列表
static
Future
<
List
<
CourseModel
>>
cart
({
int
page
=
1
,
int
limit
=
10
,
})
async
{
final
result
=
await
HttpService
.
to
.
post
(
'/v1/orders/Orders/getCartListAll'
,
params:
{
'page'
:
page
,
'pageSize'
:
limit
,
},
);
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/models/course.dart
浏览文件 @
7233760d
...
...
@@ -23,7 +23,15 @@ class CourseModel {
this
.
introduction
,
this
.
readNum
,
this
.
isCollection
,
this
.
collectionId
this
.
collectionId
,
/// 购物车列表需要参数
this
.
price
,
this
.
vipPrice
,
this
.
status
,
this
.
cartId
///
});
CourseModel
.
fromJson
(
dynamic
json
)
{
...
...
@@ -53,6 +61,14 @@ class CourseModel {
num
?
isCollection
;
num
?
collectionId
;
/// 购物车列表需要参数
String
?
price
;
String
?
vipPrice
;
num
?
status
;
num
?
cartId
;
///
int
get
type
{
if
(
progress
==
'0.00%'
){
...
...
@@ -87,6 +103,13 @@ class CourseModel {
num
?
isCollection
,
num
?
collectionId
,
/// 购物车列表需要参数
String
?
price
,
String
?
vipPrice
,
num
?
status
,
num
?
cartId
,
///
})
=>
CourseModel
(
bookId:
bookId
??
this
.
bookId
,
bookName:
bookName
??
this
.
bookName
,
authors:
authors
??
this
.
authors
,
...
...
@@ -98,7 +121,13 @@ class CourseModel {
introduction:
introduction
??
this
.
introduction
,
readNum:
readNum
??
this
.
readNum
,
isCollection:
isCollection
??
this
.
isCollection
,
collectionId:
collectionId
??
this
.
collectionId
collectionId:
collectionId
??
this
.
collectionId
,
/// 购物车列表需要参数
price:
price
??
this
.
price
,
vipPrice:
vipPrice
??
this
.
vipPrice
,
status:
status
??
this
.
status
,
cartId:
cartId
??
this
.
cartId
,
///
);
Map
<
String
,
dynamic
>
toJson
()
{
...
...
@@ -115,6 +144,11 @@ class CourseModel {
map
[
'is_collection'
]
=
isCollection
;
map
[
'collection_id'
]
=
collectionId
;
map
[
'introduction'
]
=
introduction
;
map
[
'price'
]
=
price
;
map
[
'vip_price'
]
=
vipPrice
;
map
[
'status'
]
=
status
;
map
[
'cart_id'
]
=
cartId
;
return
map
;
}
...
...
lib/pages/book_shop/controller.dart
浏览文件 @
7233760d
part of
book_shop
;
\ No newline at end of file
part of
book_shop
;
class
BookshopController
extends
GetxController
{
final
EasyRefreshController
refreshController
=
EasyRefreshController
(
controlFinishLoad:
true
,
controlFinishRefresh:
true
,
);
// 书架数组
List
<
CourseModel
>
carts
=
[];
final
int
_limit
=
10
;
int
_page
=
1
;
bool
_noMore
=
false
;
@override
void
onClose
()
{
refreshController
.
dispose
();
super
.
onClose
();
}
/// 获取课程内图书列表
Future
<
void
>
_getCart
([
bool
isRefresh
=
false
])
async
{
if
(
isRefresh
)
_page
=
1
;
// 网路请求
final
result
=
await
ShopAPI
.
cart
(
page:
_page
,
limit:
_limit
);
// 如果是刷新 清理数据
if
(
isRefresh
)
carts
.
clear
();
carts
.
addAll
(
result
);
_page
++;
_noMore
=
result
.
length
<
_limit
;
update
();
}
void
onRefresh
()
async
{
try
{
await
_getCart
(
true
);
refreshController
.
finishRefresh
(
IndicatorResult
.
success
);
refreshController
.
resetFooter
();
}
catch
(
error
)
{
refreshController
.
finishRefresh
(
IndicatorResult
.
fail
);
}
}
void
onLoading
()
async
{
if
(
_noMore
)
{
refreshController
.
finishLoad
(
IndicatorResult
.
noMore
);
return
;
}
try
{
await
_getCart
();
refreshController
.
finishLoad
();
}
catch
(
error
)
{
refreshController
.
finishLoad
(
IndicatorResult
.
fail
);
}
}
}
\ No newline at end of file
lib/pages/book_shop/index.dart
浏览文件 @
7233760d
library
book_shop
;
import
'package:easy_refresh/easy_refresh.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_book/utils/index.dart'
;
import
'package:flutter_book/widgets/index.dart'
;
import
'package:get/get.dart'
;
import
'package:go_router/go_router.dart'
;
import
'../../apis/index.dart'
;
import
'../../models/index.dart'
;
import
'../../routes/index.dart'
;
import
'../../theme.dart'
;
...
...
lib/pages/book_shop/view.dart
浏览文件 @
7233760d
...
...
@@ -10,22 +10,30 @@ class BookShopPage extends StatefulWidget {
class
_BookShopPageState
extends
State
<
BookShopPage
>
{
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'书架'
),
),
body:
Column
(
children:
[
Expanded
(
child:
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
){
return
const
BookCell
();
},
itemCount:
2
,
return
GetBuilder
<
BookshopController
>(
init:
BookshopController
(),
builder:
(
controller
)
=>
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'书架'
),
),
body:
Column
(
children:
[
Expanded
(
child:
CustomPullScrollView
(
controller:
controller
.
refreshController
,
onRefresh:
controller
.
onRefresh
,
onLoading:
controller
.
onLoading
,
child:
ListView
.
builder
(
itemBuilder:
(
BuildContext
context
,
int
index
){
return
BookCell
(
model:
controller
.
carts
[
index
],);
},
itemCount:
controller
.
carts
.
length
,
),
),
),
),
createCounter
()
]
,
createCounter
()
],
)
,
),
);
}
...
...
lib/pages/book_shop/widgets/book.dart
浏览文件 @
7233760d
...
...
@@ -7,10 +7,11 @@ enum BookCellType {
class
BookCell
extends
StatelessWidget
{
final
BookCellType
?
type
;
final
CourseModel
?
model
;
const
BookCell
({
super
.
key
,
this
.
type
=
BookCellType
.
normal
,
this
.
model
});
@override
...
...
@@ -21,10 +22,10 @@ class BookCell extends StatelessWidget {
color:
Colors
.
white
,
boxShadow:
[
BoxShadow
(
color:
Color
(
0xFFC7C7C7
).
withOpacity
(
0.5
),
color:
const
Color
(
0xFFC7C7C7
).
withOpacity
(
0.5
),
spreadRadius:
2
,
blurRadius:
5
,
offset:
Offset
(
3
,
0
),
// changes the position of the shadow
offset:
const
Offset
(
3
,
0
),
// changes the position of the shadow
),
]
),
...
...
@@ -49,10 +50,10 @@ class BookCell extends StatelessWidget {
borderRadius:
BorderRadius
.
circular
(
3
),
boxShadow:
[
BoxShadow
(
color:
Color
(
0xFF707070
).
withOpacity
(
0.5
),
color:
const
Color
(
0xFF707070
).
withOpacity
(
0.5
),
spreadRadius:
2
,
blurRadius:
5
,
offset:
Offset
(
3
,
0
),
// changes the position of the shadow
offset:
const
Offset
(
3
,
0
),
// changes the position of the shadow
),
]
),
...
...
@@ -60,7 +61,7 @@ class BookCell extends StatelessWidget {
height:
86
,
width:
72
,
child:
Container
(
padding:
EdgeInsets
.
all
(
2
),
padding:
const
EdgeInsets
.
all
(
2
),
child:
Container
(
color:
Colors
.
cyan
,
),
...
...
@@ -74,19 +75,19 @@ class BookCell extends StatelessWidget {
Expanded
(
child:
Container
(
padding:
const
EdgeInsets
.
only
(
top:
12
,
bottom:
10
),
child:
const
Column
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
Text
(
'一想到还有95%的问题留给人类,我就放一想到还有95%的问题留给人类,我就放一想到还有95%的问题留给人类,我就放'
,
style:
TextStyle
(
fontSize:
13
,
fontWeight:
FontWeight
.
w500
,
color:
Color
(
0xFF333333
)
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
SizedBox
(
height:
5
,),
Text
(
'威廉·莎士比亚'
,
style:
TextStyle
(
fontSize:
11
,
fontWeight:
FontWeight
.
w400
,
color:
Color
(
0xFF999999
)
)),
Text
(
model
!=
null
?
model
!.
bookName
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
13
,
fontWeight:
Fonts
.
medium
,
color:
Colours
.
c3
),
maxLines:
2
,
overflow:
TextOverflow
.
ellipsis
,),
const
SizedBox
(
height:
5
,),
Text
(
model
!=
null
?
model
!.
authors
.
toString
():
''
,
style:
const
TextStyle
(
fontSize:
11
,
color:
Colours
.
c9
)),
],
),
Text
(
'¥
88'
,
style:
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
Text
(
'¥
${model != null?model!.authors.toString():''}
'
,
style:
const
TextStyle
(
fontSize:
14
,
fontWeight:
FontWeight
.
w500
,
color:
AppTheme
.
primary
)),
],
),
),
...
...
lib/pages/course/controller.dart
浏览文件 @
7233760d
...
...
@@ -16,7 +16,7 @@ class CourseController extends GetxController {
controlFinishRefresh:
true
,
);
final
int
_limit
=
2
0
;
final
int
_limit
=
1
0
;
int
_page
=
1
;
bool
_noMore
=
false
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论