opt: _routePush 逻辑分支

This commit is contained in:
guozhigq
2024-06-20 00:06:45 +08:00
parent 4dba8dfc2f
commit 6978c76fcd

View File

@ -1,5 +1,6 @@
import 'package:appscheme/appscheme.dart'; import 'package:appscheme/appscheme.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:pilipala/utils/route_push.dart'; import 'package:pilipala/utils/route_push.dart';
@ -19,7 +20,6 @@ class PiliSchame {
/// 完整链接进入 b23.无效 /// 完整链接进入 b23.无效
appScheme.getLatestScheme().then((SchemeEntity? value) { appScheme.getLatestScheme().then((SchemeEntity? value) {
print('getLatestScheme value: $value');
if (value != null) { if (value != null) {
_routePush(value); _routePush(value);
} }
@ -27,8 +27,6 @@ class PiliSchame {
/// 注册从外部打开的Scheme监听信息 # /// 注册从外部打开的Scheme监听信息 #
appScheme.registerSchemeListener().listen((SchemeEntity? event) { appScheme.registerSchemeListener().listen((SchemeEntity? event) {
print('registerSchemeListener event: $event');
if (event != null) { if (event != null) {
_routePush(event); _routePush(event);
} }
@ -41,66 +39,82 @@ class PiliSchame {
final String host = value.host; final String host = value.host;
final String path = value.path; final String path = value.path;
if (scheme == 'bilibili') { if (scheme == 'bilibili') {
if (host == 'root') { switch (host) {
Navigator.popUntil( case 'root':
Get.context!, (Route<dynamic> route) => route.isFirst); Navigator.popUntil(
} else if (host == 'space') { Get.context!, (Route<dynamic> route) => route.isFirst);
final String mid = path.split('/').last; break;
Get.toNamed<dynamic>( case 'space':
'/member?mid=$mid', final String mid = path.split('/').last;
arguments: <String, dynamic>{'face': null}, Get.toNamed<dynamic>(
); '/member?mid=$mid',
} else if (host == 'video') { arguments: <String, dynamic>{'face': null},
String pathQuery = path.split('/').last;
final numericRegex = RegExp(r'^[0-9]+$');
if (numericRegex.hasMatch(pathQuery)) {
pathQuery = 'AV$pathQuery';
}
Map map = IdUtils.matchAvorBv(input: pathQuery);
if (map.containsKey('AV')) {
_videoPush(map['AV'], null);
} else if (map.containsKey('BV')) {
_videoPush(null, map['BV']);
} else {
SmartDialog.showToast('投稿匹配失败');
}
} else if (host == 'live') {
final String roomId = path.split('/').last;
Get.toNamed<dynamic>('/liveRoom?roomid=$roomId',
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId});
} else if (host == 'bangumi') {
if (path.startsWith('/season')) {
final String seasonId = path.split('/').last;
RoutePush.bangumiPush(int.parse(seasonId), null);
}
} else if (host == 'opus') {
if (path.startsWith('/detail')) {
var opusId = path.split('/').last;
Get.toNamed(
'/webview',
parameters: {
'url': 'https://www.bilibili.com/opus/$opusId',
'type': 'url',
'pageTitle': '',
},
); );
} break;
} else if (host == 'search') { case 'video':
Get.toNamed('/searchResult', parameters: {'keyword': ''}); String pathQuery = path.split('/').last;
} else if (host == 'article') { final numericRegex = RegExp(r'^[0-9]+$');
final String id = path.split('/').last.split('?').first; if (numericRegex.hasMatch(pathQuery)) {
Get.toNamed('/htmlRender', parameters: { pathQuery = 'AV$pathQuery';
'url': 'https://www.bilibili.com/read/cv$id', }
'title': 'cv$id', Map map = IdUtils.matchAvorBv(input: pathQuery);
'id': 'cv$id', if (map.containsKey('AV')) {
'dynamicType': 'read' _videoPush(map['AV'], null);
}); } else if (map.containsKey('BV')) {
} else if (host == 'pgc') { _videoPush(null, map['BV']);
if (path.contains('ep')) { } else {
final String lastPathSegment = path.split('/').last; SmartDialog.showToast('投稿匹配失败');
RoutePush.bangumiPush( }
null, int.parse(lastPathSegment.split('?').first)); break;
} case 'live':
final String roomId = path.split('/').last;
Get.toNamed<dynamic>(
'/liveRoom?roomid=$roomId',
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId},
);
break;
case 'bangumi':
if (path.startsWith('/season')) {
final String seasonId = path.split('/').last;
RoutePush.bangumiPush(int.parse(seasonId), null);
}
break;
case 'opus':
if (path.startsWith('/detail')) {
var opusId = path.split('/').last;
Get.toNamed(
'/webview',
parameters: {
'url': 'https://www.bilibili.com/opus/$opusId',
'type': 'url',
'pageTitle': '',
},
);
}
break;
case 'search':
Get.toNamed('/searchResult', parameters: {'keyword': ''});
break;
case 'article':
final String id = path.split('/').last.split('?').first;
Get.toNamed('/htmlRender', parameters: {
'url': 'https://www.bilibili.com/read/cv$id',
'title': 'cv$id',
'id': 'cv$id',
'dynamicType': 'read'
});
break;
case 'pgc':
if (path.contains('ep')) {
final String lastPathSegment = path.split('/').last;
RoutePush.bangumiPush(
null, int.parse(lastPathSegment.split('?').first));
}
break;
default:
SmartDialog.showToast('未匹配地址,请联系开发者');
Clipboard.setData(ClipboardData(text: value.toJson().toString()));
break;
} }
} }
if (scheme == 'https') { if (scheme == 'https') {