mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-09-27 00:24:40 +08:00
个人中心、收藏、搜索
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
import 'dart:async' show Future;
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter_go/model/collection.dart';
|
||||
import 'package:flutter_go/model/version.dart';
|
||||
import 'package:flutter_go/model/widget.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:flutter_go/model/responseData.dart';
|
||||
|
||||
@ -39,7 +41,6 @@ class DataUtils {
|
||||
var response = await NetUtils.get(Api.CHECK_LOGIN);
|
||||
print('response: $response');
|
||||
try {
|
||||
print('1111');
|
||||
if (response['success']) {
|
||||
print('${response['success']} ${response['data']} response[succes]');
|
||||
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
||||
@ -104,15 +105,97 @@ class DataUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取widget列表处的树型数据
|
||||
static Future<List> getWidgetTreeList() async {
|
||||
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
||||
try {
|
||||
var response = await NetUtils.get(Api.GET_WIDGET_TREE);
|
||||
print('组件树:$response');
|
||||
if (response != null && response['success']) {
|
||||
return response['data'];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} catch (error) {
|
||||
print('获取组件树 error $error');
|
||||
}
|
||||
}
|
||||
|
||||
if (response['success']) {
|
||||
return response['data'];
|
||||
// 校验是否收藏
|
||||
static Future<bool> checkCollected(Map<String, String> params) async {
|
||||
print('url 地址:${Api.CHECK_COLLECTED} $params');
|
||||
try {
|
||||
var response = await NetUtils.post(Api.CHECK_COLLECTED, params);
|
||||
return response != null && response['hasCollected'];
|
||||
} catch (error) {
|
||||
print('校验收藏 error $error');
|
||||
}
|
||||
}
|
||||
|
||||
// 添加收藏
|
||||
static Future addCollected(Map<String, String> params, context) async {
|
||||
var response = await NetUtils.post(Api.ADD_COLLECTION, params);
|
||||
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||
transition: TransitionType.nativeModal);
|
||||
}
|
||||
return response != null && response['success'];
|
||||
}
|
||||
|
||||
// 移出收藏
|
||||
static Future removeCollected(Map<String, String> params, context) async {
|
||||
var response = await NetUtils.post(Api.REMOVE_COLLECTION, params);
|
||||
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||
transition: TransitionType.nativeModal);
|
||||
}
|
||||
return response != null && response['success'];
|
||||
}
|
||||
|
||||
// 获取全部收藏
|
||||
static Future getAllCollections(context) async {
|
||||
var response = await NetUtils.get(Api.GET_ALL_COLLECTION);
|
||||
List<Collection> responseList = [];
|
||||
if (response['status'] == 401 && response['message'] == '请先登录') {
|
||||
Application.router.navigateTo(context, '${Routes.loginPage}',
|
||||
transition: TransitionType.nativeModal);
|
||||
}
|
||||
if (response != null && response['success'] == true) {
|
||||
for (int i = 0; i < response['data'].length; i++) {
|
||||
Map<String, dynamic> tempCo = response['data'][i];
|
||||
responseList.add(Collection.fromJSON(
|
||||
{"name": tempCo['name'], "router": tempCo['url']}));
|
||||
}
|
||||
return responseList;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索组件
|
||||
static Future searchWidget(String name) async {
|
||||
var response = await NetUtils.get(Api.SEARCH_WIDGET, {"name": name});
|
||||
List<WidgetPoint> list = [];
|
||||
if (response != null && response['success'] == true) {
|
||||
for (int i = 0; i < response['data'].length; i++) {
|
||||
var json = response['data'][i];
|
||||
String routerName;
|
||||
if (json['display'] == 'old') {
|
||||
routerName = json['path'];
|
||||
} else {
|
||||
routerName = json['pageId'];
|
||||
}
|
||||
Map<String, dynamic> tempMap = {
|
||||
"name": json['name'],
|
||||
"cnName": json['name'],
|
||||
"routerName": routerName,
|
||||
"catId": int.parse(json['parentId'])
|
||||
};
|
||||
list.add(WidgetPoint.fromJSON(tempMap));
|
||||
}
|
||||
return list;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user