feat: 修改权限问题

This commit is contained in:
2026-01-25 20:07:19 -08:00
parent 94d0a78e89
commit e00754847d
5 changed files with 46 additions and 107 deletions
@@ -38,8 +38,7 @@ class HIAntiLostController extends GetxController {
} else {
// Mobile: Use Gal to save to gallery
// Check permission
final hasAccess = await Gal.hasAccess();
if (!hasAccess) {
if (!await Gal.hasAccess()) {
await Gal.requestAccess();
}
@@ -51,7 +50,11 @@ class HIAntiLostController extends GetxController {
} catch (e) {
debugPrint("Save image error: $e");
if (e is GalException) {
KRCommonUtil.kr_showToast("保存失败: No Permission");
if (e.type == GalExceptionType.accessDenied) {
await Gal.requestAccess();
} else {
KRCommonUtil.kr_showToast("保存失败: ${e.type.name}");
}
} else {
KRCommonUtil.kr_showToast("保存失败: $e");
}
@@ -74,15 +74,9 @@ class HIUserInfoView extends GetView<HIUserInfoController> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Obx(() {
final account = KRAppRunData.getInstance()
.kr_account
.value;
final isDeviceLogin = account != null &&
account.startsWith('9000');
final accountText = (account == null ||
isDeviceLogin)
? '待绑定'
: '${KRAppRunData.getInstance().kr_account.value.toString()}';
final authType = KRAppRunData.getInstance().kr_authType.value;
final accountText = authType == 'email' ? '${KRAppRunData.getInstance().kr_account.value.toString()}' : '待绑定';
return Text(
accountText,
style: TextStyle(
@@ -11,37 +11,25 @@ class KRChatwootController {
final String baseUrl = 'https://app.chatwoot.com';
final String inboxIdentifier = 'YXQmh16ymNYW1SVybhnoQQ9w';
KRChatwootController() {
KRSecureStorage().kr_readData(key: 'USER_INFO').then((value) {
print('KRSecureStorage_keyUserInfo: $value');
});
}
/// 获取当前用户信息
/// 建议从你的全局 UserState 或本地存储中动态获取
ChatwootUser get chatUser {
final appRunData = KRAppRunData.getInstance();
final userId = appRunData.kr_userId.value?.toString();
final deviceId = appRunData.deviceId;
final authType = appRunData.kr_authType;
final account = appRunData.kr_account.value;
// 优先使用 userId 作为唯一标识,如果没有则使用 deviceId
final identifier = userId ?? deviceId ?? 'unknown_user';
// 名字使用账号,如果没有则显示 Guest
final name = account ?? 'Guest';
// 邮箱如果是邮箱格式则使用,否则构造一个唯一的虚拟邮箱以满足格式要求
String email = '';
if (account != null && account.contains('@')) {
email = account;
if (authType == 'device') {
email = account.toString();
} else {
email = '$identifier@hifastvpn.com';
email = '待绑定$deviceId';
}
return ChatwootUser(
identifier: identifier, // 必填:用于关联历史聊天记录
name: name,
identifier: account, // 必填:用于关联历史聊天记录
name: deviceId,
email: email,
);
}
@@ -14,56 +14,28 @@ class _KRChatwootViewState extends State<KRChatwootView> {
// 实例化控制器
final KRChatwootController _controller = KRChatwootController();
// 控制加载遮罩状态
bool _isPageLoading = true;
@override
Widget build(BuildContext context) {
return Scaffold(
// 设置背景色为白色,确保顶部 20px 区域不漏出底色
backgroundColor: Colors.white,
body: Padding(
// 在这里设置顶部 20px 的间距
padding: const EdgeInsets.only(top: 20.0),
child: Stack(
children: [
ChatwootWidget(
baseUrl: _controller.baseUrl,
websiteToken: _controller.inboxIdentifier,
user: _controller.chatUser,
locale: "zh_CN",
onAttachFile: _controller.onFilePicker,
onLoadStarted: () {
debugPrint("KRChatwoot: 开始加载 SDK");
},
closeWidget: () {
print('返回');
Get.back();
},
onLoadCompleted: () {
debugPrint("KRChatwoot: SDK 加载完毕");
if (mounted) {
setState(() => _isPageLoading = false);
}
},
),
// 获取系统状态栏高度
final double statusBarHeight = MediaQuery.of(context).padding.top;
// 加载中的占位图
if (_isPageLoading)
Container(
color: Colors.white,
child: const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(strokeWidth: 2),
const SizedBox(height: 16),
Text("正在连接客服...", style: TextStyle(color: Colors.grey)),
],
),
),
),
],
return Scaffold(
backgroundColor: const Color(0xFFF9F9FB),
body: SafeArea(
top: false, // 依然保持禁用自动顶部保护
child: Padding(
// 在状态栏高度的基础上减去 10 像素,实现向上移动
padding: EdgeInsets.only(top: statusBarHeight - 10),
child: ChatwootWidget(
baseUrl: _controller.baseUrl,
websiteToken: _controller.inboxIdentifier,
user: _controller.chatUser,
locale: "zh_CN",
onAttachFile: _controller.onFilePicker,
onLoadStarted: () => debugPrint("KRChatwoot: 开始加载 SDK"),
closeWidget: () => Get.back(),
onLoadCompleted: () => debugPrint("KRChatwoot: SDK 加载完毕"),
),
),
),
);