Commit 211c6d219d377e7abd6a8e5fd537d5df85112baf

Authored by wdn127929
1 parent d4d895cb

安卓导出excel

@@ -25,7 +25,11 @@ @@ -25,7 +25,11 @@
25 25
26 android:label="周到安排商家" 26 android:label="周到安排商家"
27 tools:replace="android:label" 27 tools:replace="android:label"
28 - android:icon="@mipmap/ic_launcher"> 28 + android:icon="@mipmap/ic_launcher"
  29 + android:requestLegacyExternalStorage="true"
  30 + android:preserveLegacyExternalStorage="true"
  31 + >
  32 +
29 <activity 33 <activity
30 android:name=".MainActivity" 34 android:name=".MainActivity"
31 android:exported="true" 35 android:exported="true"
1 -<?xml version="1.0" encoding="utf-8"?> 1 +<!-- <?xml version="1.0" encoding="utf-8"?>
2 <resources> 2 <resources>
3 <external-path name="external_storage_directory" path="." /> 3 <external-path name="external_storage_directory" path="." />
4 -</resources>  
  4 +</resources> -->
  5 +
  6 +<paths>
  7 + <external-path name="external-path" path="."/>
  8 + <external-cache-path name="external-cache-path" path="."/>
  9 + <external-files-path name="external-files-path" path="."/>
  10 + <files-path name="files_path" path="."/>
  11 + <cache-path name="cache-path" path="."/>
  12 + <root-path name="root" path="."/>
  13 +</paths>
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 archiveVersion = 1; 3 archiveVersion = 1;
4 classes = { 4 classes = {
5 }; 5 };
6 - objectVersion = 50; 6 + objectVersion = 46;
7 objects = { 7 objects = {
8 8
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
@@ -561,7 +561,7 @@ @@ -561,7 +561,7 @@
561 "$(inherited)", 561 "$(inherited)",
562 "$(PROJECT_DIR)/Flutter", 562 "$(PROJECT_DIR)/Flutter",
563 ); 563 );
564 - MARKETING_VERSION = 6.0.0; 564 + MARKETING_VERSION = 5.2.0;
565 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine; 565 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
566 PRODUCT_NAME = Runner; 566 PRODUCT_NAME = Runner;
567 PROVISIONING_PROFILE_SPECIFIER = ""; 567 PROVISIONING_PROFILE_SPECIFIER = "";
@@ -697,7 +697,7 @@ @@ -697,7 +697,7 @@
697 CURRENT_PROJECT_VERSION = 519; 697 CURRENT_PROJECT_VERSION = 519;
698 DEVELOPMENT_TEAM = 8J59HM8B82; 698 DEVELOPMENT_TEAM = 8J59HM8B82;
699 ENABLE_BITCODE = NO; 699 ENABLE_BITCODE = NO;
700 - FLUTTER_BUILD_MODE = debug; 700 + FLUTTER_BUILD_MODE = release;
701 FRAMEWORK_SEARCH_PATHS = ( 701 FRAMEWORK_SEARCH_PATHS = (
702 "$(inherited)", 702 "$(inherited)",
703 "$(PROJECT_DIR)/Flutter", 703 "$(PROJECT_DIR)/Flutter",
@@ -709,7 +709,7 @@ @@ -709,7 +709,7 @@
709 "$(inherited)", 709 "$(inherited)",
710 "$(PROJECT_DIR)/Flutter", 710 "$(PROJECT_DIR)/Flutter",
711 ); 711 );
712 - MARKETING_VERSION = 6.0.0; 712 + MARKETING_VERSION = 5.2.0;
713 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine; 713 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
714 PRODUCT_NAME = Runner; 714 PRODUCT_NAME = Runner;
715 PROVISIONING_PROFILE_SPECIFIER = ""; 715 PROVISIONING_PROFILE_SPECIFIER = "";
@@ -745,7 +745,7 @@ @@ -745,7 +745,7 @@
745 "$(inherited)", 745 "$(inherited)",
746 "$(PROJECT_DIR)/Flutter", 746 "$(PROJECT_DIR)/Flutter",
747 ); 747 );
748 - MARKETING_VERSION = 6.0.0; 748 + MARKETING_VERSION = 5.2.0;
749 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine; 749 PRODUCT_BUNDLE_IDENTIFIER = com.naji.reserveLine;
750 PRODUCT_NAME = Runner; 750 PRODUCT_NAME = Runner;
751 PROVISIONING_PROFILE_SPECIFIER = ""; 751 PROVISIONING_PROFILE_SPECIFIER = "";
@@ -6,6 +6,7 @@ import 'package:common_utils/common_utils.dart'; @@ -6,6 +6,7 @@ import 'package:common_utils/common_utils.dart';
6 import 'package:device_info/device_info.dart'; 6 import 'package:device_info/device_info.dart';
7 import 'package:dio/dio.dart'; 7 import 'package:dio/dio.dart';
8 import 'package:flutter/material.dart'; 8 import 'package:flutter/material.dart';
  9 +import 'package:flutter/services.dart';
