From 5934d25c5ef42480c530c30efcd10c1ebabfc062 Mon Sep 17 00:00:00 2001 From: fwq <418233640@qq.com> Date: Fri, 18 Oct 2024 09:46:17 +0800 Subject: [PATCH] =?UTF-8?q?1.=E9=BB=98=E8=AE=A4=E5=85=81=E8=AE=B8=E5=80=BC?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=202.=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=90=8D?= =?UTF-8?q?=E6=9C=AA=E5=A1=AB=E5=86=99=E7=9A=84=E6=A0=A1=E9=AA=8C=203.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.js | 51 +++++++++++-- index.html | 207 ++++++++++++++++++++++++++--------------------------- 2 files changed, 148 insertions(+), 110 deletions(-) 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 @@ - - -
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:
+
+