From d2cc94fb6f2478b233340aa408aea003e0c95152 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 27 May 2023 20:20:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E7=9C=8B=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/video/reply/content.dart | 3 ++ .../detail/reply/widgets/reply_item.dart | 33 ++++++++++++++++--- lib/pages/webview/controller.dart | 4 +-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/models/video/reply/content.dart b/lib/models/video/reply/content.dart index 97897f75..e210db9a 100644 --- a/lib/models/video/reply/content.dart +++ b/lib/models/video/reply/content.dart @@ -7,6 +7,7 @@ class ReplyContent { this.jumpUrl, // {} this.pictures, // {} this.vote, + this.richText }); String? message; @@ -16,6 +17,7 @@ class ReplyContent { Map? jumpUrl; List? pictures; Map? vote; + Map? richText; ReplyContent.fromJson(Map json) { message = json['message']; @@ -25,5 +27,6 @@ class ReplyContent { jumpUrl = json['jump_url'] ?? {}; pictures = json['pictures'] ?? []; vote = json['vote'] ?? {}; + richText = json['rich_text'] ?? {}; } } diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 1615ad49..d79738c7 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -243,7 +243,9 @@ class ReplyItem extends StatelessWidget { style: ButtonStyle( padding: MaterialStateProperty.all(EdgeInsets.zero), ), - child: Text('回复', style: Theme.of(context).textTheme.labelMedium), + child: Text('回复', style: Theme.of(context).textTheme.labelMedium!.copyWith( + color: Theme.of(context).colorScheme.outline + )), onPressed: () { showModalBottomSheet( context: context, @@ -260,7 +262,6 @@ class ReplyItem extends StatelessWidget { // 完成评论,数据添加 if (value['data'] != null) { - print('🌹: ${value['data'].content.message}'), addReply!(value['data']) // replyControl.replies.add(value['data']), } @@ -426,6 +427,7 @@ InlineSpan buildContent(BuildContext context, content) { ); } List spanChilds = []; + bool hasMatchMember = true; // 匹配表情 String matchEmote = content.message.splitMapJoin( RegExp(r"\[.*?\]"), @@ -459,6 +461,7 @@ InlineSpan buildContent(BuildContext context, content) { RegExp(r"@.*( |:)"), onMatch: (Match match) { if (match[0] != null) { + hasMatchMember = false; content.atNameToMid.forEach((key, value) { spanChilds.add( TextSpan( @@ -489,7 +492,7 @@ InlineSpan buildContent(BuildContext context, content) { // 匹配 jumpUrl String matchUrl = matchMember; - if (content.jumpUrl.isNotEmpty) { + if (content.jumpUrl.isNotEmpty && hasMatchMember) { List urlKeys = content.jumpUrl.keys.toList(); matchUrl = matchMember.splitMapJoin( RegExp("(?:${urlKeys.join("|")})"), @@ -525,7 +528,6 @@ InlineSpan buildContent(BuildContext context, content) { }, ); } - str = matchUrl.splitMapJoin( RegExp(r"\d{1,2}:\d{1,2}"), onMatch: (Match match) { @@ -651,6 +653,29 @@ InlineSpan buildContent(BuildContext context, content) { ); } } + + // 笔记链接 + if (content.richText.isNotEmpty) { + spanChilds.add( + TextSpan( + text: ' 笔记', + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () => { + Get.toNamed( + '/webview', + parameters: { + 'url': content.richText['note']['click_url'], + 'type': 'note', + 'pageTitle': '笔记预览' + }, + ) + }, + ), + ); + } // spanChilds.add(TextSpan(text: matchMember)); return TextSpan(children: spanChilds); } diff --git a/lib/pages/webview/controller.dart b/lib/pages/webview/controller.dart index 9fe1b670..44626968 100644 --- a/lib/pages/webview/controller.dart +++ b/lib/pages/webview/controller.dart @@ -45,9 +45,9 @@ class WebviewController extends GetxController { onPageStarted: (String url) {}, // 加载完成 onPageFinished: (String url) async { - if (url.startsWith( + if (type == 'login' && (url.startsWith( 'https://passport.bilibili.com/web/sso/exchange_cookie') || - url.startsWith('https://m.bilibili.com/')) { + url.startsWith('https://m.bilibili.com/'))) { try { var cookies = await WebviewCookieManager().getCookies(HttpString.baseUrl);