Skip to content

feat: new library design #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions lib/model/xidian_ids/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,27 @@ class BorrowData {
required this.barcode,
});

int get lendDay {
Jiffy get loanDateTime {
List<String> returnDateArr = loanDate.split("-");
return Jiffy.parseFromDateTime(DateTime(
int.parse(returnDateArr[0]),
int.parse(returnDateArr[1]),
int.parse(returnDateArr[2]),
));
}

Jiffy get normReturnDateTime {
List<String> returnDateArr = normReturnDate.split("-");
Jiffy returnDateJiffy = Jiffy.parseFromDateTime(DateTime(
return Jiffy.parseFromDateTime(DateTime(
int.parse(returnDateArr[0]),
int.parse(returnDateArr[1]),
int.parse(returnDateArr[2]),
));
return returnDateJiffy.diff(Jiffy.now(), unit: Unit.day).toInt();
}

int get lendDay =>
normReturnDateTime.diff(Jiffy.now(), unit: Unit.day).toInt();

factory BorrowData.fromJson(Map<String, dynamic> json) =>
_$BorrowDataFromJson(json);

Expand Down Expand Up @@ -98,6 +109,31 @@ class BookInfo {
_$BookInfoFromJson(json);

Map<String, dynamic> toJson() => _$BookInfoToJson(this);

int? get canBeBorrowed {
if (items == null) {
return null;
}
int toReturn = 0;
for (var i in items!) {
if (i.processType == "在架") toReturn += 1;
}
return toReturn;
}

String get searchCodeStr {
if (searchCode == null || searchCode!.isEmpty) {
return "未提供";
}
return searchCode!.first;
}

String get barCodesStr {
if (barCodes == null || barCodes!.isEmpty) {
return "未提供";
}
return barCodes!.first;
}
}

@JsonSerializable()
Expand Down
236 changes: 171 additions & 65 deletions lib/page/library/book_detail_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:styled_widget/styled_widget.dart';
import 'package:watermeter/model/xidian_ids/library.dart';
import 'package:watermeter/page/library/book_place_card.dart';
import 'package:watermeter/page/library/ebook_place_card.dart';
Expand All @@ -23,77 +24,182 @@ class BookDetailCard extends StatefulWidget {
class _BookDetailCardState extends State<BookDetailCard> {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 14,
),
child: ListView(
shrinkWrap: true,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.toUse.bookName,
style: TextStyle(
fontSize: 20.0,
color: Theme.of(context).colorScheme.primary,
),
),
const Divider(color: Colors.transparent),
Text(
"作者:${widget.toUse.author ?? "没有提供"}\n"
"ISBN:${widget.toUse.isbn ?? "没有提供"}\n"
"索书号: ${validateList(widget.toUse.searchCode)}\n"
"编排号码:${validateList(widget.toUse.barCodes)}\n"
"描述:${widget.toUse.description ?? "没有提供"}",
),
],
),
return ListView(
physics: const ClampingScrollPhysics(),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CachedNetworkImage(
imageUrl: LibrarySession.bookCover(widget.toUse.isbn ?? ""),
placeholder: (context, url) => Image.asset(
"assets/Empty-Cover.jpg",
width: 120,
height: 150,
fit: BoxFit.fill,
),
CachedNetworkImage(
imageUrl: LibrarySession.bookCover(widget.toUse.isbn ?? ""),
errorWidget: (context, url, error) =>
Image.asset("assets/Empty-Cover.jpg"),
width: 90,
height: 120,
errorWidget: (context, url, error) => Image.asset(
"assets/Empty-Cover.jpg",
width: 120,
height: 150,
fit: BoxFit.fill,
),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (widget.toUse.items != null)
...List.generate(
widget.toUse.items!.length,
(index) => BookPlaceCard(
toUse: widget.toUse.items![index],
width: 120,
height: 150,
fit: BoxFit.fitHeight,
alignment: Alignment.center,
)
//.clipRect(clipper: BookImageClipper())
.clipRRect(all: 14)
.padding(all: 2)
.decorated(
border: Border.all(color: const Color(0xFFE8E8E8), width: 2),
borderRadius: const BorderRadius.all(Radius.circular(16)),
)
.padding(right: 12),
[
Text(
widget.toUse.bookName,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.start,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 8),
Text.rich(
TextSpan(children: [
const TextSpan(
text: "作者 ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
if (widget.toUse.eitems != null)
...List.generate(
widget.toUse.eitems!.length,
(index) => EBookPlaceCard(
toUse: widget.toUse.eitems![index],
TextSpan(
text: widget.toUse.author ?? "没有提供",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
)
],
),
),
]),
),
Text.rich(TextSpan(children: [
const TextSpan(
text: "出版社 ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
TextSpan(
text: widget.toUse.publisherHouse ?? "没有相关信息",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
])),
Text.rich(TextSpan(children: [
const TextSpan(
text: "索书号 ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
TextSpan(
text: widget.toUse.searchCodeStr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
])),
Text.rich(TextSpan(children: [
const TextSpan(
text: "发行时间 ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
TextSpan(
text: widget.toUse.publishYear ?? "没有相关信息",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
])),
Text.rich(TextSpan(children: [
const TextSpan(
text: "ISBN ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
TextSpan(
text: widget.toUse.isbn ?? "没有提供",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
])),
Text.rich(TextSpan(children: [
const TextSpan(
text: "编排号码 ",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFFBFBFBF),
),
),
TextSpan(
text: widget.toUse.barCodesStr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
])),
]
.toColumn(crossAxisAlignment: CrossAxisAlignment.stretch)
.flexible(),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (widget.toUse.items != null)
...List.generate(
widget.toUse.items!.length,
(index) => BookPlaceCard(
toUse: widget.toUse.items![index],
),
),
if (widget.toUse.eitems != null)
...List.generate(
widget.toUse.eitems!.length,
(index) => EBookPlaceCard(
toUse: widget.toUse.eitems![index],
),
)
],
),
],
),
),
],
);
}
String validateList(List<String>? inputList) {
if (inputList == null || inputList.isEmpty) {
return "没有提供";
}
return inputList.first;
}
}
Loading