9 import 'package:flutter_picker/Picker.dart'; 10 import 'package:flutter_picker/Picker.dart';
10 import 'package:flutter_screenutil/flutter_screenutil.dart'; 11 import 'package:flutter_screenutil/flutter_screenutil.dart';
11 import 'package:one_key/models/get_export_info_model.dart'; 12 import 'package:one_key/models/get_export_info_model.dart';
@@ -28,11 +29,16 @@ import '../../../../utils/utils.dart'; @@ -28,11 +29,16 @@ import '../../../../utils/utils.dart';
28 import '../../../../widgets/h_empty_view.dart'; 29 import '../../../../widgets/h_empty_view.dart';
29 // import 'package:flutter_downloader/flutter_downloader.dart'; 30 // import 'package:flutter_downloader/flutter_downloader.dart';
30 // import 'package:android_path_provider/android_path_provider.dart'; 31 // import 'package:android_path_provider/android_path_provider.dart';
31 -import 'package:open_file/open_file.dart'; 32 +// import 'package:open_file/open_file.dart';
  33 +import 'package:open_filex/open_filex.dart';
32 import 'package:excel/excel.dart' as excelUtil; 34 import 'package:excel/excel.dart' as excelUtil;
33 35
34 import '../../../../widgets/loading.dart'; 36 import '../../../../widgets/loading.dart';
35 37
  38 +import 'package:external_path/external_path.dart';
  39 +// import 'package:open_file_plus/open_file_plus.dart';
  40 +// import 'package:flutter_filereader/flutter_filereader.dart';
  41 +
