feat: 移除crisp客服
This commit is contained in:
@@ -59,11 +59,6 @@ class HIMenuView extends GetView<HIMenuController> implements HasSwipeConfig {
|
||||
MenuItem(
|
||||
iconName: 'icon-5',
|
||||
title: '在线客服',
|
||||
onTap: () => KRCommonUtil.kr_openCustomerService(),
|
||||
),
|
||||
const MenuItem(
|
||||
iconName: 'icon-5',
|
||||
title: '在线客服2',
|
||||
route: Routes.KR_CHATWOOT,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import '../controllers/kr_crisp_controller.dart';
|
||||
|
||||
/// Crisp 聊天绑定
|
||||
class KRCrispBinding implements Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut<KRCrispController>(() => KRCrispController());
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:kaer_with_panels/app/common/app_config.dart';
|
||||
import 'package:kaer_with_panels/app/common/app_run_data.dart';
|
||||
import 'package:kaer_with_panels/app/localization/kr_language_utils.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../services/kr_device_info_service.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
// 移动平台使用原生 SDK
|
||||
import 'package:crisp_chat/crisp_chat.dart' as native_crisp;
|
||||
|
||||
/// 🔧 P15 重构: Crisp 聊天控制器
|
||||
/// - 移动平台 (Android/iOS): 使用 crisp_chat 原生 SDK,解决 WebView 黑屏问题
|
||||
/// - 桌面平台 (macOS/Windows): 使用 crisp_sdk WebView 实现
|
||||
class KRCrispController extends GetxController {
|
||||
// ========== 移动平台 (原生 SDK) ==========
|
||||
native_crisp.CrispConfig? _nativeConfig;
|
||||
|
||||
// ========== 共享状态 ==========
|
||||
final RxBool kr_isLoading = true.obs;
|
||||
final RxBool kr_isInitialized = false.obs;
|
||||
|
||||
/// 是否为移动平台
|
||||
bool get _isMobilePlatform => Platform.isAndroid || Platform.isIOS;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
debugPrint('🐛 [KRCrispController] onInit triggered (Hash: ${hashCode})');
|
||||
if (_isMobilePlatform) {
|
||||
_kr_prepareMobileConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 移动平台方法 (Android/iOS - 原生 SDK)
|
||||
// ==========================================
|
||||
|
||||
/// 准备移动平台 Crisp 配置
|
||||
void _kr_prepareMobileConfig() {
|
||||
try {
|
||||
kr_isLoading.value = false; // 原生 SDK 不需要加载状态
|
||||
|
||||
final appData = KRAppRunData();
|
||||
final userEmail = appData.kr_account.value ?? '';
|
||||
final deviceId = KRDeviceInfoService().deviceId ?? 'unknown';
|
||||
final identifier = userEmail.isNotEmpty ? userEmail : deviceId;
|
||||
|
||||
// 创建原生 SDK 配置
|
||||
_nativeConfig = native_crisp.CrispConfig(
|
||||
websiteID: '47fcc1ac-9674-4ab1-9e3c-6b5666f59a38',
|
||||
user: native_crisp.User(
|
||||
email: null,
|
||||
nickName: identifier,
|
||||
),
|
||||
);
|
||||
|
||||
// 🔧 P15-Optim: 尝试在初始化时就设置 Session,而不是打开时
|
||||
final currentLanguage = KRLanguageUtils.getCurrentLanguageCode();
|
||||
native_crisp.FlutterCrispChat.setSessionString(
|
||||
key: 'platform',
|
||||
value: Platform.isAndroid ? 'android' : 'ios',
|
||||
);
|
||||
native_crisp.FlutterCrispChat.setSessionString(
|
||||
key: 'language',
|
||||
value: currentLanguage,
|
||||
);
|
||||
native_crisp.FlutterCrispChat.setSessionString(
|
||||
key: 'device_id',
|
||||
value: deviceId,
|
||||
);
|
||||
|
||||
kr_isInitialized.value = true;
|
||||
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] Crisp 原生 SDK 配置及Session已预设');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] 准备 Crisp 配置时出错: $e');
|
||||
}
|
||||
kr_isInitialized.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 打开原生 Crisp 聊天界面 (移动平台)
|
||||
Future<void> kr_openNativeCrispChat() async {
|
||||
if (_nativeConfig == null) {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] Crisp 配置未准备好');
|
||||
}
|
||||
// 尝试重新准备
|
||||
_kr_prepareMobileConfig();
|
||||
if (_nativeConfig == null) return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] 正在打开 Crisp 原生聊天界面...');
|
||||
}
|
||||
|
||||
await native_crisp.FlutterCrispChat.openCrispChat(config: _nativeConfig!);
|
||||
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] Crisp 聊天界面已打开');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] 打开 Crisp 聊天时出错: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 生命周期管理
|
||||
// ==========================================
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
if (_isMobilePlatform) {
|
||||
// 移动平台:原生 SDK 无需手动清理
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] onClose - 原生 SDK 无需手动清理');
|
||||
}
|
||||
}
|
||||
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import '../controllers/kr_crisp_controller.dart';
|
||||
import 'package:kaer_with_panels/app/localization/app_translations.dart';
|
||||
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
|
||||
import '../../../widgets/kr_simple_loading.dart';
|
||||
|
||||
/// 🔧 P15 重构: Crisp 客服聊天视图
|
||||
/// - 移动平台 (Android/iOS): 打开原生聊天界面后自动返回
|
||||
/// - 桌面平台 (macOS/Windows/Linux): 直接跳转外部浏览器,不进入此页面
|
||||
class KRCrispView extends GetView<KRCrispController> {
|
||||
const KRCrispView({Key? key}) : super(key: key);
|
||||
|
||||
/// 是否为移动平台
|
||||
bool get _isMobilePlatform => Platform.isAndroid || Platform.isIOS;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: _kr_buildAppBar(context),
|
||||
body: _kr_buildBody(context),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建导航栏
|
||||
PreferredSizeWidget _kr_buildAppBar(BuildContext context) {
|
||||
return AppBar(
|
||||
backgroundColor: Theme.of(context).cardColor,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
AppTranslations.kr_userInfo.customerService,
|
||||
style: KrAppTextStyle(
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
Icons.arrow_back_ios,
|
||||
size: 20.sp,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建主体内容
|
||||
Widget _kr_buildBody(BuildContext context) {
|
||||
return Container(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Obx(() {
|
||||
if (!controller.kr_isInitialized.value) {
|
||||
return _kr_buildErrorView(context);
|
||||
}
|
||||
// 显示加载中界面,同时原生聊天界面在后台启动
|
||||
return _kr_buildLoadingView(context, '正在加载客服');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// 打开原生 Crisp 聊天界面 (移动平台)
|
||||
void _kr_openNativeCrispChat(BuildContext context) async {
|
||||
if (!controller.kr_isInitialized.value) {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] Crisp 未初始化,无法打开聊天');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] 正在打开原生 Crisp 聊天界面...');
|
||||
}
|
||||
|
||||
// 打开原生聊天界面
|
||||
await controller.kr_openNativeCrispChat();
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
print('[P15-Mobile] 打开 Crisp 聊天时出错: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 构建加载视图
|
||||
Widget _kr_buildLoadingView(BuildContext context, String message) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
KRSimpleLoading(
|
||||
color: Colors.blue,
|
||||
size: 50.0,
|
||||
),
|
||||
if (message.isNotEmpty) SizedBox(height: 16.sp),
|
||||
if (message.isNotEmpty)
|
||||
Text(
|
||||
message,
|
||||
style: KrAppTextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建错误视图
|
||||
Widget _kr_buildErrorView(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64.sp,
|
||||
color: Colors.red,
|
||||
),
|
||||
SizedBox(height: 16.sp),
|
||||
Text(
|
||||
'crisp.initFailed'.tr,
|
||||
style: KrAppTextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24.sp),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_isMobilePlatform) {
|
||||
_kr_openNativeCrispChat(context);
|
||||
} else {
|
||||
Get.back(); // 桌面端不应进入此页面,直接返回
|
||||
}
|
||||
},
|
||||
child: Text('common.retry'.tr),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user