feat: AV/BV号直接跳转
This commit is contained in:
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/search.dart';
|
||||
import 'package:pilipala/models/common/search_type.dart';
|
||||
import 'package:pilipala/utils/id_utils.dart';
|
||||
import 'package:pilipala/utils/utils.dart';
|
||||
|
||||
class SearchPanelController extends GetxController {
|
||||
SearchPanelController({this.keyword, this.searchType});
|
||||
@ -21,6 +23,7 @@ class SearchPanelController extends GetxController {
|
||||
} else if (type == 'onRefresh') {
|
||||
resultList.value = result['data'].list;
|
||||
}
|
||||
onPushDetail(keyword, resultList);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -40,4 +43,24 @@ class SearchPanelController extends GetxController {
|
||||
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
|
||||
}
|
||||
}
|
||||
|
||||
void onPushDetail(keyword, resultList) async {
|
||||
// 匹配输入内容,如果是AV、BV号且有结果 直接跳转详情页
|
||||
Map matchRes = IdUtils.matchAvorBv(input: keyword);
|
||||
List matchKeys = matchRes.keys.toList();
|
||||
if (matchKeys.isNotEmpty && searchType == SearchType.video) {
|
||||
String bvid = resultList.first.bvid;
|
||||
int aid = resultList.first.aid;
|
||||
String heroTag = Utils.makeHeroTag(bvid);
|
||||
|
||||
int cid = await SearchHttp.ab2c(aid: aid, bvid: bvid);
|
||||
if (matchKeys.first == 'BV' && matchRes[matchKeys.first] == bvid ||
|
||||
matchKeys.first == 'AV' && matchRes[matchKeys.first] == aid) {
|
||||
Get.toNamed(
|
||||
'/video?bvid=$bvid&cid=$cid',
|
||||
arguments: {'videoItem': resultList.first, 'heroTag': heroTag},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,28 @@ class IdUtils {
|
||||
}
|
||||
return (r - ADD) ^ XOR;
|
||||
}
|
||||
|
||||
// 匹配
|
||||
static Map matchAvorBv({String? input}) {
|
||||
Map result = {};
|
||||
if (input == null || input == '') {
|
||||
return result;
|
||||
}
|
||||
RegExp bvRegex = RegExp(r'BV[0-9A-Za-z]{10}', caseSensitive: false);
|
||||
RegExp avRegex = RegExp(r'AV\d+', caseSensitive: false);
|
||||
|
||||
Iterable<Match> bvMatches = bvRegex.allMatches(input);
|
||||
Iterable<Match> avMatches = avRegex.allMatches(input);
|
||||
|
||||
List<String> bvs = bvMatches.map((match) => match.group(0)!).toList();
|
||||
List<String> avs = avMatches.map((match) => match.group(0)!).toList();
|
||||
|
||||
if (bvs.isNotEmpty) {
|
||||
result['BV'] = bvs[0].substring(0, 2).toUpperCase() + bvs[0].substring(2);
|
||||
}
|
||||
if (avs.isNotEmpty) {
|
||||
result['AV'] = avs[0].substring(2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user