feat(mobile-next): 工号登录与目录薄适配,并完成登录/会话/聊天/通讯录第一批界面
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
d787c0a477
commit
60b6590409
@@ -0,0 +1,194 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:openim_common/openim_common.dart';
|
||||
|
||||
import '../auth/auth_api.dart';
|
||||
import '../brand/app_tokens.dart';
|
||||
import '../directory/directory_api.dart';
|
||||
|
||||
class AddColleagueLogic extends GetxController {
|
||||
final staffCtrl = TextEditingController();
|
||||
final msgCtrl = TextEditingController(text: '你好,我想加你为同事');
|
||||
final sending = false.obs;
|
||||
final staffError = RxnString();
|
||||
final directoryHint = RxnString();
|
||||
|
||||
final _directory = DirectoryApi();
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
staffCtrl.dispose();
|
||||
msgCtrl.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<void> lookupDirectory() async {
|
||||
final id = staffCtrl.text.trim();
|
||||
if (id.isEmpty) {
|
||||
directoryHint.value = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final items = await _directory.search(keyword: id, limit: 5);
|
||||
final hit = items.where((e) => e.userID == id).toList();
|
||||
if (hit.isNotEmpty) {
|
||||
directoryHint.value = hit.first.nickname;
|
||||
} else if (items.isNotEmpty) {
|
||||
directoryHint.value = items.map((e) => '${e.nickname}(${e.userID})').join('、');
|
||||
} else {
|
||||
directoryHint.value = null;
|
||||
}
|
||||
} catch (_) {
|
||||
directoryHint.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> send() async {
|
||||
if (sending.value) return;
|
||||
final id = staffCtrl.text.trim();
|
||||
if (id.isEmpty) {
|
||||
staffError.value = '请输入对方工号';
|
||||
return;
|
||||
}
|
||||
staffError.value = null;
|
||||
sending.value = true;
|
||||
try {
|
||||
await OpenIM.iMManager.friendshipManager.addFriend(
|
||||
userID: id,
|
||||
reason: msgCtrl.text.trim().isEmpty ? '你好,我想加你为同事' : msgCtrl.text.trim(),
|
||||
);
|
||||
IMViews.showToast('申请已发送,等对方通过');
|
||||
Get.back();
|
||||
} on AuthException catch (e) {
|
||||
IMViews.showToast(e.message);
|
||||
} catch (_) {
|
||||
IMViews.showToast('发送失败,请确认工号正确、网络正常');
|
||||
} finally {
|
||||
sending.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AddColleaguePage extends StatelessWidget {
|
||||
const AddColleaguePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.put(AddColleagueLogic());
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.pageBg,
|
||||
appBar: AppBar(
|
||||
title: const Text('添加同事'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new, size: AppIconSize.md),
|
||||
onPressed: Get.back,
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(AppGap.x4),
|
||||
child: Column(
|
||||
children: [
|
||||
Obx(() => _box(
|
||||
controller: logic.staffCtrl,
|
||||
hint: '请输入对方工号',
|
||||
height: 48,
|
||||
error: logic.staffError.value,
|
||||
enabled: !logic.sending.value,
|
||||
onChanged: (_) {
|
||||
logic.staffError.value = null;
|
||||
logic.lookupDirectory();
|
||||
},
|
||||
)),
|
||||
Obx(() {
|
||||
final hint = logic.directoryHint.value;
|
||||
if (hint == null) return const SizedBox.shrink();
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: AppGap.x2),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(hint, style: const TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: AppGap.x3),
|
||||
_box(
|
||||
controller: logic.msgCtrl,
|
||||
hint: '你好,我想加你为同事',
|
||||
height: 96,
|
||||
maxLines: 4,
|
||||
enabled: !logic.sending.value,
|
||||
),
|
||||
const Spacer(),
|
||||
Obx(() {
|
||||
final busy = logic.sending.value;
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: FilledButton(
|
||||
onPressed: busy ? null : logic.send,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
disabledBackgroundColor: AppColors.primary.withOpacity(0.4),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppRadius.control)),
|
||||
),
|
||||
child: busy
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Text('发送申请', style: TextStyle(fontSize: AppFont.body, color: Colors.white)),
|
||||
),
|
||||
);
|
||||
}),
|
||||
const SizedBox(height: AppGap.x4),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _box({
|
||||
required TextEditingController controller,
|
||||
required String hint,
|
||||
required double height,
|
||||
int maxLines = 1,
|
||||
String? error,
|
||||
bool enabled = true,
|
||||
ValueChanged<String>? onChanged,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
height: height,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppGap.x3, vertical: AppGap.x2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.searchBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.control),
|
||||
border: Border.all(color: error != null ? AppColors.danger : Colors.transparent),
|
||||
),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
maxLines: maxLines,
|
||||
enabled: enabled,
|
||||
onChanged: onChanged,
|
||||
style: const TextStyle(fontSize: AppFont.body, color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(fontSize: AppFont.body, color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppGap.x1),
|
||||
child: Text(error, style: const TextStyle(fontSize: AppFont.small, color: AppColors.danger)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:openim_common/openim_common.dart';
|
||||
|
||||
import '../auth/company_login_logic.dart';
|
||||
import '../brand/app_tokens.dart';
|
||||
import '../feature_flags.dart';
|
||||
|
||||
/// 登录页第一批:v2 布局 + Token,保留 OpenIM 标识,不做畅联换标。
|
||||
class CompanyLoginPage extends StatelessWidget {
|
||||
const CompanyLoginPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.find<CompanyLoginLogic>();
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.pageBg,
|
||||
body: SafeArea(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppGap.x8),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: constraints.maxHeight),
|
||||
child: IntrinsicHeight(
|
||||
child: Column(
|
||||
children: [
|
||||
const Spacer(flex: 2),
|
||||
_logo(),
|
||||
const SizedBox(height: AppGap.x4),
|
||||
Text(
|
||||
FeatureFlags.brandMigration ? '畅联' : 'OpenIM',
|
||||
style: const TextStyle(
|
||||
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 Spacer(flex: 3),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _logo() {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppRadius.logo),
|
||||
child: Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
color: AppColors.primary,
|
||||
alignment: Alignment.center,
|
||||
child: ImageRes.loginLogo.toImage
|
||||
..width = 48
|
||||
..height = 48,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _field({
|
||||
required TextEditingController controller,
|
||||
required String hint,
|
||||
required IconData icon,
|
||||
String? error,
|
||||
bool obscure = false,
|
||||
VoidCallback? onToggleObscure,
|
||||
bool enabled = true,
|
||||
ValueChanged<String>? onSubmitted,
|
||||
}) {
|
||||
final borderColor = error != null ? AppColors.danger : Colors.transparent;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.searchBg,
|
||||
borderRadius: BorderRadius.circular(AppRadius.control),
|
||||
border: Border.all(color: borderColor, width: error != null ? 1 : 0),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppGap.x3),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: AppIconSize.sm, color: AppColors.textSecondary),
|
||||
const SizedBox(width: AppGap.x2),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
enabled: enabled,
|
||||
obscureText: obscure,
|
||||
onSubmitted: onSubmitted,
|
||||
inputFormatters: [LengthLimitingTextInputFormatter(32)],
|
||||
style: const TextStyle(fontSize: AppFont.body, color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
hintText: hint,
|
||||
hintStyle: const TextStyle(fontSize: AppFont.body, color: AppColors.textSecondary),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (onToggleObscure != null)
|
||||
IconButton(
|
||||
onPressed: onToggleObscure,
|
||||
icon: Icon(
|
||||
obscure ? Icons.visibility_off_outlined : Icons.visibility_outlined,
|
||||
size: AppIconSize.sm,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppGap.x1, left: AppGap.x1),
|
||||
child: Text(error, style: const TextStyle(fontSize: AppFont.small, color: AppColors.danger)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _loginButton(CompanyLoginLogic logic) {
|
||||
final busy = logic.submitting.value;
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: FilledButton(
|
||||
onPressed: busy ? null : logic.submit,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
disabledBackgroundColor: AppColors.primary.withOpacity(0.4),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppRadius.control)),
|
||||
),
|
||||
child: busy
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
|
||||
),
|
||||
SizedBox(width: AppGap.x2),
|
||||
Text('登录中', style: TextStyle(fontSize: AppFont.body, color: Colors.white)),
|
||||
],
|
||||
)
|
||||
: const Text('登 录', style: TextStyle(fontSize: AppFont.body, color: Colors.white)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user