This commit is contained in:
zhutao
2025-09-04 17:57:35 +08:00
parent 4d12f8afc2
commit 0231dcfe1a
34 changed files with 1339 additions and 368 deletions

View File

@@ -1,32 +1,22 @@
class UserInfo {
int? id;
String? name;
dynamic avatar;
String? avatar;
String? description;
String? email;
dynamic emailVerifiedAt;
dynamic googleId;
dynamic appleId;
String? lastLoginIp;
String? lastLoginTime;
dynamic lastUsedTime;
String? googleId;
String? appleId;
int? status;
String? createdAt;
String? updatedAt;
UserInfo({
this.id,
this.name,
this.avatar,
this.description,
this.email,
this.emailVerifiedAt,
this.googleId,
this.appleId,
this.lastLoginIp,
this.lastLoginTime,
this.lastUsedTime,
this.status,
this.createdAt,
this.updatedAt,
});
Map<String, dynamic> toJson() {
@@ -34,16 +24,11 @@ class UserInfo {
map["id"] = id;
map["name"] = name;
map["avatar"] = avatar;
map["description"] = description;
map["email"] = email;
map["email_verified_at"] = emailVerifiedAt;
map["google_id"] = googleId;
map["apple_id"] = appleId;
map["last_login_ip"] = lastLoginIp;
map["last_login_time"] = lastLoginTime;
map["last_used_time"] = lastUsedTime;
map["status"] = status;
map["created_at"] = createdAt;
map["updated_at"] = updatedAt;
return map;
}
@@ -51,19 +36,38 @@ class UserInfo {
id = json["id"] ?? 0;
name = json["name"] ?? "";
avatar = json["avatar"];
description = json["description"] ?? "";
email = json["email"] ?? "";
emailVerifiedAt = json["email_verified_at"];
googleId = json["google_id"];
appleId = json["apple_id"];
lastLoginIp = json["last_login_ip"] ?? "";
lastLoginTime = json["last_login_time"] ?? "";
lastUsedTime = json["last_used_time"];
status = json["status"] ?? 0;
createdAt = json["created_at"] ?? "";
updatedAt = json["updated_at"] ?? "";
}
/// copyWith 方法
UserInfo copyWith({
int? id,
String? name,
String? avatar,
String? description,
String? email,
String? googleId,
String? appleId,
int? status,
}) {
return UserInfo(
id: id ?? this.id,
name: name ?? this.name,
avatar: avatar ?? this.avatar,
description: description ?? this.description,
email: email ?? this.email,
googleId: googleId ?? this.googleId,
appleId: appleId ?? this.appleId,
status: status ?? this.status,
);
}
}
class LoginDto {
String? accessToken;
UserInfo? userInfo;

View File

@@ -1,3 +1,4 @@
import 'package:dio/dio.dart';
import '../../data/models/other_login_type.dart';
import '../dto/login_dto.dart';
@@ -53,3 +54,25 @@ Future<LoginDto> thirdLoginApi(String token, OtherLoginType type) async {
Future<void> deleteAccountApi() async {
return Request().get("/delete_account");
}
///修改用户资料
Future<UserInfo> updateUserInfoApi({
String? name,
List<int>? avatar,
String? description,
}) async {
FormData formData = FormData.fromMap({
"avatar": avatar != null
? MultipartFile.fromBytes(
avatar,
filename: "upload.jpg",
contentType: DioMediaType("image", "jpeg"),
)
: null,
"description": description,
"name": name,
});
//请求
var res = await Request().post("/user/update_profile", formData);
return UserInfo.fromJson(res);
}

View File

@@ -1,6 +1,7 @@
import 'package:dio/dio.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../providers/app_store.dart';
import '../dto/base_dto.dart';
///请求拦截器
@@ -8,8 +9,8 @@ void onRequest(
RequestOptions options,
RequestInterceptorHandler handler,
) async {
// String token = await AppStore.getToken();
// options.headers['Authorization'] = 'Bearer $token';
String token = await AppStore.getToken();
options.headers['Authorization'] = 'Bearer $token';
return handler.next(options);
}