mobile_skt/lib/apis/api.dart

68 lines
2.1 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:sk_base_mobile/constants/global_url.dart';
import 'package:sk_base_mobile/services/dio.service.dart';
import '../constants/constants.dart';
Future<Response> login(String? oauthType, String? token) {
return DioService.dio.post(Urls.login,
data: {'oauthType': oauthType, 'token': token},
options: Options(contentType: "application/x-www-form-urlencoded"));
}
Future<Response> logout() {
return DioService.dio.post(
Urls.logout,
);
}
Future<Response> deleteAccount() {
return DioService.dio.post(
Urls.deleteAccount,
);
}
Future<Response> getAppConfig() {
Map<String, dynamic> query = {'ver': 0};
return DioService.dio.get(Urls.getAppConfig, queryParameters: query);
}
Future<Response> saveUserInfo(Map<String, dynamic> data) {
return DioService.dio.post(Urls.saveUserInfo, data: data);
}
Future<Response> getUserInfo(String userId) {
Map<String, dynamic> data = {
"userId": userId,
};
return DioService.dio.get(Urls.getUserInfo, queryParameters: data);
}
Future<Response> uploadImg(File file) async {
// DateTime dateTime = DateTime.now();
// String fileName = file.path.split('/').last;
// String format = fileName.split('.').last;
// int imageTimeName = dateTime.millisecondsSinceEpoch +
// (dateTime.microsecondsSinceEpoch ~/ 1000000);
// String imageName = '$imageTimeName.$format';
// String host = AppInfoService.to.ossPolicy.host!;
// String dir = AppInfoService.to.ossPolicy.dir!;
// final filePath = await MultipartFile.fromFile(file.path, filename: fileName);
// final formData = FormData.fromMap({
// 'ossaccessKeyId': AppInfoService.to.ossPolicy.accessKeyId,
// 'policy': AppInfoService.to.ossPolicy.policy,
// 'signature': AppInfoService.to.ossPolicy.signature,
// 'callback': AppInfoService.to.ossPolicy.callback,
// 'key': '$dir/$imageName',
// 'file': filePath,
// });
// return DioService.dio.post(host, data: formData);
return {} as Response;
}
Future<Response> updateAvatar(String filename) {
return DioService.dio.post(Urls.updateAvatar, data: {'avatarPath': filename});
}