修了一些问题

main
落雨楓 2 years ago
parent a8e5d51a3a
commit 08fae6fd4c

@ -110,11 +110,16 @@ class BaseApi {
static Future<String> post(Uri uri, {Map<String, dynamic>? search, dynamic data}) async { static Future<String> post(Uri uri, {Map<String, dynamic>? search, dynamic data}) async {
var client = await getClient(); var client = await getClient();
String? contentType;
if (data is Map) {
contentType = Headers.formUrlEncodedContentType;
}
var res = await client.post<String>( var res = await client.post<String>(
uri.toString(), uri.toString(),
queryParameters: search, queryParameters: search,
data: data, data: data,
options: Options(responseType: ResponseType.plain), options: Options(responseType: ResponseType.plain, contentType: contentType),
); );
if (res.statusCode != null && res.statusCode != 200) { if (res.statusCode != null && res.statusCode != 200) {

@ -115,26 +115,25 @@ class MWApi {
static Future<MWResponse<Map<String, dynamic>>> post(String action, static Future<MWResponse<Map<String, dynamic>>> post(String action,
{Map<String, dynamic>? params, String? withToken}) async { {Map<String, dynamic>? params, String? withToken}) async {
Map<String, String> paramsStr = params ??= {};
params?.map((key, value) => MapEntry(key, value.toString())) ?? {}; params.addAll({
paramsStr.addAll({
"action": action, "action": action,
"format": "json", "format": "json",
"formatversion": "2", "formatversion": 2,
"uselang": Global.wikiLang, "uselang": Global.wikiLang,
}); });
if (Global.webOrigin != null) { if (Global.webOrigin != null) {
paramsStr["origin"] = Global.webOrigin!; params["origin"] = Global.webOrigin!;
} }
var resText = ""; var resText = "";
try { try {
if (withToken != null) { if (withToken != null) {
// CSRF Token // CSRF Token
paramsStr["token"] = await getToken(type: withToken); params["token"] = await getToken(type: withToken);
} }
resText = await BaseApi.post(apiBaseUri, data: paramsStr); resText = await BaseApi.post(apiBaseUri, data: params);
} on DioError catch (err) { } on DioError catch (err) {
if (err.type == DioErrorType.response) { if (err.type == DioErrorType.response) {
if (err.response != null) { if (err.response != null) {

@ -1,6 +1,7 @@
// ignore_for_file: invalid_annotation_target // ignore_for_file: invalid_annotation_target
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isekai_wiki/utils/utils.dart';
part 'page_info.freezed.dart'; part 'page_info.freezed.dart';
part 'page_info.g.dart'; part 'page_info.g.dart';
@ -20,6 +21,8 @@ class PageInfo {
String? pagelanguage; String? pagelanguage;
String? pagelanguagehtmlcode; String? pagelanguagehtmlcode;
String? pagelanguagedir; String? pagelanguagedir;
@JsonKey(fromJson: _inwatchlistFromInt, toJson: _inwatchlistToInt)
bool? inwatchlist; bool? inwatchlist;
@JsonKey(name: "touched") @JsonKey(name: "touched")
@ -62,6 +65,22 @@ class PageInfo {
factory PageInfo.fromJson(Map<String, dynamic> json) => _$PageInfoFromJson(json); factory PageInfo.fromJson(Map<String, dynamic> json) => _$PageInfoFromJson(json);
Map<String, dynamic> toJson() => _$PageInfoToJson(this); Map<String, dynamic> toJson() => _$PageInfoToJson(this);
static bool? _inwatchlistFromInt(int? val) {
if (val != null) {
return val == 1;
} else {
return null;
}
}
static int? _inwatchlistToInt(bool? val) {
if (val != null) {
return val ? 1 : 0;
} else {
return null;
}
}
} }
@freezed @freezed

@ -18,7 +18,7 @@ typedef AddFavoriteCallback = Future<bool> Function(
typedef PageInfoCallback = Future<void> Function(PageInfo pageInfo); typedef PageInfoCallback = Future<void> Function(PageInfo pageInfo);
class PageCardStyles { class PageCardStyles {
static const double cardInnerHeight = 140; static const double cardInnerHeight = 150;
static const cardInnerPadding = EdgeInsets.only(top: 16, left: 20, right: 20, bottom: 12); static const cardInnerPadding = EdgeInsets.only(top: 16, left: 20, right: 20, bottom: 12);
static const double footerButtonSize = 30; static const double footerButtonSize = 30;
static const double footerButtonInnerSize = 26; static const double footerButtonInnerSize = 26;
@ -163,13 +163,15 @@ class _PageCardState extends ReactiveState<PageCard> {
Expanded( Expanded(
flex: 1, flex: 1,
child: c.isLoading.value child: c.isLoading.value
? SkeletonParagraph( ? ClipRect(
style: SkeletonParagraphStyle( child: SkeletonParagraph(
lines: 3, style: SkeletonParagraphStyle(
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 0), lines: 3,
lineStyle: SkeletonLineStyle( padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 0),
randomLength: true, lineStyle: SkeletonLineStyle(
height: Styles.pageCardDescription.fontSize! * textScale), randomLength: true,
height: Styles.pageCardDescription.fontSize! * textScale),
),
), ),
) )
: Text(c.pageInfo.value?.description ?? "没有简介", : Text(c.pageInfo.value?.description ?? "没有简介",

@ -28,8 +28,7 @@ class RecentPageListController extends GetxController {
@override @override
void onInit() { void onInit() {
scrollController?.addListener(() { scrollController?.addListener(() {
if (scrollController!.position.pixels > if (scrollController!.position.pixels > scrollController!.position.maxScrollExtent - 10) {
scrollController!.position.maxScrollExtent - 10) {
// //
if (hasNextPage.value && !isLoading.value) { if (hasNextPage.value && !isLoading.value) {
loadNextPages(); loadNextPages();
@ -73,8 +72,7 @@ class RecentPageListController extends GetxController {
try { try {
var rcListRes = await MWApiList.getMixedRecentChanges( var rcListRes = await MWApiList.getMixedRecentChanges(
limit: 10, limit: 10, continueInfo: continueInfo.isNotEmpty ? continueInfo : null);
continueInfo: continueInfo.isNotEmpty ? continueInfo : null);
var pageIds = rcListRes.data.map((rcInfo) => rcInfo.pageid).toList(); var pageIds = rcListRes.data.map((rcInfo) => rcInfo.pageid).toList();
var pageListRes = await MWApiList.getPageInfoList( var pageListRes = await MWApiList.getPageInfoList(
@ -95,7 +93,7 @@ class RecentPageListController extends GetxController {
} }
hasNextPage.value = rcListRes.continueInfo != null; hasNextPage.value = rcListRes.continueInfo != null;
continueInfo.value = rcListRes.continueInfo ?? {}; continueInfo.value = rcListRes.continueInfo ?? {};
} catch (err) { } catch (err, stack) {
hasNextPage.value = false; hasNextPage.value = false;
if (shouldRefresh) { if (shouldRefresh) {
pageList.clear(); pageList.clear();
@ -128,14 +126,13 @@ class RecentPageList extends StatelessWidget {
return Column( return Column(
key: key, key: key,
children: [ children: [
for (var i = 0; i < 6; i++) for (var i = 0; i < 6; i++) PageCard(key: ValueKey("rpl-card-$i"), isLoading: true),
PageCard(key: ValueKey("rpl-card-$i"), isLoading: true),
], ],
); );
} }
Widget _buildPageCard(int index, PageInfo pageInfo, Widget _buildPageCard(
RecentPageListController c, FavoriteListController fc) { int index, PageInfo pageInfo, RecentPageListController c, FavoriteListController fc) {
return PageCard( return PageCard(
key: ValueKey("rpl-card-$index"), key: ValueKey("rpl-card-$index"),
pageInfo: c.pageList[index], pageInfo: c.pageList[index],
@ -153,11 +150,13 @@ class RecentPageList extends StatelessWidget {
(context, index) { (context, index) {
if (index == 0) { if (index == 0) {
// //
if (c.pageList.isEmpty) { return Obx(() {
return _buildSkeletonList(); if (c.pageList.isEmpty) {
} else { return _buildSkeletonList();
return _buildPageCard(index, c.pageList[index], c, flc); } else {
} return _buildPageCard(index, c.pageList[index], c, flc);
}
});
} }
// //
@ -168,14 +167,16 @@ class RecentPageList extends StatelessWidget {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 12), padding: const EdgeInsets.symmetric(vertical: 12),
child: Center( child: Center(
child: c.isLoading.value child: Obx(
? const CupertinoActivityIndicator( () => c.isLoading.value
radius: 14, ? const CupertinoActivityIndicator(
) radius: 14,
: const SizedBox( )
width: 28, : const SizedBox(
height: 28, width: 28,
), height: 28,
),
),
), ),
); );
} }

@ -235,17 +235,19 @@ class UserController extends GetxController {
} }
Future<void> logout({bool logoutRemote = true}) async { Future<void> logout({bool logoutRemote = true}) async {
authProcessing.value = true; if (logoutRemote) {
authProcessing.value = true;
try {
await MWApiUser.logout(); try {
} catch (err, stack) { await MWApiUser.logout();
alert(Get.overlayContext!, ErrorUtils.getErrorMessage(err), title: "错误"); } catch (err, stack) {
if (kDebugMode) { authProcessing.value = false;
print("Exception in logout: $err"); alert(Get.overlayContext!, ErrorUtils.getErrorMessage(err), title: "错误");
stack.printError(); if (kDebugMode) {
print("Exception in logout: $err");
stack.printError();
}
} }
return;
} }
// Cookie // Cookie
@ -255,9 +257,9 @@ class UserController extends GetxController {
userId.value = 0; userId.value = 0;
userName.value = ""; userName.value = "";
nickName.value = ""; nickName.value = "";
avatarUrlSet.clear(); avatarUrlSet.value = {};
authProcessing.value = true; authProcessing.value = false;
saveToStorage(); saveToStorage();
} }

@ -16,8 +16,7 @@ import '../styles.dart';
enum HomeTabs { newest, followed } enum HomeTabs { newest, followed }
class HomeController extends GetxController class HomeController extends GetxController with GetSingleTickerProviderStateMixin {
with GetSingleTickerProviderStateMixin {
double _navSearchButtonOffset = 90; double _navSearchButtonOffset = 90;
var showNavSearchButton = false.obs; var showNavSearchButton = false.obs;
@ -36,15 +35,12 @@ class HomeController extends GetxController
void onInit() { void onInit() {
tabController = TabController(length: 2, vsync: this); tabController = TabController(length: 2, vsync: this);
_navSearchButtonOffset = _navSearchButtonOffset = 48 * MediaQuery.of(Get.context!).textScaleFactor + 48;
48 * MediaQuery.of(Get.context!).textScaleFactor + 48;
scrollController.addListener(() { scrollController.addListener(() {
if (scrollController.offset >= _navSearchButtonOffset && if (scrollController.offset >= _navSearchButtonOffset && !showNavSearchButton.value) {
!showNavSearchButton.value) {
showNavSearchButton.value = true; showNavSearchButton.value = true;
} else if (scrollController.offset < _navSearchButtonOffset && } else if (scrollController.offset < _navSearchButtonOffset && showNavSearchButton.value) {
showNavSearchButton.value) {
showNavSearchButton.value = false; showNavSearchButton.value = false;
} }
}); });
@ -102,11 +98,8 @@ class HomeTab extends StatelessWidget {
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),
child: CupertinoButton( child: CupertinoButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.search, child: const Icon(CupertinoIcons.bell, size: 26, color: Styles.themeNavTitleColor),
size: 26, color: Styles.themeNavTitleColor), onPressed: () {},
onPressed: () {
onSearchClick?.call();
},
), ),
), ),
); );
@ -121,8 +114,7 @@ class HomeTab extends StatelessWidget {
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),
child: CupertinoButton( child: CupertinoButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.search, child: const Icon(CupertinoIcons.search, size: 26, color: Styles.themeNavTitleColor),
size: 26, color: Styles.themeNavTitleColor),
onPressed: () { onPressed: () {
onSearchClick?.call(); onSearchClick?.call();
}, },
@ -144,13 +136,12 @@ class HomeTab extends StatelessWidget {
), ),
slivers: <Widget>[ slivers: <Widget>[
IsekaiSliverNavigationBar( IsekaiSliverNavigationBar(
leading: _buildNotificationIconButton(), leading: _buildSearchIconButton(),
backgroundColor: Styles.themeMainColor, backgroundColor: Styles.themeMainColor,
brightness: Brightness.dark, brightness: Brightness.dark,
largeTitle: const Text('首页', largeTitle: const Text('首页', style: TextStyle(color: Styles.themeNavTitleColor)),
style: TextStyle(color: Styles.themeNavTitleColor)),
border: Border.all(style: BorderStyle.none), border: Border.all(style: BorderStyle.none),
trailing: _buildSearchIconButton(), trailing: _buildNotificationIconButton(),
), ),
SliverPersistentHeader( SliverPersistentHeader(
delegate: _SliverAppBarDelegate( delegate: _SliverAppBarDelegate(
@ -181,12 +172,10 @@ class HomeTab extends StatelessWidget {
children: [ children: [
Container( Container(
padding: const EdgeInsets.all(1), padding: const EdgeInsets.all(1),
child: const Icon(CupertinoIcons.search, child: const Icon(CupertinoIcons.search, color: Colors.black54),
color: Colors.black54),
), ),
const Text("搜索页面...", const Text("搜索页面...",
textAlign: TextAlign.center, textAlign: TextAlign.center, style: TextStyle(color: Colors.black54))
style: TextStyle(color: Colors.black54))
], ],
), ),
), ),
@ -216,10 +205,7 @@ class HomeTab extends StatelessWidget {
indicatorColor: Styles.themeMainColor, indicatorColor: Styles.themeMainColor,
labelColor: Styles.themeMainColor, labelColor: Styles.themeMainColor,
unselectedLabelColor: Colors.black45, unselectedLabelColor: Colors.black45,
tabs: const [ tabs: const [CollapsedTabText('最新'), CollapsedTabText('关注')],
CollapsedTabText('最新'),
CollapsedTabText('关注')
],
onTap: (int selected) {}, onTap: (int selected) {},
), ),
), ),
@ -264,8 +250,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
double get maxExtent => max(maxHeight, minHeight); double get maxExtent => max(maxHeight, minHeight);
@override @override
Widget build( Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
BuildContext context, double shrinkOffset, bool overlapsContent) {
return SizedBox.expand(child: child); return SizedBox.expand(child: child);
} }

@ -39,7 +39,7 @@ abstract class Styles {
static const TextStyle pageCardDescription = TextStyle( static const TextStyle pageCardDescription = TextStyle(
color: Colors.black54, color: Colors.black54,
fontSize: 16, fontSize: 14,
fontStyle: FontStyle.normal, fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal, fontWeight: FontWeight.normal,
); );

Loading…
Cancel
Save