mobile_skt/lib/apis/api.dart

70 lines
2.0 KiB
Dart

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 username, String password) {
return DioService.dio.post(
Urls.login,
data: {'username': username, 'password': password},
);
}
// 获取个人信息
Future<Response> getUserInfo() {
return DioService.dio.get(
Urls.getUserInfo,
);
}
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> 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});
}