feat: search user by uid
This commit is contained in:
@ -26,7 +26,6 @@ class SSearchController extends GetxController {
|
|||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
bool enableHotKey = true;
|
bool enableHotKey = true;
|
||||||
bool enableSearchSuggest = true;
|
bool enableSearchSuggest = true;
|
||||||
late StreamController<bool> clearStream = StreamController<bool>.broadcast();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -42,7 +41,6 @@ class SSearchController extends GetxController {
|
|||||||
final hint = parameters['hintText'];
|
final hint = parameters['hintText'];
|
||||||
if (hint != null) {
|
if (hint != null) {
|
||||||
hintText = hint;
|
hintText = hint;
|
||||||
searchKeyWord.value = hintText;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
historyCacheList = GlobalDataCache().historyCacheList;
|
historyCacheList = GlobalDataCache().historyCacheList;
|
||||||
@ -55,10 +53,8 @@ class SSearchController extends GetxController {
|
|||||||
searchKeyWord.value = value;
|
searchKeyWord.value = value;
|
||||||
if (value == '') {
|
if (value == '') {
|
||||||
searchSuggestList.value = [];
|
searchSuggestList.value = [];
|
||||||
clearStream.add(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearStream.add(true);
|
|
||||||
if (enableSearchSuggest) {
|
if (enableSearchSuggest) {
|
||||||
_debouncer.call(() => querySearchSuggest(value));
|
_debouncer.call(() => querySearchSuggest(value));
|
||||||
}
|
}
|
||||||
@ -68,23 +64,20 @@ class SSearchController extends GetxController {
|
|||||||
controller.value.clear();
|
controller.value.clear();
|
||||||
searchKeyWord.value = '';
|
searchKeyWord.value = '';
|
||||||
searchSuggestList.value = [];
|
searchSuggestList.value = [];
|
||||||
clearStream.add(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 搜索
|
// 搜索
|
||||||
void submit() {
|
void submit() {
|
||||||
if (searchKeyWord.value == '') {
|
if (searchKeyWord.value == '' && hintText.isNotEmpty && hintText == '搜索') {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
if (searchKeyWord.value == '' && hintText != '搜索') {
|
||||||
|
searchKeyWord.value = hintText;
|
||||||
|
controller.value.text = hintText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
List arr = historyCacheList.where((e) => e != searchKeyWord.value).toList();
|
hintText = '搜索';
|
||||||
arr.insert(0, searchKeyWord.value);
|
cacheHistory();
|
||||||
historyCacheList = arr;
|
|
||||||
|
|
||||||
historyList.value = historyCacheList;
|
|
||||||
// 手动刷新
|
|
||||||
historyList.refresh();
|
|
||||||
localCache.put('cacheList', historyCacheList);
|
|
||||||
searchFocusNode.unfocus();
|
|
||||||
Get.toNamed('/searchResult', parameters: {'keyword': searchKeyWord.value});
|
Get.toNamed('/searchResult', parameters: {'keyword': searchKeyWord.value});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +128,18 @@ class SSearchController extends GetxController {
|
|||||||
historyCacheList = [];
|
historyCacheList = [];
|
||||||
historyList.refresh();
|
historyList.refresh();
|
||||||
localCache.put('cacheList', []);
|
localCache.put('cacheList', []);
|
||||||
|
GlobalDataCache().historyCacheList = [];
|
||||||
SmartDialog.showToast('搜索历史已清空');
|
SmartDialog.showToast('搜索历史已清空');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cacheHistory() {
|
||||||
|
List arr = historyCacheList.where((e) => e != searchKeyWord.value).toList();
|
||||||
|
arr.insert(0, searchKeyWord.value);
|
||||||
|
historyCacheList = arr;
|
||||||
|
historyList.value = historyCacheList;
|
||||||
|
historyList.refresh();
|
||||||
|
localCache.put('cacheList', historyCacheList);
|
||||||
|
GlobalDataCache().historyCacheList = historyCacheList;
|
||||||
|
searchFocusNode.unfocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,24 +63,35 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
|||||||
focusNode: _searchController.searchFocusNode,
|
focusNode: _searchController.searchFocusNode,
|
||||||
controller: _searchController.controller.value,
|
controller: _searchController.controller.value,
|
||||||
textInputAction: TextInputAction.search,
|
textInputAction: TextInputAction.search,
|
||||||
onChanged: (value) => _searchController.onChange(value),
|
onChanged: _searchController.onChange,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: _searchController.hintText,
|
hintText: _searchController.hintText,
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
suffixIcon: StreamBuilder(
|
suffix: Obx(() {
|
||||||
initialData: false,
|
RxString searchKeyWord = _searchController.searchKeyWord;
|
||||||
stream: _searchController.clearStream.stream,
|
if (searchKeyWord.value.isEmpty) {
|
||||||
builder: (_, snapshot) {
|
return const SizedBox();
|
||||||
if (snapshot.data == true) {
|
}
|
||||||
return IconButton(
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (RegExp(r'^\d+$').hasMatch(searchKeyWord.value))
|
||||||
|
IconButton(
|
||||||
|
tooltip: '直达up主页',
|
||||||
|
icon: const Icon(Icons.person_outline, size: 22),
|
||||||
|
onPressed: () {
|
||||||
|
_searchController.cacheHistory();
|
||||||
|
Get.toNamed('/member?mid=${searchKeyWord.value}',
|
||||||
|
arguments: {'face': null});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
icon: const Icon(Icons.clear, size: 22),
|
icon: const Icon(Icons.clear, size: 22),
|
||||||
onPressed: () => _searchController.onClear(),
|
onPressed: () => _searchController.onClear(),
|
||||||
);
|
),
|
||||||
} else {
|
],
|
||||||
return const SizedBox();
|
);
|
||||||
}
|
}),
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
onSubmitted: (String value) => _searchController.submit(),
|
onSubmitted: (String value) => _searchController.submit(),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/http/member.dart';
|
||||||
import 'package:pilipala/http/search.dart';
|
import 'package:pilipala/http/search.dart';
|
||||||
import 'package:pilipala/models/common/search_type.dart';
|
import 'package:pilipala/models/common/search_type.dart';
|
||||||
|
import 'package:pilipala/models/search/result.dart';
|
||||||
import 'package:pilipala/utils/id_utils.dart';
|
import 'package:pilipala/utils/id_utils.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
|
||||||
@ -39,6 +41,30 @@ class SearchPanelController extends GetxController {
|
|||||||
page.value++;
|
page.value++;
|
||||||
onPushDetail(keyword, resultList);
|
onPushDetail(keyword, resultList);
|
||||||
}
|
}
|
||||||
|
if (RegExp(r'^\d+$').hasMatch(keyword!) &&
|
||||||
|
searchType == SearchType.bili_user) {
|
||||||
|
var res = await MemberHttp.memberInfo(mid: int.parse(keyword!));
|
||||||
|
if (res['status']) {
|
||||||
|
try {
|
||||||
|
final user = SearchUserItemModel(
|
||||||
|
mid: res['data'].mid,
|
||||||
|
uname: res['data'].name,
|
||||||
|
upic: res['data'].face,
|
||||||
|
level: res['data'].level,
|
||||||
|
fans: null,
|
||||||
|
videos: null,
|
||||||
|
officialVerify: res['data'].official,
|
||||||
|
);
|
||||||
|
if (resultList.isEmpty) {
|
||||||
|
resultList = [user].obs;
|
||||||
|
} else {
|
||||||
|
resultList.insert(0, user);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
debugPrint('搜索用户信息失败: $err');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,10 +13,10 @@ Widget searchUserPanel(BuildContext context, ctr, list) {
|
|||||||
controller: ctr!.scrollController,
|
controller: ctr!.scrollController,
|
||||||
addAutomaticKeepAlives: false,
|
addAutomaticKeepAlives: false,
|
||||||
addRepaintBoundaries: false,
|
addRepaintBoundaries: false,
|
||||||
itemCount: list!.length,
|
itemCount: list.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
var i = list![index];
|
var i = list[index];
|
||||||
String heroTag = Utils.makeHeroTag(i!.mid);
|
String heroTag = Utils.makeHeroTag(i.mid);
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => Get.toNamed('/member?mid=${i.mid}',
|
onTap: () => Get.toNamed('/member?mid=${i.mid}',
|
||||||
arguments: {'heroTag': heroTag, 'face': i.upic}),
|
arguments: {'heroTag': heroTag, 'face': i.upic}),
|
||||||
@ -43,7 +43,7 @@ Widget searchUserPanel(BuildContext context, ctr, list) {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
i!.uname,
|
i.uname!,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
@ -55,15 +55,16 @@ Widget searchUserPanel(BuildContext context, ctr, list) {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
if (i.fans != null && i.videos != null)
|
||||||
children: [
|
Row(
|
||||||
Text('粉丝:${i.fans} ', style: style),
|
children: [
|
||||||
Text(' 视频:${i.videos}', style: style)
|
Text('粉丝:${i.fans} ', style: style),
|
||||||
],
|
Text(' 视频:${i.videos}', style: style)
|
||||||
),
|
],
|
||||||
if (i.officialVerify['desc'] != '')
|
),
|
||||||
|
if (i.officialVerify!['desc'] != '')
|
||||||
Text(
|
Text(
|
||||||
i.officialVerify['desc'],
|
i.officialVerify!['desc'],
|
||||||
style: style,
|
style: style,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user