From c5fcacd08996ca61f8f5aa0de2768d92853d9230 Mon Sep 17 00:00:00 2001 From: cjl_macbook Date: Tue, 7 Aug 2018 20:54:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=B8=8B=E8=BD=BD=EF=BC=88=E4=BF=9D=E5=AD=98=EF=BC=89?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/generator.dart | 1 - lib/json_generator.dart | 21 +++++++++++++++- web/index.html | 55 ++++++++++++++++++++++------------------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/lib/generator.dart b/lib/generator.dart index 9c1ad55..9408c98 100644 --- a/lib/generator.dart +++ b/lib/generator.dart @@ -26,7 +26,6 @@ class Generator { void refreshTemplate(DefaultTemplate template) { var fieldList = template.fieldList; - bool needRefresh = false; fieldList.forEach((filed) { if (filed is MapField) { // filed.typeString diff --git a/lib/json_generator.dart b/lib/json_generator.dart index 7b771c3..9bf528c 100644 --- a/lib/json_generator.dart +++ b/lib/json_generator.dart @@ -9,6 +9,8 @@ bool useJsonKey = true; bool isCamelCase = true; +var downloadFileName = ""; + const defaultValue = """{ "body": "", "data": [1], @@ -45,6 +47,7 @@ void main() { InputElement eJsonKey = querySelector("#use_json_key"); InputElement eCamelCase = querySelector("#camelCase"); + TextAreaElement result = querySelector("#result"); void onJsonKeyChange() { useJsonKey = eJsonKey.checked; @@ -78,12 +81,27 @@ void main() { refreshData(); querySelector("#copy").onClick.listen((event) { - TextAreaElement result = querySelector("#result"); result.focus(); result.setSelectionRange(0, result.textLength); document.execCommand("copy", null, ""); result.blur(); }); + + ButtonElement saveButton = querySelector("#save"); + saveButton.onClick.listen((event) async { + Blob blob = Blob([result.value]); + // FileSystem _filesystem = + // await window.requestFileSystem(1024 * 1024, persistent: false); + // FileEntry fileEntry = await _filesystem.root.createFile('dart_test.csv'); + // FileWriter fw = await fileEntry.createWriter(); + // fw.write(blob); + // File file = await fileEntry.file(); + AnchorElement saveLink = document.createElementNS("http://www.w3.org/1999/xhtml", "a"); + saveLink.href = Url.createObjectUrlFromBlob(blob); + // saveLink.type = "download"; + saveLink.download = downloadFileName; + saveLink.click(); + }); } void refreshData() { @@ -107,6 +125,7 @@ void refreshData() { var generator = Generator(string, entityClassName); var dartCode = generator.makeDartCode(); var dartFileName = ("${generator.fileName}.dart"); + downloadFileName = dartFileName; querySelector("#file_name").text = "应该使用的文件名为: $dartFileName"; result.value = dartCode; diff --git a/web/index.html b/web/index.html index 9c471d2..3edc823 100644 --- a/web/index.html +++ b/web/index.html @@ -3,10 +3,10 @@ - - - - + + + + hello_world @@ -15,30 +15,35 @@ -
-
-
- 将json粘贴至左边 +
+
+
+ 将json粘贴至左边 +
+ +
+ +
- -
- +
+
+
+ 类名称 + + + jsonKey annotation + + use camelCase +
+
+ +
+ + +
-
-
-
-
- 类名称 - - jsonKey annotation - use camelCase -
-
- -
-
-
+
\ No newline at end of file From 9c4dca58a91d2fa5b14e7ddd3a1bdc2095eea7ce Mon Sep 17 00:00:00 2001 From: cjl_macbook Date: Tue, 7 Aug 2018 21:00:43 +0800 Subject: [PATCH 2/3] readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21a0246..9bc0ced 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,14 @@ 一个网页版本的json转dart库 -不同于https://github.com/debuggerx01/JSONFormat4Flutter的是 这个是为了json_serializable创建的 +不同于https://github.com/debuggerx01/JSONFormat4Flutter 的是:这个是为了json_serializable创建的 页面较简陋 +json_serializable 可以参考flutter官网json部分 [flutter](https://flutter.io/json) + +项目的展示地址: https://caijinglong.github.io/json2dart/ + ## todo 1. 格式化代码:完成 2. 编写格式化相关的逻辑 From ad1aa77c5fb1efa6d40e4a1ff7261d6b24184fdc Mon Sep 17 00:00:00 2001 From: cjl_macbook Date: Tue, 7 Aug 2018 21:12:15 +0800 Subject: [PATCH 3/3] modify the pubspec update readme --- README.md | 17 ++++++++++++----- pubspec.yaml | 4 ++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9bc0ced..18e2db8 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,24 @@ 一个网页版本的json转dart库 -不同于https://github.com/debuggerx01/JSONFormat4Flutter 的是:这个是为了json_serializable创建的 -页面较简陋 +## 说明 +不同于https://github.com/debuggerx01/JSONFormat4Flutter 的是:这个是为了json_serializable创建的 +页面较简陋,功能完善😊 json_serializable 可以参考flutter官网json部分 [flutter](https://flutter.io/json) 项目的展示地址: https://caijinglong.github.io/json2dart/ -## todo -1. 格式化代码:完成 -2. 编写格式化相关的逻辑 +项目使用dart web开发 +## 说明 +主体功能完结,有需要修改的地方欢迎留言 + + +``` +dart --version +Dart VM version: 2.0.0-dev.69.5 (Tue Jul 31 15:05:14 2018 +0200) on "macos_x64" +``` ## license diff --git a/pubspec.yaml b/pubspec.yaml index d7d8a0e..da0befb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,11 @@ environment: #dependencies: # path: ^1.4.1 +dependencies: + # Your other regular dependencies here + json_annotation: ^0.2.3 dev_dependencies: build_runner: ^0.9.0 build_web_compilers: ^0.4.0 + json_serializable: ^0.5.4 \ No newline at end of file