diff --git a/code.js b/code.js index 4ce7af6..930dd2b 100644 --- a/code.js +++ b/code.js @@ -84,10 +84,10 @@ $(function () { //snake to camel const snakeToCamel = (str) => str.replace( - /([-_][a-zA-Z])/g, - (group) => group.toUpperCase() - .replace('-', '') - .replace('_', '') + /([-_][a-zA-Z])/g, + (group) => group.toUpperCase() + .replace('-', '') + .replace('_', '') ); //去除重复元素 @@ -459,6 +459,9 @@ $(function () { checkBoxBinding('faultToleranceCheckBox', false); checkBoxBinding('forceStringCheckBox', false); checkBoxBinding('origJsonCheckBox', false); + // 默认允许为空 + $('#nullSafeCheckBox').prop('checked', true); + $('#usingJsonKeyCheckBox').on('change', function () { $('#jsonKeyPrivateCheckBox').prop('disabled', !(this.checked)); @@ -476,7 +479,45 @@ $(function () { } $('#copyFileBtn').click(function () { - copyToClipboard(resultDartCode); + let fileName = $('#fileNameTextField').val(); + if(fileName === undefined || fileName === ''){ + alert('Please enter the class name'); + }else{ + copyToClipboard(resultDartCode); + } + }); + + + function downloadFile(filename, text) { + // 创建一个Blob实例,类型为纯文本 + var blob = new Blob([text], { type: 'text/plain' }); + + // 创建一个指向Blob的URL + var url = URL.createObjectURL(blob); + + // 创建一个a标签 + var a = document.createElement('a'); + + // 设置a标签属性 + a.href = url; + a.download = filename; + + // 模拟a标签点击,触发下载 + document.body.appendChild(a); + a.click(); + + // 清理临时DOM和对象URL + document.body.removeChild(a); + URL.revokeObjectURL(url); + } + + $('#downloadFileBtn').click(function () { + let fileName = $('#fileNameTextField').val(); + if(fileName === undefined || fileName === ''){ + alert('Please enter the class name'); + }else{ + downloadFile(fileName, resultDartCode); + } }); })(); diff --git a/index.html b/index.html index 43b031d..2e23172 100644 --- a/index.html +++ b/index.html @@ -7,125 +7,122 @@ - - - Json To Dart Model -
-
- -

Json To Dart Model Code Generator

- view source -
-
- +
+
+ +

Json To Dart Model Code Generator

+ view source +
+
+ -
-
- -
- -
- -
- - -
+
+
+ +
+ +
+ +
+ + +
+
+
+
+ +
+
+

JsonKey:

+
+
+

Json key string

+

  |  

+

Private

-
- -
-
-

JsonKey:

-
-
-

Json key string

-

  |  

-

Private

-
-
-
-
-

Camel Case:

-
-
-

Convert snake case to camel case

-
-
-
-
-

Null safe:

-
-
-

Enable null safe

-
-
-
-
-

Fault tolerance:

-
-
-

Fault tolerance for JSON with mismatched data types

-
-
-
-
-

Force String Type:

-
-
-

Convert all props to String type (Except bool)

-
-
-
-
-

Store Original Json:

-
-
-

Enable store original Json

-
-
-
-
-

Root Class Name:

-
-
- -
-
-
-
-

File Name:

-
-
- -
+
+
+

Camel Case:

+
+
+

Convert snake case to camel case

-
-
- -
- -
+
+
+

Null safe:

+
+
+

Enable null safe

+
-
- +
+
+

Fault tolerance:

+
+
+

Fault tolerance for JSON with mismatched data types

+
+
+
+
+

Force String Type:

+
+
+

Convert all props to String type (Except bool)

+
+
+
+
+

Store Original Json:

+
+
+

Enable store original Json

+
+
+
+
+

Root Class Name:

+
+
+ +
+
+
+
+

File Name:

+
+
+ +
+
+ +
+ +
+
+
+ + +
+
- - - - - -
- -
+
+ + + + + + +