Skip to content

Commit

Permalink
fix: 专栏+导航栏(横屏侧栏)
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Jan 1, 2025
1 parent f7189b1 commit c732182
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
18 changes: 16 additions & 2 deletions lib/http/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:html/dom.dart';
import 'package:flutter/foundation.dart';
import 'package:html/parser.dart';
import 'index.dart';

Expand Down Expand Up @@ -73,7 +74,11 @@ class HtmlHttp {
static Future reqReadHtml(id, dynamicType) async {
var response = await Request().get(
"https://www.bilibili.com/$dynamicType/$id/",
extra: {'ua': 'pc'},
options: Options(headers: {
HttpHeaders.userAgentHeader: 'Mozilla/5.0',
HttpHeaders.refererHeader: 'https://www.bilibili.com/',
HttpHeaders.cookieHeader: 'opus-goback=1',
}),
);
Document rootTree = parse(response.data);
Element body = rootTree.body!;
Expand All @@ -99,7 +104,16 @@ class HtmlHttp {
// print(updateTime);

//
String opusContent = opusDetail.innerHtml ?? '';
String opusContent =
opusDetail.querySelector('#read-article-holder')?.innerHtml ?? '';
print("opusContent: $opusContent");
if (opusContent.isEmpty) {
// 查找形如"dyn_id_str":"(\d+)"的id
String opusid =
RegExp(r'"dyn_id_str":"(\d+)"').firstMatch(response.data)!.group(1)!;
print("opusid: $opusid");
return await reqHtml(opusid, 'opus');
}
RegExp digitRegExp = RegExp(r'\d+');
Iterable<Match> matches = digitRegExp.allMatches(id);
String number = matches.first.group(0)!;
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/main/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MainController extends GetxController {
DateTime? _lastPressedAt;
late bool hideTabBar;
late PageController pageController;
int selectedIndex = 0;
late int selectedIndex;
Box userInfoCache = GStorage.userInfo;
RxBool userLogin = false.obs;
late DynamicBadgeMode dynamicBadgeType;
Expand All @@ -43,6 +43,8 @@ class MainController extends GetxController {
setting.get(SettingBoxKey.defaultHomePage, defaultValue: 0) as int;
selectedIndex = defaultNavigationBars
.indexWhere((item) => item['id'] == defaultHomePage);
print("selectedIndex: ${selectedIndex}");
pageController = PageController(initialPage: selectedIndex);
var userInfo = userInfoCache.get('userInfoCache');
userLogin.value = userInfo != null;
dynamicBadgeType = DynamicBadgeMode.values[setting.get(
Expand Down
5 changes: 3 additions & 2 deletions lib/pages/main/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class _MainAppState extends State<MainApp>
// late bool useSideBar;
late SideBarPosition sideBarPosition;
late bool enableGradientBg;
final GlobalKey pageViewKey = GlobalKey();

@override
void initState() {
super.initState();
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
_mainController.pageController =
PageController(initialPage: _mainController.selectedIndex);

enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
// useSideBar = setting.get(SettingBoxKey.useSideBar, defaultValue: false);
sideBarPosition = SideBarPositionCode.fromCode(setting.get(
Expand Down Expand Up @@ -285,6 +285,7 @@ class _MainAppState extends State<MainApp>
SizedBox(width: context.width * 0.004),
Expanded(
child: PageView(
key: pageViewKey,
physics: const NeverScrollableScrollPhysics(),
controller: _mainController.pageController,
onPageChanged: (index) {
Expand Down

0 comments on commit c732182

Please sign in to comment.