feat: 移除crisp客服
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../widgets/kr_toast.dart';
|
||||
import '../common/app_config.dart';
|
||||
import '../routes/app_pages.dart';
|
||||
import '../widgets/dialogs/hi_dialog.dart';
|
||||
import '../modules/kr_crisp_chat/controllers/kr_crisp_controller.dart';
|
||||
|
||||
class KRCommonUtil {
|
||||
/// 是否正在打开客服(防重复点击)
|
||||
@@ -14,13 +10,7 @@ class KRCommonUtil {
|
||||
|
||||
/// 预热客服(提前初始化控制器)
|
||||
static void kr_warmUpCustomerService() {
|
||||
// 桌面端全部使用外部浏览器打开,无需预热
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
if (!Get.isRegistered<KRCrispController>()) {
|
||||
Get.put(KRCrispController(), permanent: true);
|
||||
debugPrint('客服系统预热中(持久模式)...');
|
||||
}
|
||||
}
|
||||
// 统一使用内置 Chatwoot 页面,无需预热原生 SDK
|
||||
}
|
||||
|
||||
/// 打开客服
|
||||
@@ -30,73 +20,18 @@ class KRCommonUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
final websiteId = '47fcc1ac-9674-4ab1-9e3c-6b5666f59a38'; // AppConfig.getInstance().kr_website_id;
|
||||
if (websiteId.isEmpty) {
|
||||
HIDialog.show(
|
||||
title: '提示',
|
||||
message: '加载失败',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 🔧 桌面端(Windows/macOS/Linux)直接跳转外部浏览器
|
||||
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
|
||||
_kr_isOpeningCustomerService = true;
|
||||
|
||||
// 显示加载提示
|
||||
_kr_isOpeningCustomerService = true;
|
||||
try {
|
||||
kr_showToast('userInfo.openingCustomerService'.tr);
|
||||
|
||||
// 直接使用 zh
|
||||
final Uri url = Uri.parse(
|
||||
'https://go.crisp.chat/chat/embed/?website_id=$websiteId&locale=zh',
|
||||
);
|
||||
|
||||
try {
|
||||
if (await canLaunchUrl(url)) {
|
||||
await launchUrl(url, mode: LaunchMode.externalApplication);
|
||||
} else {
|
||||
kr_showToast("common.cannotOpenBrowser".tr);
|
||||
}
|
||||
} catch (e) {
|
||||
kr_showToast("common.openLinkFailed".tr);
|
||||
} finally {
|
||||
// 延迟重置状态
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
_kr_isOpeningCustomerService = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
await Get.toNamed(Routes.KR_CHATWOOT);
|
||||
} catch (e) {
|
||||
debugPrint('打开客服失败: $e');
|
||||
HIDialog.show(title: '提示', message: '加载失败');
|
||||
} finally {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
_kr_isOpeningCustomerService = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 移动平台 (Android/iOS):直接调用原生 SDK,避免页面跳转闪烁
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
_kr_isOpeningCustomerService = true;
|
||||
|
||||
// 预先显示加载提示(可选,原生 SDK 启动很快)
|
||||
// kr_showToast('userInfo.openingCustomerService'.tr);
|
||||
|
||||
try {
|
||||
// 优先使用已注册的控制器
|
||||
KRCrispController crispController;
|
||||
if (Get.isRegistered<KRCrispController>()) {
|
||||
crispController = Get.find<KRCrispController>();
|
||||
} else {
|
||||
crispController = Get.put(KRCrispController(), permanent: true);
|
||||
}
|
||||
// 直接调用原生打开方法
|
||||
await crispController.kr_openNativeCrispChat();
|
||||
} catch (e) {
|
||||
debugPrint('打开原生客服失败: $e');
|
||||
// 如果原生失败,可以考虑降级到内置页面或报错
|
||||
Get.toNamed(Routes.KR_CRISP);
|
||||
} finally {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
_kr_isOpeningCustomerService = false;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// 提示 meesage: 提示内容, toastPosition: 提示显示的位置, timeout: 显示时间(毫秒)
|
||||
@@ -124,16 +59,16 @@ class KRCommonUtil {
|
||||
/// [bytes] 字节数
|
||||
static String kr_formatBytes(int bytes) {
|
||||
if (bytes <= 0) return "0 B";
|
||||
|
||||
|
||||
const List<String> suffixes = ["B", "KB", "MB", "GB", "TB"];
|
||||
int i = 0;
|
||||
double value = bytes.toDouble();
|
||||
|
||||
|
||||
while (value >= 1024 && i < suffixes.length - 1) {
|
||||
value /= 1024;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
return "${value.toStringAsFixed(2)} ${suffixes[i]}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user