mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-22 23:36:36 +08:00
52 lines
1.4 KiB
Dart
52 lines
1.4 KiB
Dart
import 'dart:async' show Future;
|
|
|
|
import './net_utils.dart';
|
|
import '../model/user_info.dart';
|
|
import 'package:flutter_go/api/api.dart';
|
|
|
|
class DataUtils {
|
|
// 登陆获取用户信息
|
|
static Future doLogin(Map<String, String> params) async {
|
|
var response = await NetUtils.post(Api.DO_LOGIN, params);
|
|
try {
|
|
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
|
return userInfo;
|
|
} catch (err) {
|
|
return response['message'];
|
|
}
|
|
}
|
|
|
|
// 获取用户信息
|
|
static Future<UserInformation> getUserInfo(Map<String, String> params) async {
|
|
var response = await NetUtils.get(Api.GET_USER_INFO, params);
|
|
try {
|
|
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
|
return userInfo;
|
|
} catch (err) {
|
|
return response['message'];
|
|
}
|
|
}
|
|
|
|
// 验证登陆
|
|
static Future checkLogin() async {
|
|
var response = await NetUtils.get(Api.CHECK_LOGIN);
|
|
try {
|
|
if (response['success']) {
|
|
UserInformation userInfo = UserInformation.fromJson(response['data']);
|
|
return userInfo;
|
|
} else {
|
|
return response['success'];
|
|
}
|
|
} catch (err) {
|
|
return response['message'];
|
|
}
|
|
}
|
|
|
|
// 退出登陆
|
|
static Future<bool> logout() async {
|
|
var response = await NetUtils.get(Api.LOGOUT);
|
|
print('退出登陆 $response');
|
|
return response['success'];
|
|
}
|
|
}
|