fix(mobile-next): 登录失败改为顶部 toast,2 秒后自动消失
改 company_login_page.dart 与 company_login_logic.dart。 保留「工号或密码不正确」「网络异常,请稍后重试」;去掉按钮下方常驻错误字。 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
87a5930906
commit
092f513708
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:openim/core/controller/im_controller.dart';
|
import 'package:openim/core/controller/im_controller.dart';
|
||||||
@@ -15,12 +17,14 @@ class CompanyLoginLogic extends GetxController {
|
|||||||
final staffError = RxnString();
|
final staffError = RxnString();
|
||||||
final pwdError = RxnString();
|
final pwdError = RxnString();
|
||||||
final toast = RxnString();
|
final toast = RxnString();
|
||||||
|
Timer? _toastTimer;
|
||||||
|
|
||||||
final _auth = AuthApi();
|
final _auth = AuthApi();
|
||||||
final _im = Get.find<IMController>();
|
final _im = Get.find<IMController>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
|
_toastTimer?.cancel();
|
||||||
staffCtrl.dispose();
|
staffCtrl.dispose();
|
||||||
pwdCtrl.dispose();
|
pwdCtrl.dispose();
|
||||||
super.onClose();
|
super.onClose();
|
||||||
@@ -28,6 +32,14 @@ class CompanyLoginLogic extends GetxController {
|
|||||||
|
|
||||||
void toggleObscure() => obscure.toggle();
|
void toggleObscure() => obscure.toggle();
|
||||||
|
|
||||||
|
void _showToast(String msg) {
|
||||||
|
toast.value = msg;
|
||||||
|
_toastTimer?.cancel();
|
||||||
|
_toastTimer = Timer(const Duration(seconds: 2), () {
|
||||||
|
toast.value = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> submit() async {
|
Future<void> submit() async {
|
||||||
if (submitting.value) return;
|
if (submitting.value) return;
|
||||||
final staffNo = staffCtrl.text.trim();
|
final staffNo = staffCtrl.text.trim();
|
||||||
@@ -58,10 +70,10 @@ class CompanyLoginLogic extends GetxController {
|
|||||||
Get.find<CacheController>().resetCache();
|
Get.find<CacheController>().resetCache();
|
||||||
AppNavigator.startMain(conversations: conversations);
|
AppNavigator.startMain(conversations: conversations);
|
||||||
} on AuthException catch (e) {
|
} on AuthException catch (e) {
|
||||||
toast.value = e.network ? '网络异常,请稍后重试' : '工号或密码不正确';
|
_showToast(e.network ? '网络异常,请稍后重试' : '工号或密码不正确');
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logger.print('company login e: $e $s');
|
Logger.print('company login e: $e $s');
|
||||||
toast.value = '网络异常,请稍后重试';
|
_showToast('网络异常,请稍后重试');
|
||||||
} finally {
|
} finally {
|
||||||
submitting.value = false;
|
submitting.value = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,77 +16,94 @@ class CompanyLoginPage extends StatelessWidget {
|
|||||||
final logic = Get.find<CompanyLoginLogic>();
|
final logic = Get.find<CompanyLoginLogic>();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.pageBg,
|
backgroundColor: AppColors.pageBg,
|
||||||
body: SafeArea(
|
body: Stack(
|
||||||
child: LayoutBuilder(
|
children: [
|
||||||
builder: (context, constraints) {
|
SafeArea(
|
||||||
return SingleChildScrollView(
|
child: LayoutBuilder(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: AppGap.x8),
|
builder: (context, constraints) {
|
||||||
child: ConstrainedBox(
|
return SingleChildScrollView(
|
||||||
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
padding: const EdgeInsets.symmetric(horizontal: AppGap.x8),
|
||||||
child: IntrinsicHeight(
|
child: ConstrainedBox(
|
||||||
child: Column(
|
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
||||||
children: [
|
child: IntrinsicHeight(
|
||||||
const Spacer(flex: 2),
|
child: Column(
|
||||||
_logo(),
|
children: [
|
||||||
const SizedBox(height: AppGap.x4),
|
const Spacer(flex: 2),
|
||||||
Text(
|
_logo(),
|
||||||
FeatureFlags.brandMigration ? '畅联' : 'OpenIM',
|
const SizedBox(height: AppGap.x4),
|
||||||
style: const TextStyle(
|
Text(
|
||||||
fontSize: 22,
|
FeatureFlags.brandMigration ? '畅联' : 'OpenIM',
|
||||||
fontWeight: FontWeight.w700,
|
style: const TextStyle(
|
||||||
color: AppColors.textPrimary,
|
fontSize: 22,
|
||||||
),
|
fontWeight: FontWeight.w700,
|
||||||
),
|
color: AppColors.textPrimary,
|
||||||
const SizedBox(height: AppGap.x1),
|
),
|
||||||
const Text(
|
|
||||||
'企业内部通讯',
|
|
||||||
style: TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary),
|
|
||||||
),
|
|
||||||
const SizedBox(height: AppGap.x8),
|
|
||||||
Obx(() => _field(
|
|
||||||
controller: logic.staffCtrl,
|
|
||||||
hint: '请输入工号',
|
|
||||||
icon: Icons.person_outline,
|
|
||||||
error: logic.staffError.value,
|
|
||||||
enabled: !logic.submitting.value,
|
|
||||||
)),
|
|
||||||
const SizedBox(height: AppGap.x3),
|
|
||||||
Obx(() => _field(
|
|
||||||
controller: logic.pwdCtrl,
|
|
||||||
hint: '请输入密码',
|
|
||||||
icon: Icons.lock_outline,
|
|
||||||
obscure: logic.obscure.value,
|
|
||||||
onToggleObscure: logic.toggleObscure,
|
|
||||||
error: logic.pwdError.value,
|
|
||||||
enabled: !logic.submitting.value,
|
|
||||||
onSubmitted: (_) => logic.submit(),
|
|
||||||
)),
|
|
||||||
const SizedBox(height: AppGap.x4),
|
|
||||||
Obx(() => _loginButton(logic)),
|
|
||||||
const SizedBox(height: AppGap.x3),
|
|
||||||
const Text(
|
|
||||||
'登录即代表同意内部使用规范',
|
|
||||||
style: TextStyle(fontSize: AppFont.small, color: AppColors.textSecondary),
|
|
||||||
),
|
|
||||||
Obx(() {
|
|
||||||
final msg = logic.toast.value;
|
|
||||||
if (msg == null) return const SizedBox.shrink();
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(top: AppGap.x3),
|
|
||||||
child: Text(
|
|
||||||
msg,
|
|
||||||
style: const TextStyle(fontSize: AppFont.sub, color: AppColors.danger),
|
|
||||||
),
|
),
|
||||||
);
|
const SizedBox(height: AppGap.x1),
|
||||||
}),
|
const Text(
|
||||||
const Spacer(flex: 3),
|
'企业内部通讯',
|
||||||
],
|
style: TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary),
|
||||||
|
),
|
||||||
|
const SizedBox(height: AppGap.x8),
|
||||||
|
Obx(() => _field(
|
||||||
|
controller: logic.staffCtrl,
|
||||||
|
hint: '请输入工号',
|
||||||
|
icon: Icons.person_outline,
|
||||||
|
error: logic.staffError.value,
|
||||||
|
enabled: !logic.submitting.value,
|
||||||
|
)),
|
||||||
|
const SizedBox(height: AppGap.x3),
|
||||||
|
Obx(() => _field(
|
||||||
|
controller: logic.pwdCtrl,
|
||||||
|
hint: '请输入密码',
|
||||||
|
icon: Icons.lock_outline,
|
||||||
|
obscure: logic.obscure.value,
|
||||||
|
onToggleObscure: logic.toggleObscure,
|
||||||
|
error: logic.pwdError.value,
|
||||||
|
enabled: !logic.submitting.value,
|
||||||
|
onSubmitted: (_) => logic.submit(),
|
||||||
|
)),
|
||||||
|
const SizedBox(height: AppGap.x4),
|
||||||
|
Obx(() => _loginButton(logic)),
|
||||||
|
const SizedBox(height: AppGap.x3),
|
||||||
|
const Text(
|
||||||
|
'登录即代表同意内部使用规范',
|
||||||
|
style: TextStyle(fontSize: AppFont.small, color: AppColors.textSecondary),
|
||||||
|
),
|
||||||
|
const Spacer(flex: 3),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Obx(() {
|
||||||
|
final msg = logic.toast.value;
|
||||||
|
if (msg == null) return const SizedBox.shrink();
|
||||||
|
return SafeArea(
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(AppGap.x4, AppGap.x2, AppGap.x4, 0),
|
||||||
|
child: Material(
|
||||||
|
color: AppColors.bannerBg,
|
||||||
|
borderRadius: BorderRadius.circular(AppRadius.control),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: AppGap.x4, vertical: AppGap.x3),
|
||||||
|
child: Text(
|
||||||
|
msg,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(fontSize: AppFont.sub, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
}),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user