|
...
|
...
|
@@ -100,13 +100,17 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
|
|
|
|
// if()/
|
|
|
|
|
|
|
|
final directory = await getExternalStorageDirectory();
|
|
|
|
externalStorageDirPath = directory?.path;
|
|
|
|
// final directory = await getExternalStorageDirectory();
|
|
|
|
// externalStorageDirPath = directory?.path;
|
|
|
|
|
|
|
|
externalStorageDirPath = '/storage/emulated/0/Download';
|
|
|
|
} else if (Platform.isIOS) {
|
|
|
|
// externalStorageDirPath =
|
|
|
|
// (await getApplicationDocumentsDirectory()).absolute.path;
|
|
|
|
|
|
|
|
externalStorageDirPath = (await getTemporaryDirectory()).path;
|
|
|
|
// externalStorageDirPath = (await getTemporaryDirectory()).path;
|
|
|
|
|
|
|
|
externalStorageDirPath = (await getApplicationSupportDirectory()).path;
|
|
|
|
|
|
|
|
externalStorageDirPath =
|
|
|
|
externalStorageDirPath.replaceFirst("Library/Caches", "Documents");
|
|
...
|
...
|
@@ -125,7 +129,7 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
final status = await Permission.storage.status;
|
|
|
|
final status = await Permission.manageExternalStorage.status;
|
|
|
|
if (status == PermissionStatus.granted) {
|
|
|
|
return true;
|
|
|
|
}
|
|
...
|
...
|
@@ -137,17 +141,18 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// print('failed to get downloads path: $err, $st');
|
|
|
|
|
|
|
|
// if()/
|
|
|
|
PermissionStatus permissionStatus = await Permission.storage.status;
|
|
|
|
PermissionStatus permissionStatus =
|
|
|
|
await Permission.manageExternalStorage.status;
|
|
|
|
|
|
|
|
if (permissionStatus != PermissionStatus.permanentlyDenied) {
|
|
|
|
//全局提示权限使用目的
|
|
|
|
BuildContext context = App.navigatorKey.currentState.overlay.context;
|
|
|
|
DialogUtil.showAuthorityDestination(
|
|
|
|
context, 'h_storage', '存储权限使用说明', '用于存储下载的预订表。');
|
|
|
|
context, 'h_storage', '访问所有文件权限', '用于存储下载的预订表。');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final result = await Permission.storage.request();
|
|
|
|
final result = await Permission.manageExternalStorage.request();
|
|
|
|
return result == PermissionStatus.granted;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -334,16 +339,31 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
String starttime = fromDate.replaceAll('-', '');
|
|
|
|
String endtime = endDate.replaceAll('-', '');
|
|
|
|
String fileName = "/${sellername}${starttime}至${endtime}.xlsx";
|
|
|
|
String filePath = _localPath + fileName;
|
|
|
|
String filePath = _localPath + '${fileName}';
|
|
|
|
// Utils.showToast('文件已保存到${filePath}');
|
|
|
|
if (fileBytes != null) {
|
|
|
|
File file = File(filePath)
|
|
|
|
// File file =
|
|
|
|
File(filePath)
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..writeAsBytesSync(fileBytes);
|
|
|
|
file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
// try {
|
|
|
|
// // File file1 = File('/storage/emulated/0/Download${fileName}')
|
|
|
|
// // ..createSync(recursive: true)
|
|
|
|
// // ..writeAsBytesSync(fileBytes);
|
|
|
|
// // File file2 =
|
|
|
|
// // await file.copy('/storage/emulated/0/Documents${fileName}');
|
|
|
|
// File file1 = await file.copy('/storage/emulated/0/Download${fileName}');
|
|
|
|
// Utils.showToast('文件已保存到${file1.path}');
|
|
|
|
// } catch (e) {
|
|
|
|
// Utils.showToast('保存失败:${e}');
|
|
|
|
// }
|
|
|
|
|
|
|
|
Loading.hideLoading(context);
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
title: '提示',
|
|
|
|
content: '文件下载完成,是否打开?',
|
|
|
|
content: Platform.isAndroid
|
|
|
|
? '文件已保存到 /sdcard/Download${fileName}'
|
|
|
|
: '文件下载完成,是否打开?',
|
|
|
|
lTitle: '取消',
|
|
|
|
rTitle: '打开', lCallback: () {
|
|
|
|
progress = null;
|
|
...
|
...
|
@@ -522,82 +542,81 @@ class _ExportBookDataPageState extends State<ExportBookDataPage> { |
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (timeType == '点击选择') {
|
|
|
|
Utils.showToast('请选择时间类型');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fromDate == '点击选择') {
|
|
|
|
Utils.showToast('请选择开始日期');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (endDate == '点击选择') {
|
|
|
|
Utils.showToast('请选择结束日期');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DateUtil.getDateTime(endDate)
|
|
|
|
.compareTo(DateUtil.getDateTime(fromDate)) <
|
|
|
|
0) {
|
|
|
|
Utils.showToast('结束日期不能早于开始日期!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
bool _permissionReady = await _checkPermission();
|
|
|
|
if (_permissionReady) {
|
|
|
|
await _prepareSaveDir();
|
|
|
|
if (timeType == '点击选择') {
|
|
|
|
Utils.showToast('请选择时间类型');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fromDate == '点击选择') {
|
|
|
|
Utils.showToast('请选择开始日期');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (endDate == '点击选择') {
|
|
|
|
Utils.showToast('请选择结束日期');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (DateUtil.getDateTime(endDate)
|
|
|
|
.compareTo(DateUtil.getDateTime(fromDate)) <
|
|
|
|
0) {
|
|
|
|
Utils.showToast('结束日期不能早于开始日期!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
bool temp = customerProvider.reportFieldModelData
|
|
|
|
.any((element) => element.select);
|
|
|
|
if (!temp) {
|
|
|
|
Utils.showToast('请选择导出字段');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool temp = customerProvider.reportFieldModelData
|
|
|
|
.any((element) => element.select);
|
|
|
|
if (!temp) {
|
|
|
|
Utils.showToast('请选择导出字段');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String from = fromDate + ' 00:00:00';
|
|
|
|
String end = endDate + ' 23:59:59';
|
|
|
|
String stime = fromDate == '点击设置开始日期'
|
|
|
|
? ""
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(from) / 1000).floor()}';
|
|
|
|
String etime = endDate == '点击设置结束日期'
|
|
|
|
? ''
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(end) / 1000).floor()}';
|
|
|
|
|
|
|
|
String fields = '';
|
|
|
|
customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
if (element.select) {
|
|
|
|
fields += element.code + ',';
|
|
|
|
String from = fromDate + ' 00:00:00';
|
|
|
|
String end = endDate + ' 23:59:59';
|
|
|
|
String stime = fromDate == '点击设置开始日期'
|
|
|
|
? ""
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(from) / 1000).floor()}';
|
|
|
|
String etime = endDate == '点击设置结束日期'
|
|
|
|
? ''
|
|
|
|
: '${(DateUtil.getDateMsByTimeStr(end) / 1000).floor()}';
|
|
|
|
|
|
|
|
String fields = '';
|
|
|
|
customerProvider.reportFieldModelData.forEach((element) {
|
|
|
|
if (element.select) {
|
|
|
|
fields += element.code + ',';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (fields.endsWith(',')) {
|
|
|
|
fields = fields.substring(0, fields.length - 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (fields.endsWith(',')) {
|
|
|
|
fields = fields.substring(0, fields.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, String> pramas = {
|
|
|
|
'sid': Provider.of<UserModel>(context, listen: false)
|
|
|
|
.user
|
|
|
|
.sellerid,
|
|
|
|
'time': timeType == '到店时间' ? 'ddate' : 'cdate',
|
|
|
|
'rdate': stime,
|
|
|
|
'edate': etime,
|
|
|
|
'fields': fields
|
|
|
|
};
|
|
|
|
bool success =
|
|
|
|
await customerProvider.getExportInfo(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
//成功
|
|
|
|
|
|
|
|
bool _permissionReady = await _checkPermission();
|
|
|
|
if (_permissionReady) {
|
|
|
|
await _prepareSaveDir();
|
|
|
|
Map<String, String> pramas = {
|
|
|
|
'sid': Provider.of<UserModel>(context, listen: false)
|
|
|
|
.user
|
|
|
|
.sellerid,
|
|
|
|
'time': timeType == '到店时间' ? 'ddate' : 'cdate',
|
|
|
|
'rdate': stime,
|
|
|
|
'edate': etime,
|
|
|
|
'fields': fields
|
|
|
|
};
|
|
|
|
bool success =
|
|
|
|
await customerProvider.getExportInfo(context, pramas);
|
|
|
|
if (success) {
|
|
|
|
//成功
|
|
|
|
_download();
|
|
|
|
} else {
|
|
|
|
String title = Platform.isAndroid ? '存储' : '相册';
|
|
|
|
|
|
|
|
//用户选择不在弹出权限提示框
|
|
|
|
print('never');
|
|
|
|
// Navigator.pop(context);
|
|
|
|
DialogUtil.openAlertDialog(context, '未获得${title}权限',
|
|
|
|
"请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
|
|
|
|
openSetting();
|
|
|
|
Navigator.pop(context, '');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// String title = Platform.isAndroid ? '存储' : '相册';
|
|
|
|
|
|
|
|
// //用户选择不在弹出权限提示框
|
|
|
|
// print('never');
|
|
|
|
// // Navigator.pop(context);
|
|
|
|
// DialogUtil.openAlertDialog(context, '未获得${title}权限',
|
|
|
|
// "请在手机的权限管理里,将${title}权限开启", '去设置', 340.0, onTap: () {
|
|
|
|
// openSetting();
|
|
|
|
// Navigator.pop(context, '');
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
...
|
...
|
|