178 lines
6.6 KiB
Dart
178 lines
6.6 KiB
Dart
import 'dart:io';
|
||
|
||
import 'package:ef/ef.dart';
|
||
import 'package:fluwx/fluwx.dart';
|
||
import 'package:json_annotation/json_annotation.dart';
|
||
|
||
import 'package:path/path.dart' as p;
|
||
|
||
import 'package:vbvs_app/controller/mh_controller/user_data.dart';
|
||
part 'muser_info_controller.g.dart';
|
||
|
||
@JsonSerializable()
|
||
class MUserInfoModel {
|
||
int? message = 0; //消息数量
|
||
|
||
UserModel? user; //用户信息
|
||
String? token; //token值
|
||
String? runSystem; //运行系统
|
||
String? phoneVersion; //手机版本
|
||
String? deviceId; //手机唯一
|
||
String? deviceModel; //设备可见型号(如 "iPhone","iPad")
|
||
String? appVersion; //app版本信息
|
||
|
||
@JsonKey(ignore: true)
|
||
Session? superbase_session;
|
||
@JsonKey(ignore: true)
|
||
User? superbase_user;
|
||
|
||
String? img_bucket = 'user';
|
||
int? login = 0; //是否登录0:未登录 1:已登录
|
||
|
||
MUserInfoModel();
|
||
static MUserInfoModel fromJson(Map<String, dynamic> json) =>
|
||
_$MUserInfoModelFromJson(json);
|
||
Map<String, dynamic> toJson() => _$MUserInfoModelToJson(this);
|
||
}
|
||
|
||
class MUserInfoController extends GetControllerEx<MUserInfoModel> {
|
||
// 初始化实例
|
||
final Fluwx fluwx = Fluwx();
|
||
|
||
MUserInfoController() {
|
||
attr = GetModel(MUserInfoModel()).obs;
|
||
}
|
||
|
||
// Future<void> uploadImg() async {
|
||
// final ImagePicker picker = ImagePicker();
|
||
// final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||
// final user = Supabase.instance.client.auth.currentUser;
|
||
// try {
|
||
// if (image != null) {
|
||
// int fileSize = await image.length(); // 获取图片大小,单位为字节
|
||
// if (fileSize > 1048576) {
|
||
// // 1 MB = 1024 * 1024 bytes
|
||
// showToast("头像图片不能超过1MB");
|
||
// return;
|
||
// }
|
||
// final filePath = image.path; // 获取文件路径
|
||
// final fileExtension = p.extension(filePath); // 获取文件扩展名,包括点(.)
|
||
// // 获取当前日期并格式化为 yyyy-MM-dd
|
||
// final String folderName =
|
||
// DateFormat('yyyy-MM-dd').format(DateTime.now());
|
||
// final file = File(image.path);
|
||
// // 构造文件路径,文件会被上传到 record_img 文件夹下的当天日期文件夹
|
||
// var response = await ef.client.storage
|
||
// .from(model.img_bucket!)
|
||
// .upload('$folderName/${Uuid().v4()}$fileExtension', file);
|
||
// if (response != null) {
|
||
// String publicUrl =
|
||
// ef.client.storage.from(model.img_bucket!).getPublicUrl(response);
|
||
|
||
// print('文件上传成功: $response');
|
||
// print('文件上传成功: $publicUrl');
|
||
// String prefixToRemove = 'user/';
|
||
// // model.user!.tmpHead = model.user!.head;
|
||
// model.user!.tmpHead = publicUrl.startsWith(prefixToRemove)
|
||
// ? response.substring(prefixToRemove.length)
|
||
// : response;
|
||
// updateAll();
|
||
// }
|
||
// print('/$model.img_bucket');
|
||
// } else {
|
||
// print('未选择图片');
|
||
// return;
|
||
// }
|
||
// } catch (e) {
|
||
// print('上传失败: $e');
|
||
// }
|
||
// }
|
||
|
||
// updateData() {
|
||
// UserInfoController controller = Get.find();
|
||
// UserRepository userRepository = UserRepository();
|
||
// return userRepository.updateInfo(controller.model.user!);
|
||
// }
|
||
|
||
// autoLogin(String token) async {
|
||
// final UserInfoController userInfoController = Get.find();
|
||
// try {
|
||
// final Map<String, dynamic> requestBody = {
|
||
// 'token': token,
|
||
// };
|
||
|
||
// var response = await ApiService.request
|
||
// .post("/api/auth/account/info/autoLogin", data: requestBody);
|
||
// if (response.statusCode == 200) {
|
||
// if (response.data != null) {
|
||
// ApiResponse<UserModel> apiResponse = ApiResponse.fromJson(
|
||
// response.data,
|
||
// (json) => UserModel.fromJson(json as Map<String, dynamic>));
|
||
// if (apiResponse.code == HttpStatusCodes.ok) {
|
||
// userInfoController.model.user = apiResponse.data;
|
||
// userInfoController.model.token = response.headers['token']!.first;
|
||
// userInfoController.model.login = 1;
|
||
|
||
// final box = GetStorage();
|
||
// box.write(
|
||
// 'user', userInfoController.model.user!.toJson()); // 存储用户信息
|
||
// box.write('token', userInfoController.model.token); // 存储 token
|
||
// String efPd = await getValueBySysConfigKey(CommonVariables.efKey);
|
||
// if (efPd != null && efPd.isNotEmpty) {
|
||
// await initDataEf(key: efPd);
|
||
// } else {
|
||
// print("efPD为空,无法初始化");
|
||
// // 清除本地缓存
|
||
// final box = GetStorage();
|
||
// box.remove('user');
|
||
// box.remove('token');
|
||
// userInfoController.model.token = null;
|
||
// userInfoController.model.user = null;
|
||
// // 设置成未登录
|
||
// userInfoController.model.login = 0;
|
||
// return;
|
||
// }
|
||
|
||
// final AuthResponse res = await ef.client.auth.signInWithPassword(
|
||
// phone: userInfoController.model.user!.tel,
|
||
// password: userInfoController.model.user!.exp1!,
|
||
// );
|
||
// userInfoController.model.superbase_session = res.session;
|
||
// userInfoController.model.superbase_user = res.user;
|
||
// userInfoController.updateAll();
|
||
// // 登录成功移出网络检查监听
|
||
// Checknetwork.subscription?.cancel();
|
||
// }
|
||
// }
|
||
// } else {
|
||
// // 处理非 200 响应
|
||
// print('Failed to sign in. Status code: ${response.statusCode}');
|
||
// print('Response data: ${response.data}');
|
||
// }
|
||
// } catch (e) {
|
||
// e.printError();
|
||
// // 清除本地缓存
|
||
// final box = GetStorage();
|
||
// box.remove('user');
|
||
// box.remove('token');
|
||
// userInfoController.model.token = null;
|
||
// userInfoController.model.user = null;
|
||
// // 设置成未登录
|
||
// userInfoController.model.login = 0;
|
||
// }
|
||
// }
|
||
|
||
// // 拉起微信企业客服
|
||
// Future<void> openWeChatCustomerService() async {
|
||
// bool isWeChatInstalled = await fluwx.isWeChatInstalled;
|
||
// if (!isWeChatInstalled) {
|
||
// showToast("请先安装微信APP,再联系客服", color: color_error);
|
||
// return;
|
||
// }
|
||
// showToast('正在打开微信客服...', color: color_success);
|
||
// await fluwx.open(
|
||
// target: CustomerServiceChat(
|
||
// corpId: CommonVariables.wxCorpId, url: CommonVariables.wxKfUrl));
|
||
// }
|
||
}
|