@@ -21,6 +21,15 @@ extension CompressLevelExtension on CompressLevel {
2121 };
2222 return labels[this ] ?? "unknown" ;
2323 }
24+
25+ int value () {
26+ final Map <CompressLevel , int > values = {
27+ CompressLevel .normal: - 1 ,
28+ CompressLevel .best: 9 ,
29+ CompressLevel .fast: 1 ,
30+ };
31+ return values[this ] ?? - 1 ;
32+ }
2433}
2534
2635class BaseForm extends StatefulWidget {
@@ -110,6 +119,7 @@ class _BaseFormState extends State<BaseForm> {
110119 ),
111120 ListTile (
112121 title: Text ('文件加密' .tr ()),
122+ subtitle: Text ("文件加密创建后不可更改加密配置" .tr ()),
113123 trailing: Switch (
114124 value: _option["encrypt" ] ?? false ,
115125 onChanged: (result) {
@@ -142,6 +152,21 @@ class _BaseFormState extends State<BaseForm> {
142152 },
143153 ),
144154 if (_option["encrypt" ] ?? false )
155+ CustomFormField (
156+ type: CustomFormFieldType .password,
157+ label: "文件密码加密" .tr (),
158+ value: _encryptOption["password_salt" ],
159+ subtitle: Text ("类似二次密码" .tr ()),
160+ onTap: (result) {
161+ setState (() {
162+ _encryptOption["password_salt" ] = result;
163+ _option["encrypt_option" ] = _encryptOption;
164+ });
165+
166+ widget.form.option = jsonEncode (_option);
167+ },
168+ ),
169+ if (_option["encrypt" ] ?? false )
145170 CustomFormField (
146171 label: "文件后缀" .tr (),
147172 value: _encryptOption["suffix" ],
@@ -186,6 +211,7 @@ class _BaseFormState extends State<BaseForm> {
186211 ),
187212 ListTile (
188213 title: Text ('文件压缩' .tr ()),
214+ subtitle: Text ("文件压缩创建后不可更改压缩配置" .tr ()),
189215 trailing: Switch (
190216 value: _option["compress" ] ?? false ,
191217 onChanged: (result) {
@@ -205,22 +231,16 @@ class _BaseFormState extends State<BaseForm> {
205231 if (_option["compress" ] ?? false )
206232 CustomFormField (
207233 label: "压缩水平" .tr (),
208- value: _compressOption[" level" ] ,
234+ value: _compressValue ( _compressOption[' level' ]) ,
209235 type: CustomFormFieldType .option,
210236 options: CompressLevel .values.map ((v) {
211237 return CustomFormFieldOption (label: v.label (), value: v.name);
212238 }).toList (),
213239 isRequired: true ,
214240 onTap: (result) {
215241 setState (() {
216- switch (result) {
217- case "fast" :
218- _compressOption["level" ] = 1 ;
219- case "best" :
220- _compressOption["level" ] = 9 ;
221- default :
222- _compressOption["level" ] = - 1 ;
223- }
242+ _compressOption["level" ] =
243+ CompressLevel .values.byName (result).value ();
224244 _option["compress_option" ] = _compressOption;
225245 });
226246
@@ -231,4 +251,17 @@ class _BaseFormState extends State<BaseForm> {
231251 ),
232252 );
233253 }
254+
255+ String ? _compressValue (int ? value) {
256+ if (value == null ) {
257+ return null ;
258+ }
259+ if (value == 1 ) {
260+ return CompressLevel .fast.name;
261+ }
262+ if (value == 9 ) {
263+ return CompressLevel .best.name;
264+ }
265+ return CompressLevel .normal.name;
266+ }
234267}
0 commit comments