Explorar el Código

1、人脉的搜索的实现

tags/0.0.1
PH2 hace 4 años
padre
commit
12cffd46cb
Se han modificado 8 ficheros con 119 adiciones y 19 borrados
  1. +22
    -3
      lib/pages/team_page/notifier/team_page_notifier.dart
  2. +1
    -1
      lib/pages/team_page/team_page.dart
  3. +17
    -0
      lib/widgets/team/fans_list/bloc/team_list_fans_bloc.dart
  4. +8
    -0
      lib/widgets/team/fans_list/bloc/team_list_fans_event.dart
  5. +21
    -3
      lib/widgets/team/fans_list/bloc/team_list_fans_repository.dart
  6. +13
    -5
      lib/widgets/team/fans_list/team_fans_widget.dart
  7. +20
    -0
      lib/widgets/team/filter/team_filter_widget.dart
  8. +17
    -7
      lib/widgets/team/input/team_input_widget.dart

+ 22
- 3
lib/pages/team_page/notifier/team_page_notifier.dart Ver fichero

@@ -4,20 +4,30 @@ import 'package:zhiying_comm/util/log/let_log.dart';
class TeamPageNotifier with ChangeNotifier {
/// taBar选中的index
int tabSelectIndex = 0;
bool isSearch = false;
String keyword;

/// 筛选的条件
Map<String, String> reqArgs = {};

/// 更新筛选条件
void updateSortCondition(String key, String args) {
reqArgs[key] = args;
Logger.log('updateSortCondition reqArgs = ${reqArgs?.toString()}');
this.isSearch = false;
this.reqArgs[key] = args;
notifyListeners();
}

/// 重置
void searchReset(String keyword) {
this.isSearch = true;
this.keyword = keyword;
this.reqArgs.clear();
notifyListeners();
}

/// 更新选中Index
void updateTabIndex(int index) {
print('111111');
isSearch = false;
this.tabSelectIndex = index;
}

@@ -30,4 +40,13 @@ class TeamPageNotifier with ChangeNotifier {
int getTabIndex() {
return this.tabSelectIndex;
}

/// 获取搜索关键字
String getKeyword(){
return this.keyword;
}
/// 获取是否是搜索方式
bool getSearch() {
return this.isSearch;
}
}

+ 1
- 1
lib/pages/team_page/team_page.dart Ver fichero

@@ -127,7 +127,7 @@ class _TeamPageContainerState extends State<_TeamPageContainer> {
SliverToBoxAdapter(child: SizedBox(height: 8)),

/// 输入框
SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(min: 34, max: 34, child: TeamInputWidget(styleModel)), pinned: true),
SliverPersistentHeader(delegate: CustomSliverPersistentHeaderDelegate(min: 34, max: 34, child: TeamInputWidget(styleModel, _controller)), pinned: true),

/// 悬停TabBar
SliverPersistentHeader(


+ 17
- 0
lib/widgets/team/fans_list/bloc/team_list_fans_bloc.dart Ver fichero

@@ -50,6 +50,12 @@ class TeamListFansBloc extends Bloc<TeamListFansEvent, TeamListFansState> {
if (event is TeamListFansFilterEvent) {
yield* _mapFilterEventToState(event);
}

/// 搜索
if(event is TeamListFansSearchEvent){
yield* _mapSearchEventToState(event);
}

}

/// 初始化
@@ -103,4 +109,15 @@ class TeamListFansBloc extends Bloc<TeamListFansEvent, TeamListFansState> {
yield TeamListFansErrorState();
}
}

/// 搜索
Stream<TeamListFansState> _mapSearchEventToState(TeamListFansSearchEvent event) async*{
var result = await repository.fetchSearchData(event?.keyword);
if (!EmptyUtil.isEmpty(result)) {
yield TeamListFansLoadedState(model: result);
} else {
yield TeamListFansErrorState();
}
}

}

+ 8
- 0
lib/widgets/team/fans_list/bloc/team_list_fans_event.dart Ver fichero

@@ -40,4 +40,12 @@ class TeamListFansFilterEvent extends TeamListFansEvent{
const TeamListFansFilterEvent({@required this.args});
@override
List<Object> get props => [this.args];
}

/// 搜索
class TeamListFansSearchEvent extends TeamListFansEvent{
final String keyword;
TeamListFansSearchEvent(this.keyword);
@override
List<Object> get props => [this.keyword];
}

+ 21
- 3
lib/widgets/team/fans_list/bloc/team_list_fans_repository.dart Ver fichero

@@ -16,6 +16,24 @@ class TeamListFansRepository {

TeamListFansRepository({this.type = 'all'});

/// 搜索对方法
Future<TeamFansListModel> fetchSearchData(String keyword) async {
try {
if (!EmptyUtil.isEmpty(keyword)) {
var result = await NetUtil.post('/api/v1/user/fans/search', params: {'keyword': keyword}, method: NetMethod.POST);
if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
TeamFansListModel model = TeamFansListModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
if (null != model && !EmptyUtil.isEmpty(model?.fans) && model.fans.length > 0) {
return model;
}
}
}
} catch (e, s) {
Logger.error(e, s);
}
return null;
}

