|
@@ -1,6 +1,6 @@
|
|
|
import 'dart:async';
|
|
|
import 'dart:convert';
|
|
|
-
|
|
|
+import 'package:excel/excel.dart';
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
@@ -16,7 +16,7 @@ class ImportDataView extends StatelessWidget {
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return GridView.count(
|
|
|
- crossAxisCount: 7, // 每行显示的子组件数量
|
|
|
+ crossAxisCount: 6, // 每行显示的子组件数量
|
|
|
crossAxisSpacing: 4.0, // 子组件之间的水平间距
|
|
|
mainAxisSpacing: 4.0, // 子组件之间的垂直间距
|
|
|
childAspectRatio: 1.0, // 子组件的宽高比
|
|
@@ -27,13 +27,35 @@ class ImportDataView extends StatelessWidget {
|
|
|
Icons.abc,
|
|
|
size: 40,
|
|
|
),
|
|
|
- onTap: _csvImportClick,
|
|
|
+ onTap: () {
|
|
|
+ _importClick("BiochemicalValues_CQZY");
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ FunctionButton(
|
|
|
+ label: "黑台生化",
|
|
|
+ icon: Icon(
|
|
|
+ Icons.abc,
|
|
|
+ size: 40,
|
|
|
+ ),
|
|
|
+ onTap: () {
|
|
|
+ _importClick("BiochemicalValues_HT");
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ FunctionButton(
|
|
|
+ label: "黑台血常规",
|
|
|
+ icon: Icon(
|
|
|
+ Icons.abc,
|
|
|
+ size: 40,
|
|
|
+ ),
|
|
|
+ onTap: () {
|
|
|
+ _importClick("BloodRoutine_HT");
|
|
|
+ },
|
|
|
),
|
|
|
],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Future<void> _csvImportClick() async {
|
|
|
+ Future<void> _importClick(String key) async {
|
|
|
final html.FileUploadInputElement uploadInput =
|
|
|
html.FileUploadInputElement();
|
|
|
uploadInput.accept = '.xls,.xlsx,.csv'; // 设置接受的文件类型
|
|
@@ -43,19 +65,45 @@ class ImportDataView extends StatelessWidget {
|
|
|
|
|
|
html.File? file = uploadInput.files?.first;
|
|
|
String extension = file?.name.split('.').last.toLowerCase() ?? "";
|
|
|
+ Store.app.busy = true;
|
|
|
if (extension == "csv") {
|
|
|
- Store.app.busy = true;
|
|
|
try {
|
|
|
List<List<dynamic>> csvData = await readCSVFile(file!);
|
|
|
- var records = await Get.find<ICsvDataManager>().CsvDataConvert(csvData);
|
|
|
+ var records =
|
|
|
+ await Get.find<ICsvDataManager>().CsvDataConvert(csvData, key);
|
|
|
if (records.isNotEmpty) {
|
|
|
Get.to(CSVDatasView(records));
|
|
|
} else {
|
|
|
PromptBox.toast('无可上传数据');
|
|
|
}
|
|
|
} catch (e) {}
|
|
|
- Store.app.busy = false;
|
|
|
+ } else if (extension == "xlsx") {
|
|
|
+ final reader = html.FileReader();
|
|
|
+ reader.onLoadEnd.listen((e) async {
|
|
|
+ var bytes = reader.result as List<int>;
|
|
|
+ var excel = Excel.decodeBytes(bytes);
|
|
|
+
|
|
|
+ // Assuming the first sheet is what you want to read
|
|
|
+ for (var table in excel.tables.keys) {
|
|
|
+ print(table); // sheet name
|
|
|
+ print(excel.tables[table]?.maxColumns);
|
|
|
+ print(excel.tables[table]?.maxRows);
|
|
|
+ var records = await Get.find<ICsvDataManager>()
|
|
|
+ .ExcelDataConvert(excel.tables[table]!.rows, key);
|
|
|
+ if (records.isNotEmpty) {
|
|
|
+ Get.to(CSVDatasView(records));
|
|
|
+ } else {
|
|
|
+ PromptBox.toast('无可上传数据');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var content = excel.tables.keys.first;
|
|
|
+ });
|
|
|
+ reader.onError.listen((fileEvent) {
|
|
|
+ print("Some Error occured while reading the file");
|
|
|
+ });
|
|
|
+ reader.readAsArrayBuffer(file!);
|
|
|
}
|
|
|
+ Store.app.busy = false;
|
|
|
}
|
|
|
|
|
|
Future<List<List<dynamic>>> readCSVFile(html.File file) async {
|