36 /** 42 /**
37 * 导出预订数据 43 * 导出预订数据
38 */ 44 */
@@ -52,17 +58,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -52,17 +58,14 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
52 58
53 List<String> data = ['到店时间', '下单时间']; 59 List<String> data = ['到店时间', '下单时间'];
54 int timeIndex; 60 int timeIndex;
55 - // ReceivePort _port = ReceivePort(); 61 +
56 String _localPath; 62 String _localPath;
57 63
58 String taskId; 64 String taskId;
59 - // DownloadTaskStatus status;  
60 int progress; 65 int progress;
61 66
62 CustomerProvider customerProvider; 67 CustomerProvider customerProvider;
63 68
64 - // List<Map<String, String>> fieldData = {};  
65 -  
66 @override 69 @override
67 void initState() { 70 void initState() {
68 super.initState(); 71 super.initState();
@@ -73,12 +76,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -73,12 +76,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
73 } 76 }
74 77
75 _getReportField() async { 78 _getReportField() async {
76 - bool success = await customerProvider.getReportField(context);  
77 - // if (success) {  
78 - // customerProvider.reportFieldModelData.forEach((element) {  
79 - // fieldData[element.code] = element.name;  
80 - // });  
81 - // } 79 + await customerProvider.getReportField(context);
  80 +
  81 + await _checkPermission();
82 } 82 }
83 83
84 Future<void> _prepareSaveDir() async { 84 Future<void> _prepareSaveDir() async {
@@ -93,23 +93,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -93,23 +93,9 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
93 String externalStorageDirPath; 93 String externalStorageDirPath;
94 94
95 if (Platform.isAndroid) { 95 if (Platform.isAndroid) {
96 - // try {  
97 - // externalStorageDirPath = await AndroidPathProvider.downloadsPath;  
98 - // } catch (err, st) {  
99 - // print('failed to get downloads path: $err, $st');  
100 -  
101 - // if()/  
102 -  
103 - // final directory = await getExternalStorageDirectory();  
104 - // externalStorageDirPath = directory?.path;  
105 -  
106 - externalStorageDirPath = '/storage/emulated/0/Download'; 96 + final directory = await getExternalStorageDirectory();
  97 + externalStorageDirPath = directory?.path;
107 } else if (Platform.isIOS) { 98 } else if (Platform.isIOS) {
108 - // externalStorageDirPath =  
109 - // (await getApplicationDocumentsDirectory()).absolute.path;  
110 -  
111 - // externalStorageDirPath = (await getTemporaryDirectory()).path;  
112 -  
113 externalStorageDirPath = (await getApplicationSupportDirectory()).path; 99 externalStorageDirPath = (await getApplicationSupportDirectory()).path;
114 100
115 externalStorageDirPath = 101 externalStorageDirPath =
@@ -124,38 +110,42 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -124,38 +110,42 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
124 } 110 }
125 111
126 if (Platform.isAndroid) { 112 if (Platform.isAndroid) {
127 - // final info = await DeviceInfoPlugin().androidInfo;  
128 - // if (info.version.sdkInt > 28) {  
129 - // return true;  
130 - // }  
131 -  
132 - final status = await Permission.manageExternalStorage.status;  
133 - if (status == PermissionStatus.granted) {  
134 - return true;  
135 - } 113 + final info = await DeviceInfoPlugin().androidInfo;
136 114
137 - if (Platform.isAndroid) {  
138 - // try {  
139 - // externalStorageDirPath = await AndroidPathProvider.downloadsPath;  
140 - // } catch (err, st) {  
141 - // print('failed to get downloads path: $err, $st'); 115 + if (info.version.sdkInt >= 33) {
  116 + final status = await Permission.photos.status;
  117 + if (status == PermissionStatus.granted) {
  118 + return true;
  119 + }
  120 +
  121 + if (status != PermissionStatus.permanentlyDenied) {
  122 +//全局提示权限使用目的
  123 + BuildContext context = App.navigatorKey.currentState.overlay.context;
  124 + dynamic object = DialogUtil.showAuthorityDestination(
  125 + context, 'h_storage', '访问照片和视频权限', '用于存储下载的预订表。');
  126 + print(object);
  127 + }
142 128
143 - // if()/  
144 - PermissionStatus permissionStatus =  
145 - await Permission.manageExternalStorage.status; 129 + final result = await Permission.photos.request();
  130 + return result == PermissionStatus.granted;
  131 + } else {
  132 + final status = await Permission.storage.status;
  133 + if (status == PermissionStatus.granted) {
  134 + return true;
  135 + }
146 136
147 - if (permissionStatus != PermissionStatus.permanentlyDenied) { 137 + if (status != PermissionStatus.permanentlyDenied) {
148 //全局提示权限使用目的 138 //全局提示权限使用目的
149 BuildContext context = App.navigatorKey.currentState.overlay.context; 139 BuildContext context = App.navigatorKey.currentState.overlay.context;
150 DialogUtil.showAuthorityDestination( 140 DialogUtil.showAuthorityDestination(
151 - context, 'h_storage', '访问所有文件权限', '用于存储下载的预订表。'); 141 + context, 'h_storage', '访问存储权限', '用于存储下载的预订表。');
152 } 142 }
153 - }  
154 143
155 - final result = await Permission.manageExternalStorage.request();  
156 - return result == PermissionStatus.granted; 144 + final result = await Permission.storage.request();
  145 + return result == PermissionStatus.granted;
  146 + }
157 } 147 }
158 - 148 + // manageExternalStorage
159 throw StateError('unknown platform'); 149 throw StateError('unknown platform');
160 } 150 }
161 151
@@ -338,25 +328,29 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -338,25 +328,29 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
338 Provider.of<UserModel>(context, listen: false).user.sellername; 328 Provider.of<UserModel>(context, listen: false).user.sellername;
339 String starttime = fromDate.replaceAll('-', ''); 329 String starttime = fromDate.replaceAll('-', '');
340 String endtime = endDate.replaceAll('-', ''); 330 String endtime = endDate.replaceAll('-', '');
341 - String fileName = "/${sellername}${starttime}至${endtime}.xlsx"; 331 + String nameS = '/${sellername}${starttime}至${endtime}_';
  332 + String timetemp =
  333 + ((DateTime.now().millisecondsSinceEpoch / 1000).floor()).toString();
  334 + String sunfix = '.xlsx';
  335 +
  336 + // String sunfix = '.xls';
  337 + // String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
  338 + String fileName = nameS + timetemp + sunfix;
  339 + if (Platform.isIOS) {
  340 + fileName = nameS + sunfix;
  341 + }