/// 初始化方法
Future<TeamFansListModel> fetchInitData() async {
_currentPage = 1;
@@ -49,8 +67,8 @@ class TeamListFansRepository {
}

/// 整体筛选排序的方法
Future<TeamFansListModel> fetchFilter(final Map<String ,String > reqArgs) async{
if(!EmptyUtil.isEmpty(reqArgs)) {
Future<TeamFansListModel> fetchFilter(final Map<String, String> reqArgs) async {
if (!EmptyUtil.isEmpty(reqArgs)) {
_reqArgs = reqArgs;
return fetchInitData();
}
@@ -102,7 +120,7 @@ class TeamListFansRepository {
_reqArgs.forEach((key, value) {
// sb.write(key);
// sb.write('=');
if(!EmptyUtil.isEmpty(value)) {
if (!EmptyUtil.isEmpty(value)) {
sb.write(value);
sb.write('&');
}


+ 13
- 5
lib/widgets/team/fans_list/team_fans_widget.dart Ver fichero

@@ -78,11 +78,19 @@ class __TeamFansWidgetContainerState extends State<_TeamFansWidgetContainer> {
TeamPageNotifier notifier = Provider.of<TeamPageNotifier>(context);
if (null != notifier) {
tabSelectIndex = notifier?.getTabIndex() ?? 0;
Map<String, String> reqArgs = notifier?.getReqArgs() ?? null;
if (widget.tabCurrentIndex == tabSelectIndex && !EmptyUtil.isEmpty(reqArgs)) {
Logger.log('didChangeDependencies, currentTabIndex = ${widget?.tabCurrentIndex}, tabSelectIndex = $tabSelectIndex , reqArgs = ${reqArgs?.toString()}');
// _refreshController.refreshToIdle();
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansFilterEvent(args: reqArgs));
bool isSearch = notifier?.getSearch() ?? false;
Logger.log('isSearch ==== $isSearch');

/// 如果是搜索框
if(isSearch){
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansSearchEvent(notifier?.getKeyword()));
}else {
Map<String, String> reqArgs = notifier?.getReqArgs() ?? null;
if (widget.tabCurrentIndex == tabSelectIndex && !EmptyUtil.isEmpty(reqArgs)) {
Logger.log('didChangeDependencies, currentTabIndex = ${widget?.tabCurrentIndex}, tabSelectIndex = $tabSelectIndex , reqArgs = ${reqArgs?.toString()}');
// _refreshController.refreshToIdle();
BlocProvider.of<TeamListFansBloc>(context).add(TeamListFansFilterEvent(args: reqArgs));
}
}
}
super.didChangeDependencies();


+ 20
- 0
lib/widgets/team/filter/team_filter_widget.dart Ver fichero

@@ -43,6 +43,26 @@ class _TeamFilterWidgetState extends State<TeamFilterWidget> {
setState(() {});
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
try {
TeamPageNotifier notifier = Provider.of<TeamPageNotifier>(context);
if (null != notifier) {
bool needRebuild = notifier?.getSearch()?? false;
if(needRebuild){
widget.styleModel.teamViewSortList.forEach((element) {
element.selectState = 0;
});
setState(() {});
}
}
}catch(e, s){
Logger.error(e, s);
}

}

@override
Widget build(BuildContext context) {
return Container(


+ 17
- 7
lib/widgets/team/input/team_input_widget.dart Ver fichero

@@ -1,12 +1,15 @@
import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/team_page/model/team_style_model.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:zhiying_base_widget/pages/team_page/notifier/team_page_notifier.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:provider/provider.dart';

class TeamInputWidget extends StatefulWidget {
TeamStyleModel styleModel;
TabController tabController;

TeamInputWidget(this.styleModel);
TeamInputWidget(this.styleModel, this.tabController);

@override
_TeamInputWidgetState createState() => _TeamInputWidgetState();
@@ -18,22 +21,28 @@ class _TeamInputWidgetState extends State<TeamInputWidget> {
bool _showCancel = false;

/// 搜索方法
void _onSearchClick() {}
void _onSearchClick() {
String text = _controller?.text?.toString()?.trim();
if (!EmptyUtil.isEmpty(text) && text.length > 0) {
widget?.tabController?.index = 0;
Provider.of<TeamPageNotifier>(context, listen: false).searchReset(text);
}
}

/// 点击取消输入
void _cancel() {
_controller?.clear();
}

void _onChange(text){
if(!EmptyUtil.isEmpty(text)){
if(!_showCancel){
void _onChange(text) {
if (!EmptyUtil.isEmpty(text)) {
if (!_showCancel) {
setState(() {
_showCancel = true;
});
}
}else{
if(_showCancel) {
} else {
if (_showCancel) {
setState(() {
_showCancel = false;
});
@@ -105,6 +114,7 @@ class _TeamInputWidgetState extends State<TeamInputWidget> {
controller: _controller,
focusNode: _focusNode,
onChanged: _onChange,
onSubmitted: (text) => _onSearchClick(),
style: TextStyle(fontSize: 11, color: HexColor.fromHex(widget?.styleModel?.headerNoReferrerInputColor ?? '#000000'), textBaseline: TextBaseline.alphabetic),
decoration: InputDecoration(
focusedBorder: InputBorder.none,


Cargando…
Cancelar
Guardar