Skip to content

Commit

Permalink
添加了搜索的界面,现在排行榜还暂时无法使用,后续版本将会加入。
Browse files Browse the repository at this point in the history
  • Loading branch information
deretame committed Oct 17, 2024
1 parent 83ec671 commit 6a3f16f
Show file tree
Hide file tree
Showing 20 changed files with 857 additions and 1,059 deletions.
Binary file added asset/image/bika_image/cat_forum.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/image/bika_image/cat_latest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/image/bika_image/cat_leaderboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added asset/image/bika_image/cat_random.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions lib/config/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,44 @@ int shieldedCategoriesVersion = 0;
class Global {
final BuildContext context;

// 搜索界面信息
CategoriesGlobal categories = CategoriesGlobal();

Global(this.context) {
// 在构造函数中初始化屏幕宽度和高度
screenWidth = MediaQuery.of(context).size.width;
screenHeight = MediaQuery.of(context).size.height;

// 因为部分分类不在返回值中,所以需要在这里添加
CategoryGlobal temp = CategoryGlobal(
title: '哔咔排行榜',
thumb: ThumbGlobal(originalName: '', path: '', fileServer: ''),
isWeb: false,
active: true,
link: 'asset/image/bika_image/cat_leaderboard.jpg',
);

categories.categoriesGlobal.add(temp);

temp = CategoryGlobal(
title: '最近更新',
thumb: ThumbGlobal(originalName: '', path: '', fileServer: ''),
isWeb: false,
active: true,
link: 'asset/image/bika_image/cat_latest.jpg',
);

categories.categoriesGlobal.add(temp);

temp = CategoryGlobal(
title: '随机本子',
thumb: ThumbGlobal(originalName: '', path: '', fileServer: ''),
isWeb: false,
active: true,
link: 'asset/image/bika_image/cat_random.jpg',
);

categories.categoriesGlobal.add(temp);
}
}

Expand Down Expand Up @@ -64,6 +98,7 @@ Map<String, bool> categoryMap = {
"重口地帶": false,
};

// 存储屏蔽分类
Map<String, bool> shieldCategoryMapRealm = {
"嗶咔漢化": false,
"全彩": false,
Expand Down Expand Up @@ -101,3 +136,49 @@ Map<String, bool> shieldCategoryMapRealm = {
"Cosplay": false,
"重口地帶": false,
};

// 分类信息
class CategoriesGlobal {
late List<CategoryGlobal> categoriesGlobal;

CategoriesGlobal() {
categoriesGlobal = [];
}

// 排序方法,将isWeb为true的CategoryGlobal对象放在前面
void sortCategoriesByIsWeb() {
categoriesGlobal.sort((a, b) {
if (b.isWeb && !a.isWeb) return 1; // 如果b是Web而a不是,b排在前面
if (!b.isWeb && a.isWeb) return -1; // 如果a是Web而b不是,a排在前面
return 0; // 如果两者都是Web或者都不是,保持原来的顺序
});
}
}

class CategoryGlobal {
late String title;
late ThumbGlobal thumb;
late bool isWeb;
late bool active;
late String link;

CategoryGlobal({
required this.title,
required this.thumb,
required this.isWeb,
required this.active,
required this.link,
});
}

class ThumbGlobal {
late String originalName;
late String path;
late String fileServer;

ThumbGlobal({
required this.originalName,
required this.path,
required this.fileServer,
});
}
33 changes: 11 additions & 22 deletions lib/json/search_page.dart → lib/json/search_category.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
// To parse this JSON data, do
//
// final searchPage = searchPageFromJson(jsonString);
// final searchCategory = searchCategoryFromJson(jsonString);

import 'dart:convert';

import 'package:freezed_annotation/freezed_annotation.dart';

part 'search_page.freezed.dart';
part 'search_page.g.dart';
part 'search_category.freezed.dart';
part 'search_category.g.dart';

SearchPage searchPageFromJson(String str) =>
SearchPage.fromJson(json.decode(str));
SearchCategory searchCategoryFromJson(String str) =>
SearchCategory.fromJson(json.decode(str));

String searchPageToJson(SearchPage data) => json.encode(data.toJson());
String searchCategoryToJson(SearchCategory data) => json.encode(data.toJson());

@freezed
class SearchPage with _$SearchPage {
const factory SearchPage({
@JsonKey(name: "code") required int code,
@JsonKey(name: "message") required String message,
@JsonKey(name: "data") required Data data,
}) = _SearchPage;

factory SearchPage.fromJson(Map<String, dynamic> json) =>
_$SearchPageFromJson(json);
}

@freezed
class Data with _$Data {
const factory Data({
class SearchCategory with _$SearchCategory {
const factory SearchCategory({
@JsonKey(name: "categories") required List<Category> categories,
}) = _Data;
}) = _SearchCategory;

factory Data.fromJson(Map<String, dynamic> json) => _$DataFromJson(json);
factory SearchCategory.fromJson(Map<String, dynamic> json) =>
_$SearchCategoryFromJson(json);
}

@freezed
Expand Down
Loading

0 comments on commit 6a3f16f

Please sign in to comment.