初始化提交

This commit is contained in:
2025-09-23 16:23:15 +08:00
commit 877b18a70f
590 changed files with 53617 additions and 0 deletions
@@ -0,0 +1,12 @@
import 'package:get/get.dart';
import '../controllers/kr_delete_account_controller.dart';
class KrDeleteAccountBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<KRDeleteAccountController>(
() => KRDeleteAccountController(),
);
}
}
@@ -0,0 +1,109 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/common/app_run_data.dart';
import 'package:kaer_with_panels/app/model/enum/kr_request_type.dart';
import 'package:kaer_with_panels/app/services/api_service/kr_auth_api.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import '../../../localization/app_translations.dart';
class KRDeleteAccountController extends GetxController {
// 验证码输入框控制器
final TextEditingController kr_codeController = TextEditingController();
// 验证码输入框是否有文本
final RxBool kr_codeHasText = false.obs;
// 是否可以发送验证码
final RxBool kr_canSendCode = true.obs;
// 倒计时秒数
final RxInt kr_countdown = 60.obs;
// 定时器
Timer? _timer;
// API 实例
final KRAuthApi _authApi = KRAuthApi();
@override
void onInit() {
super.onInit();
// 监听验证码输入框文本变化
kr_codeController.addListener(() {
kr_codeHasText.value = kr_codeController.text.isNotEmpty;
});
}
@override
void onClose() {
kr_codeController.dispose();
_timer?.cancel();
super.onClose();
}
// 发送验证码
Future<void> kr_sendCode() async {
final account = KRAppRunData.getInstance().kr_account;
if (account == null || account.isEmpty) {
KRCommonUtil.kr_showToast('账号不能为空');
return;
}
// 判断账号类型
final isEmail = KRAppRunData.getInstance().kr_loginType == KRLoginType.kr_email;
final type = isEmail ? KRLoginType.kr_email : KRLoginType.kr_telephone;
// 发送验证码
final result = await _authApi.kr_sendCode(
type,
account,
KRAppRunData.getInstance().kr_areaCode, // 手机号不需要区号
2, // 删除账号的验证码类型
);
result.fold(
(error) {
KRCommonUtil.kr_showToast(error.msg);
},
(success) {
kr_canSendCode.value = false;
kr_countdown.value = 60;
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
if (kr_countdown.value > 0) {
kr_countdown.value--;
} else {
timer.cancel();
kr_canSendCode.value = true;
}
});
},
);
}
// 请求删除账号
Future<void> requestDeleteAccount() async {
if (kr_codeController.text.isEmpty) {
KRCommonUtil.kr_showToast(AppTranslations.kr_login.sendCode);
return;
}
final result = await _authApi.kr_deleteAccount(
KRAppRunData.getInstance().kr_loginType ?? KRLoginType.kr_telephone,
kr_codeController.text,
);
result.fold(
(error) {
KRCommonUtil.kr_showToast(error.msg);
},
(success) {
KRCommonUtil.kr_showToast('删除账号成功');
KRAppRunData.getInstance().kr_loginOut();
},
);
// TODO: 实现删除账号的逻辑
}
}
@@ -0,0 +1,195 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:kaer_with_panels/app/common/app_run_data.dart';
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';
import '../controllers/kr_delete_account_controller.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
class KRDeleteAccountView extends GetView<KRDeleteAccountController> {
const KRDeleteAccountView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text(
AppTranslations.kr_userInfo.myAccount,
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
onPressed: () {
// 先收起键盘
FocusScope.of(context).unfocus();
// 返回到首页
Get.until((route) => route.isFirst);
},
),
),
body: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(16.w),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 20.w),
KrLocalImage(
imageName: 'delete_account',
width: 150.w,
height: 150.w,
imageType: ImageType.png,
),
SizedBox(height: 20.w),
Text(
'${AppTranslations.kr_userInfo.myAccount} ${KRAppRunData.getInstance().kr_account}\n${AppTranslations.kr_userInfo.willBeDeleted}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
SizedBox(height: 20.w),
Text(
AppTranslations.kr_userInfo.deleteAccountWarning,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14.sp,
color: Theme.of(context).textTheme.bodySmall?.color,
),
),
SizedBox(height: 20.w),
// 验证码输入框
Container(
width: double.infinity,
height: 52.w,
decoration: ShapeDecoration(
color: Theme.of(context).cardColor,
shape: RoundedRectangleBorder(
side: BorderSide(width: 0.5, color: const Color(0xFFD2D2D2)),
borderRadius: BorderRadius.circular(10.r),
),
),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(left: 12.w),
child: Icon(
Icons.lock_outline,
size: 20.w,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
SizedBox(width: 8.w),
Expanded(
child: TextField(
controller: controller.kr_codeController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'login.enterCode'.tr,
hintStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
fontSize: 14.sp,
fontFamily: 'AlibabaPuHuiTi-Regular',
),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(vertical: 16.w),
),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontSize: 14.sp,
fontFamily: 'AlibabaPuHuiTi-Regular',
),
),
),
if (controller.kr_codeHasText.value)
GestureDetector(
onTap: () {
controller.kr_codeController.clear();
},
child: Container(
height: double.infinity,
padding: EdgeInsets.symmetric(horizontal: 8.w),
child: Icon(
Icons.close,
size: 20.w,
color: Theme.of(context).textTheme.bodyMedium?.color,
),
),
),
_buildSendCodeButton(context),
],
),
),
SizedBox(height: 20.w),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: controller.requestDeleteAccount,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
padding: EdgeInsets.symmetric(vertical: 12.w),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.w),
),
),
child: Text(
AppTranslations.kr_userInfo.requestDelete,
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
),
),
),
),
SizedBox(height: 20.w),
],
),
),
),
);
}
Widget _buildSendCodeButton(BuildContext context) {
return Obx(() => GestureDetector(
onTap: controller.kr_canSendCode.value ? controller.kr_sendCode : null,
child: Container(
height: double.infinity,
padding: EdgeInsets.symmetric(horizontal: 12.w),
decoration: BoxDecoration(
border: Border(
left: BorderSide(
width: 0.5,
color: const Color(0xFFD2D2D2),
),
),
),
child: Center(
child: Text(
controller.kr_canSendCode.value
? AppTranslations.kr_login.sendCode
: '${controller.kr_countdown}s',
style: TextStyle(
fontSize: 14.sp,
color: controller.kr_canSendCode.value
? const Color(0xFF2196F3)
: Theme.of(context).textTheme.bodySmall?.color,
fontFamily: 'AlibabaPuHuiTi-Regular',
fontWeight: FontWeight.w500,
),
),
),
),
));
}
}