1,新增下载导出记录相关逻辑
2,iOS端查看导出记录及系统分享文件完成
This commit is contained in:
parent
e86c6a8dc9
commit
fd449954cf
@ -1,70 +1,62 @@
|
|||||||
//
|
|
||||||
// XSFlutterManager.m
|
|
||||||
// Runner
|
|
||||||
//
|
|
||||||
// Created by DaisyWu on 2023/10/14.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "XSFlutterManager.h"
|
#import "XSFlutterManager.h"
|
||||||
#include "GeneratedPluginRegistrant.h"
|
#include "GeneratedPluginRegistrant.h"
|
||||||
#import "CommonDefine.h"
|
#import "CommonDefine.h"
|
||||||
|
|
||||||
|
|
||||||
@interface XSFlutterManager ()
|
@interface XSFlutterManager ()
|
||||||
|
|
||||||
@property(nonatomic,strong) FlutterMethodChannel* methodChannel;
|
@property(nonatomic, strong) FlutterMethodChannel *methodChannel;
|
||||||
@property (nonatomic, copy) NSString *textToShare;
|
@property(nonatomic, copy) NSString *textToShare;
|
||||||
@property (nonatomic, copy) NSString *urlToShare;
|
@property(nonatomic, copy) NSString *urlToShare;
|
||||||
|
@property(nonatomic, copy) NSArray *activityItems;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation XSFlutterManager{
|
@implementation XSFlutterManager
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
self.textToShare = [[NSString alloc] init];
|
self.textToShare = [[NSString alloc] init];
|
||||||
self.textToShare = [[NSString alloc] init];
|
self.urlToShare = [[NSString alloc] init];
|
||||||
|
self.activityItems = [[NSArray alloc] init];
|
||||||
|
|
||||||
[self methodChannelFunction];
|
[self methodChannelFunction];
|
||||||
}
|
}
|
||||||
- (void)methodChannelFunction {
|
|
||||||
|
|
||||||
//创建 FlutterMethodChannel
|
- (void)methodChannelFunction {
|
||||||
self.methodChannel = [FlutterMethodChannel
|
// 创建 FlutterMethodChannel
|
||||||
methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
|
self.methodChannel = [FlutterMethodChannel methodChannelWithName:XSflutterMethodChannel binaryMessenger:self];
|
||||||
//设置监听
|
|
||||||
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall* methodCall, FlutterResult result) {
|
// 设置监听
|
||||||
// TODO
|
[self.methodChannel setMethodCallHandler:^(FlutterMethodCall *methodCall, FlutterResult result) {
|
||||||
NSString *method=methodCall.method;
|
NSString *method = methodCall.method;
|
||||||
//调用系统分享
|
// 调用系统分享
|
||||||
if ([method isEqualToString:XSflutterMethodSharePassword]) {
|
if ([method isEqualToString:XSflutterMethodSharePassword]) {
|
||||||
id params = methodCall.arguments;
|
id params = methodCall.arguments;
|
||||||
self.textToShare = @"您好,您的密码是:";
|
self.textToShare = @"您好,您的密码是:";
|
||||||
if ([params isKindOfClass:[NSDictionary class]]) {
|
if ([params isKindOfClass:[NSDictionary class]]) {
|
||||||
NSDictionary *paramDic = (NSDictionary *)params;
|
NSDictionary *paramDic = (NSDictionary *)params;
|
||||||
//分享的标题
|
// 分享的标题
|
||||||
self.textToShare = paramDic[@"shareText"];
|
self.textToShare = paramDic[@"shareText"];
|
||||||
self.urlToShare = paramDic[@"urlToShare"];
|
self.urlToShare = paramDic[@"urlToShare"];
|
||||||
}
|
}
|
||||||
if ([self.urlToShare isEqualToString:"fileShare"]) {
|
|
||||||
|
if ([self.urlToShare isEqualToString:@"fileShare"]) {
|
||||||
// 创建要分享或操作的文件对象
|
// 创建要分享或操作的文件对象
|
||||||
let fileURL = URL(fileURLWithPath: "/path/to/file.pdf")
|
NSURL *fileURL = [NSURL fileURLWithPath:self.textToShare];
|
||||||
|
|
||||||
// 将文件对象添加到数组中
|
// 将文件对象添加到数组中
|
||||||
let activityItems = [fileURL]
|
self.activityItems = @[fileURL];
|
||||||
} else {
|
} else {
|
||||||
//分享的url
|
// 分享的 URL
|
||||||
NSURL *urlToShare = [NSURL URLWithString:self.urlToShare];
|
NSURL *urlToShare = [NSURL URLWithString:self.urlToShare];
|
||||||
|
|
||||||
//在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
|
// 在这里呢 如果想分享图片 就把图片添加进去 文字什么的通上
|
||||||
NSArray *activityItems = @[self.textToShare,urlToShare];
|
self.activityItems = @[self.textToShare, urlToShare];
|
||||||
}
|
}
|
||||||
|
|
||||||
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
|
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:self.activityItems applicationActivities:nil];
|
||||||
|
|
||||||
//不出现在活动项目
|
// 不出现在活动项目
|
||||||
activityVC.excludedActivityTypes = @[UIActivityTypePrint];
|
activityVC.excludedActivityTypes = @[UIActivityTypePrint];
|
||||||
[self presentViewController:activityVC animated:YES completion:nil];
|
[self presentViewController:activityVC animated:YES completion:nil];
|
||||||
|
|
||||||
@ -72,40 +64,37 @@
|
|||||||
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
|
||||||
if (completed) {
|
if (completed) {
|
||||||
NSLog(@"completed");
|
NSLog(@"completed");
|
||||||
//分享 成功
|
// 分享成功
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"cancled");
|
NSLog(@"canceled");
|
||||||
//分享 取消
|
// 分享取消
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
result(@"push返回到flutter");
|
result(@"push返回到flutter");
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[GeneratedPluginRegistrant registerWithRegistry:self];
|
[GeneratedPluginRegistrant registerWithRegistry:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)viewWillAppear:(BOOL)animated {
|
||||||
|
|
||||||
|
|
||||||
-(void)viewWillAppear:(BOOL)animated{
|
|
||||||
[super viewWillAppear:animated];
|
[super viewWillAppear:animated];
|
||||||
[self.navigationController setNavigationBarHidden:YES];
|
[self.navigationController setNavigationBarHidden:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)viewWillDisappear:(BOOL)animated{
|
- (void)viewWillDisappear:(BOOL)animated {
|
||||||
[super viewWillDisappear:animated];
|
[super viewWillDisappear:animated];
|
||||||
[self.navigationController setNavigationBarHidden:NO];
|
[self.navigationController setNavigationBarHidden:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#pragma mark - Navigation
|
#pragma mark - Navigation
|
||||||
|
|
||||||
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
||||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||||
// Get the new view controller using [segue destinationViewController].
|
// Get the new view controller using [segue destinationViewController].
|
||||||
// Pass the selected object to the new view controller.
|
// Pass the selected object to the new view controller.
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -38,7 +38,8 @@ class BatchExportLogLogic extends BaseGetXController {
|
|||||||
final http.Response response = await http.get(Uri.parse(url));
|
final http.Response response = await http.get(Uri.parse(url));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final Directory directory = await getApplicationDocumentsDirectory();
|
final Directory directory = await getApplicationDocumentsDirectory();
|
||||||
final File file = File('${directory.path}/exported_file.pdf');
|
final File file = File(
|
||||||
|
'${directory.path}/record${DateTime.now().millisecondsSinceEpoch}.xlsx');
|
||||||
await file.writeAsBytes(response.bodyBytes);
|
await file.writeAsBytes(response.bodyBytes);
|
||||||
return file.path;
|
return file.path;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -225,7 +225,7 @@ class __DerivedRecordWidgetState extends State<_DerivedRecordWidget> {
|
|||||||
final http.Response response = await http.get(Uri.parse(url));
|
final http.Response response = await http.get(Uri.parse(url));
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final Directory directory = await getApplicationDocumentsDirectory();
|
final Directory directory = await getApplicationDocumentsDirectory();
|
||||||
final File file = File('${directory.path}/exported_file.xlsx');
|
final File file = File('${directory.path}/record.xlsx');
|
||||||
await file.writeAsBytes(response.bodyBytes);
|
await file.writeAsBytes(response.bodyBytes);
|
||||||
return file.path;
|
return file.path;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -3,17 +3,15 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:open_file/open_file.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:star_lock/appRouters.dart';
|
|
||||||
import 'package:star_lock/app_settings/app_colors.dart';
|
import 'package:star_lock/app_settings/app_colors.dart';
|
||||||
import 'package:star_lock/main/lockDetail/doorLockLog/exportSuccess/exportSuccess_logic.dart';
|
import 'package:star_lock/main/lockDetail/doorLockLog/exportSuccess/exportSuccess_logic.dart';
|
||||||
import 'package:star_lock/main/lockDetail/doorLockLog/exportSuccess/exportSuccess_state.dart';
|
import 'package:star_lock/main/lockDetail/doorLockLog/exportSuccess/exportSuccess_state.dart';
|
||||||
import 'package:star_lock/tools/NativeInteractionTool.dart';
|
import 'package:star_lock/tools/NativeInteractionTool.dart';
|
||||||
import 'package:star_lock/tools/commonDataManage.dart';
|
|
||||||
import 'package:star_lock/tools/submitBtn.dart';
|
import 'package:star_lock/tools/submitBtn.dart';
|
||||||
import 'package:star_lock/tools/titleAppBar.dart';
|
import 'package:star_lock/tools/titleAppBar.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
import 'package:open_file/open_file.dart';
|
|
||||||
|
|
||||||
class ExportSuccessPage extends StatefulWidget {
|
class ExportSuccessPage extends StatefulWidget {
|
||||||
const ExportSuccessPage({Key? key}) : super(key: key);
|
const ExportSuccessPage({Key? key}) : super(key: key);
|
||||||
@ -40,7 +38,6 @@ class _ExportSuccessPageState extends State<ExportSuccessPage> with RouteAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 导出成功
|
// 导出成功
|
||||||
|
|
||||||
Widget sendElectronicKeySucceed() {
|
Widget sendElectronicKeySucceed() {
|
||||||
return Column(
|
return Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
@ -83,19 +80,6 @@ class _ExportSuccessPageState extends State<ExportSuccessPage> with RouteAware {
|
|||||||
btnName: '立即查看'.tr,
|
btnName: '立即查看'.tr,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
OpenFile.open(state.getFilePath.value);
|
OpenFile.open(state.getFilePath.value);
|
||||||
NativeInteractionTool()
|
|
||||||
.loadNativeFileShare(shareText: state.getFilePath.value);
|
|
||||||
|
|
||||||
// openFile(state.getFilePath.value);
|
|
||||||
// previewFile();
|
|
||||||
// Get.toNamed(Routers.viewExportRecordPage,
|
|
||||||
// arguments: <String, Object>{
|
|
||||||
// 'filePath': state.getFilePath.value,
|
|
||||||
// });
|
|
||||||
// Get.toNamed(Routers.webviewShowPage, arguments: <String, Object>{
|
|
||||||
// 'url': state.getFilePath.value,
|
|
||||||
// 'title': '查看操作记录'.tr
|
|
||||||
// });
|
|
||||||
}),
|
}),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 20.h,
|
height: 20.h,
|
||||||
@ -103,27 +87,19 @@ class _ExportSuccessPageState extends State<ExportSuccessPage> with RouteAware {
|
|||||||
OutLineBtn(
|
OutLineBtn(
|
||||||
btnName: '分享'.tr,
|
btnName: '分享'.tr,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
_openModalBottomSheet();
|
NativeInteractionTool()
|
||||||
|
.loadNativeFileShare(shareText: state.getFilePath.value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Future<void> openFile(String filePath) async {
|
|
||||||
// final File file = File(filePath);
|
|
||||||
// if (await file.exists()) {
|
|
||||||
// await launchUrl(Uri.parse('file://$filePath'));
|
|
||||||
// } else {
|
|
||||||
// throw 'File not found';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
Future<void> previewFile() async {
|
Future<void> previewFile() async {
|
||||||
// 获取本地文件路径
|
// 获取本地文件路径
|
||||||
final Directory appDocDir = await getApplicationDocumentsDirectory();
|
final Directory appDocDir = await getApplicationDocumentsDirectory();
|
||||||
final String appDocPath = appDocDir.path;
|
final String appDocPath = appDocDir.path;
|
||||||
final String filePath = '$appDocPath/exported_file.xlsx';
|
final String filePath = '$appDocPath/record.xlsx';
|
||||||
|
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
final File file = File(filePath);
|
final File file = File(filePath);
|
||||||
@ -137,107 +113,4 @@ class _ExportSuccessPageState extends State<ExportSuccessPage> with RouteAware {
|
|||||||
print('File does not exist');
|
print('File does not exist');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _openModalBottomSheet() async {
|
|
||||||
showModalBottomSheet(
|
|
||||||
context: context,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadiusDirectional.circular(10)),
|
|
||||||
constraints: BoxConstraints(maxHeight: 270.h),
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
children: <Widget>[
|
|
||||||
SizedBox(
|
|
||||||
width: ScreenUtil().screenWidth,
|
|
||||||
height: 160.h,
|
|
||||||
child: ListView(
|
|
||||||
scrollDirection: Axis.horizontal, //横向滚动
|
|
||||||
children: initBottomSheetList()),
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
height: 8.h,
|
|
||||||
color: AppColors.greyBackgroundColor,
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
style: ButtonStyle(
|
|
||||||
overlayColor:
|
|
||||||
MaterialStateProperty.all<Color>(Colors.white)),
|
|
||||||
child: Text(
|
|
||||||
'取消'.tr,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.black, fontSize: ScreenUtil().setSp(24)),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Widget> initBottomSheetList() {
|
|
||||||
final List<Widget> widgetList = <Widget>[];
|
|
||||||
|
|
||||||
widgetList.add(buildCenter3('images/icon_wechat.png', '微信好友'.tr, 0));
|
|
||||||
widgetList.add(buildCenter3('images/icon_message.png', '短信'.tr, 1));
|
|
||||||
widgetList.add(buildCenter3('images/icon_email.png', '邮件'.tr, 2));
|
|
||||||
widgetList.add(buildCenter3('images/icon_more.png', '更多'.tr, 3));
|
|
||||||
|
|
||||||
return widgetList;
|
|
||||||
}
|
|
||||||
|
|
||||||
GestureDetector buildCenter3(
|
|
||||||
String imageName, String titleStr, int itemIndex) {
|
|
||||||
return GestureDetector(
|
|
||||||
child: Container(
|
|
||||||
width: 120.w,
|
|
||||||
// height: 64.h,
|
|
||||||
margin:
|
|
||||||
EdgeInsets.only(top: 20.w, bottom: 20.w, left: 10.w, right: 10.w),
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
Image.asset(
|
|
||||||
imageName,
|
|
||||||
width: 50.w,
|
|
||||||
height: 50.h,
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 16.w,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
titleStr,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: ScreenUtil().setSp(20), color: Colors.black),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onTap: () => jumpSmartDeviceRoute(itemIndex),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> jumpSmartDeviceRoute(int itemIndex) async {
|
|
||||||
Get.back();
|
|
||||||
// final String pwdShareStr = logic.getShareContentStr();
|
|
||||||
switch (itemIndex) {
|
|
||||||
case 0: //微信好友
|
|
||||||
// NativeInteractionTool().loadNativeShare(shareText: pwdShareStr);
|
|
||||||
break;
|
|
||||||
case 1: //短信
|
|
||||||
case 2: //邮件
|
|
||||||
Get.toNamed(Routers.sendEmailNotificationPage,
|
|
||||||
arguments: <String, Object?>{
|
|
||||||
'receiver': '',
|
|
||||||
'channelType': itemIndex == 1 ? 1 : 2,
|
|
||||||
'keyId': CommonDataManage().currentKeyInfo.keyId,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case 3: //更多
|
|
||||||
// NativeInteractionTool().loadNativeShare(shareText: pwdShareStr);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
import 'dart:io';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
import 'package:star_lock/app_settings/app_colors.dart';
|
import 'package:star_lock/app_settings/app_colors.dart';
|
||||||
import 'package:star_lock/app_settings/app_settings.dart';
|
|
||||||
import 'package:star_lock/main/lockDetail/doorLockLog/viewExportRecord/viewExportRecord_logic.dart';
|
import 'package:star_lock/main/lockDetail/doorLockLog/viewExportRecord/viewExportRecord_logic.dart';
|
||||||
import 'package:star_lock/main/lockDetail/doorLockLog/viewExportRecord/viewExportRecord_state.dart';
|
import 'package:star_lock/main/lockDetail/doorLockLog/viewExportRecord/viewExportRecord_state.dart';
|
||||||
import 'package:star_lock/tools/titleAppBar.dart';
|
import 'package:star_lock/tools/titleAppBar.dart';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user