342 String filePath = _localPath + '${fileName}'; 342 String filePath = _localPath + '${fileName}';
343 - // Utils.showToast('文件已保存到${filePath}'); 343 +
344 if (fileBytes != null) { 344 if (fileBytes != null) {
345 - // File file =  
346 - File(filePath) 345 + File file = File(filePath)
347 ..createSync(recursive: true) 346 ..createSync(recursive: true)
348 ..writeAsBytesSync(fileBytes); 347 ..writeAsBytesSync(fileBytes);
349 - // try {  
350 - // // File file1 = File('/storage/emulated/0/Download${fileName}')  
351 - // // ..createSync(recursive: true)  
352 - // // ..writeAsBytesSync(fileBytes);  
353 - // // File file2 =  
354 - // // await file.copy('/storage/emulated/0/Documents${fileName}');  
355 - // File file1 = await file.copy('/storage/emulated/0/Download${fileName}');  
356 - // Utils.showToast('文件已保存到${file1.path}');  
357 - // } catch (e) {  
358 - // Utils.showToast('保存失败:${e}');  
359 - // } 348 + try {
  349 + File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
  350 + // Utils.showToast('文件已保存到${file1.path}');
  351 + } catch (e) {
  352 + // Utils.showToast('保存失败!');
  353 + }
360 354
361 Loading.hideLoading(context); 355 Loading.hideLoading(context);
362 DialogUtil.cupertinoAlertDialog(context, 356 DialogUtil.cupertinoAlertDialog(context,
@@ -369,24 +363,21 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -369,24 +363,21 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
369 progress = null; 363 progress = null;
370 setState(() {}); 364 setState(() {});
371 }, rCallback: () async { 365 }, rCallback: () async {
372 - // Navigator.pop(context);  
373 -  
374 - // print(_localPath);  
375 -  
376 - // final tasks = await FlutterDownloader.loadTasks();  
377 - // String str = '';  
378 - // tasks.forEach((element) {  
379 - // str = element.savedDir + '/' + element.filename;  
380 - // });  
381 - // print(str);  
382 -  
383 - // if (str != '') {  
384 - // print(savePath);  
385 - // progress = null;  
386 - // setState(() {});  
387 - OpenFile.open(filePath);  
388 - // _delete();  
389 - // } 366 + // final result =
  367 + // await OpenFilex.open(filePath, type: 'application/vnd.ms-excel');
  368 + final result = await OpenFilex.open(filePath,
  369 + type:
  370 + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  371 + print(result.type);
  372 + if (result.type == ResultType.noAppToOpen) {
  373 + Utils.showToast('没有应用可以打开');
  374 + } else if (result.type == ResultType.fileNotFound) {
  375 + Utils.showToast('找不到文件');
  376 + } else if (result.type == ResultType.permissionDenied) {
  377 + Utils.showToast('没有相关权限');
  378 + } else if (result.type == ResultType.permissionDenied) {
  379 + Utils.showToast('发生未知错误');
  380 + }
390 }); 381 });
391 } else { 382 } else {
392 Loading.hideLoading(context); 383 Loading.hideLoading(context);
@@ -412,13 +403,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -412,13 +403,6 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
412 // controller: controller, 403 // controller: controller,
413 child: Column( 404 child: Column(
414 children: [ 405 children: [
415 - // (status == DownloadTaskStatus.running ||  
416 - // status == DownloadTaskStatus.paused)  
417 - // ? LinearProgressIndicator(  
418 - // value: progress / 100,  
419 - // )  
420 - // : VEmptyView(10),  
421 -  
422 progress != null && progress != 100 406 progress != null && progress != 100
423 ? LinearProgressIndicator( 407 ? LinearProgressIndicator(
424 value: progress / 100, 408 value: progress / 100,
@@ -604,7 +588,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { @@ -604,7 +588,12 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> {
604 await customerProvider.getExportInfo(context, pramas); 588 await customerProvider.getExportInfo(context, pramas);
605 if (success) { 589 if (success) {
606 //成功 590 //成功
607 - _download(); 591 + if (customerProvider.exportInfoSunModel.list.length == 0) {
  592 + Utils.showToast('当前时间段内没有预订数据!');
  593 + return;
  594 + } else {
  595 + _download();
  596 + }
608 } 597 }
609 } else { 598 } else {
610 // String title = Platform.isAndroid ? '存储' : '相册'; 599 // String title = Platform.isAndroid ? '存储' : '相册';
@@ -812,7 +812,7 @@ class CustomerProvider extends ChangeNotifier { @@ -812,7 +812,7 @@ class CustomerProvider extends ChangeNotifier {
812 getExportInfo(BuildContext context, Map<String, String> params) async { 812 getExportInfo(BuildContext context, Map<String, String> params) async {
813 BaseResp<dynamic> baseResp = await DioUtil() 813 BaseResp<dynamic> baseResp = await DioUtil()
814 .request<dynamic>(context, Method.get, HttpUrl.get_export_info, 814 .request<dynamic>(context, Method.get, HttpUrl.get_export_info,
815 - data: params, showLoading: false) 815 + data: params, showLoading: true)
816 .catchError((error) { 816 .catchError((error) {
817 print(error.toString()); 817 print(error.toString());
818 if (error is MyError) { 818 if (error is MyError) {
@@ -233,7 +233,7 @@ class DialogUtil { @@ -233,7 +233,7 @@ class DialogUtil {
233 233
234 static showAuthorityDestination( 234 static showAuthorityDestination(
235 BuildContext context, String name, String title, String subTitle) async { 235 BuildContext context, String name, String title, String subTitle) async {
236 - Timer _timer = Timer(const Duration(seconds: 5), () { 236 + Timer _timer = Timer(const Duration(seconds: 2), () {
237 // if(!TickerMode.of(context)){ 237 // if(!TickerMode.of(context)){
238 Navigator.of(context).pop(true); 238 Navigator.of(context).pop(true);
239 // } 239 // }
@@ -456,6 +456,13 @@ packages: @@ -456,6 +456,13 @@ packages:
456 url: "https://pub.flutter-io.cn" 456 url: "https://pub.flutter-io.cn"
457 source: hosted 457 source: hosted
458 version: "9.1.1" 458 version: "9.1.1"
  459 + external_path:
  460 + dependency: "direct main"
  461 + description:
  462 + name: external_path
  463 + url: "https://pub.flutter-io.cn"
  464 + source: hosted
  465 + version: "1.0.3"
459 fake_async: 466 fake_async:
460 dependency: transitive 467 dependency: transitive
461 description: 468 description:
@@ -566,6 +573,13 @@ packages: @@ -566,6 +573,13 @@ packages:
566 url: "https://pub.flutter-io.cn" 573 url: "https://pub.flutter-io.cn"
567 source: hosted 574 source: hosted
568 version: "0.0.7" 575 version: "0.0.7"
  576 + flutter_filereader:
  577 + dependency: "direct main"
  578 + description:
  579 + name: flutter_filereader
  580 + url: "https://pub.flutter-io.cn"
  581 + source: hosted
  582 + version: "3.0.0"
569 flutter_image_compress: 583 flutter_image_compress:
570 dependency: "direct main" 584 dependency: "direct main"
571 description: 585 description:
@@ -917,13 +931,13 @@ packages: @@ -917,13 +931,13 @@ packages:
917 url: "https://pub.flutter-io.cn" 931 url: "https://pub.flutter-io.cn"
918 source: hosted 932 source: hosted
919 version: "1.0.2" 933 version: "1.0.2"
920 - open_file: 934 + open_filex:
921 dependency: "direct main" 935 dependency: "direct main"
922 description: 936 description:
923 - name: open_file 937 + name: open_filex
924 url: "https://pub.flutter-io.cn" 938 url: "https://pub.flutter-io.cn"
925 source: hosted 939 source: hosted
926 - version: "3.3.2" 940 + version: "4.3.4"
927 package_config: 941 package_config:
928 dependency: transitive 942 dependency: transitive
929 description: 943 description:
@@ -60,6 +60,7 @@ dependencies: @@ -60,6 +60,7 @@ dependencies:
60 # path_provider: ^1.6.5 60 # path_provider: ^1.6.5
61 # path_provider: ^2.0.10 61 # path_provider: ^2.0.10
62 path_provider: ^2.1.0 62 path_provider: ^2.1.0
  63 + external_path: ^1.0.3
63 ## 官方image组件扩展,支持多种图片效果展示 64 ## 官方image组件扩展,支持多种图片效果展示
64 # extended_image: ^1.1.1 65 # extended_image: ^1.1.1
65 # 任意位置访问navigator 66 # 任意位置访问navigator
@@ -187,7 +188,11 @@ dependencies: @@ -187,7 +188,11 @@ dependencies:
187 flutter_downloader: ^1.10.5 188 flutter_downloader: ^1.10.5
188 android_path_provider: ^0.3.0 189 android_path_provider: ^0.3.0
189 # open_file: ^3.2.1 190 # open_file: ^3.2.1
190 - open_file: ^3.3.2 191 + # open_file: ^3.3.2
  192 + open_filex: ^4.3.4
  193 + # open_file_plus: ^3.3.0
  194 + flutter_filereader: ^3.0.0
  195 +
191 196
192 webview_flutter: 197 webview_flutter:
193 path: library/webview_flutter-2.0.13-copy_inappwebview_select_file_20210930 198 path: library/webview_flutter-2.0.13-copy_inappwebview_select_file_20210930