@@ -140,7 +140,7 @@ const ChallengeContributePage: React.FC = () => {
140
140
'difficulty-level' : values . difficultyLevel ,
141
141
'description-markdown' : values . description || values . descriptionMarkdown ,
142
142
'base64-url' : values . base64Url ,
143
- 'is-expired' : values . isExpired ,
143
+ 'is-expired' : values . isExpired === undefined ? false : values . isExpired ,
144
144
'tags' : values . tags || [ ] ,
145
145
'solutions' : ( values . solutions || [ ] ) ?. filter ( s => s . title && s . url ) . map ( s => ( {
146
146
title : s . title ,
@@ -170,12 +170,12 @@ const ChallengeContributePage: React.FC = () => {
170
170
'name' : values . name ,
171
171
'name_en' : values . nameEn ,
172
172
'difficulty-level' : values . difficultyLevel ,
173
- 'description-markdown' : values . description || values . descriptionMarkdown ,
174
- 'description-markdown_en' : values . descriptionEn || values . descriptionMarkdownEn ,
173
+ 'description-markdown' : values . description || values . descriptionMarkdown || '' ,
174
+ 'description-markdown_en' : values . descriptionEn || values . descriptionMarkdownEn || '' ,
175
175
'base64-url' : values . base64Url ,
176
- 'is-expired' : values . isExpired ,
176
+ 'is-expired' : values . isExpired === undefined ? false : values . isExpired ,
177
177
'tags' : values . tags || [ ] ,
178
- 'solutions' : ( values . solutions || [ ] ) ?. filter ( s => s . title && s . url ) . map ( s => ( {
178
+ 'solutions' : ( values . solutions || [ ] ) ?. filter ( ( s : any ) => s . title && s . url ) . map ( ( s : any ) => ( {
179
179
title : s . title ,
180
180
url : s . url ,
181
181
...( s . source ? { source : s . source } : { } ) ,
@@ -187,7 +187,7 @@ const ChallengeContributePage: React.FC = () => {
187
187
const lines = values . rawYaml . split ( '\n' ) ;
188
188
189
189
// 新的方法:创建行类型映射,标记每行是什么类型
190
- const lineTypes = lines . map ( line => {
190
+ const lineTypes = lines . map ( ( line : string ) => {
191
191
const trimmedLine = line . trim ( ) ;
192
192
if ( trimmedLine === '' ) return 'empty' ;
193
193
if ( trimmedLine . startsWith ( '#' ) ) return 'comment' ;
@@ -228,22 +228,22 @@ const ChallengeContributePage: React.FC = () => {
228
228
if ( ! fieldRanges [ currentField ] ) {
229
229
fieldRanges [ currentField ] = { start : - 1 , end : - 1 , valueStart : - 1 , valueEnd : - 1 } ;
230
230
}
231
- fieldRanges [ currentField ] . end = i - 1 ;
231
+ fieldRanges [ currentField as string ] . end = i - 1 ;
232
232
}
233
233
234
234
// 记录当前字段的开始位置
235
235
currentField = fieldName ;
236
236
if ( ! fieldRanges [ currentField ] ) {
237
237
fieldRanges [ currentField ] = { start : i , end : - 1 , valueStart : - 1 , valueEnd : - 1 } ;
238
238
} else {
239
- fieldRanges [ currentField ] . start = i ;
239
+ fieldRanges [ currentField as string ] . start = i ;
240
240
}
241
241
242
242
// 找出值的开始位置
243
243
const valueMatch = line . match ( / ^ ( \s * [ a - z A - Z 0 - 9 _ - ] + : ) ( \s * ) ( .* ) / ) ;
244
244
if ( valueMatch && valueMatch [ 3 ] ) {
245
- fieldRanges [ currentField ] . valueStart = valueMatch [ 1 ] . length + valueMatch [ 2 ] . length ;
246
- fieldRanges [ currentField ] . valueEnd = line . length ;
245
+ fieldRanges [ currentField as string ] . valueStart = valueMatch [ 1 ] . length + valueMatch [ 2 ] . length ;
246
+ fieldRanges [ currentField as string ] . valueEnd = line . length ;
247
247
}
248
248
249
249
// 处理tags和solutions字段
@@ -272,7 +272,7 @@ const ChallengeContributePage: React.FC = () => {
272
272
273
273
// 设置最后一个字段的结束位置
274
274
if ( currentField && fieldRanges [ currentField ] ) {
275
- fieldRanges [ currentField ] . end = lines . length - 1 ;
275
+ fieldRanges [ currentField as string ] . end = lines . length - 1 ;
276
276
}
277
277
278
278
console . log ( '字段范围:' , fieldRanges ) ;
@@ -288,6 +288,12 @@ const ChallengeContributePage: React.FC = () => {
288
288
continue ; // 这些复杂字段单独处理
289
289
}
290
290
291
+ // 特殊处理is-expired字段,确保它总是有值
292
+ if ( fieldName === 'is-expired' && ( value === undefined || value === null ) ) {
293
+ // 如果is-expired未定义,默认设为false
294
+ fieldValueMap [ 'is-expired' ] = false ;
295
+ }
296
+
291
297
if ( fieldRanges [ fieldName ] && fieldRanges [ fieldName ] . valueStart >= 0 ) {
292
298
const lineIndex = fieldRanges [ fieldName ] . start ;
293
299
const line = lines [ lineIndex ] ;
@@ -303,9 +309,10 @@ const ChallengeContributePage: React.FC = () => {
303
309
if ( fieldValueMap [ 'description-markdown' ] && fieldRanges [ 'description-markdown' ] ) {
304
310
const fieldRange = fieldRanges [ 'description-markdown' ] ;
305
311
const startLine = fieldRange . start ;
306
- const indent = fieldIndents [ 'description-markdown' ] ;
312
+ const indent = fieldIndents [ 'description-markdown' ] || '' ;
307
313
308
- const descriptionValue = fieldValueMap [ 'description-markdown' ] ;
314
+ // 获取最新的描述内容(确保使用最新表单值)
315
+ const descriptionValue = form . getFieldValue ( 'description' ) || form . getFieldValue ( 'descriptionMarkdown' ) || '' ;
309
316
310
317
// 检查原始格式是否使用竖线(|)
311
318
if ( lines [ startLine ] . includes ( '|' ) ) {
@@ -576,7 +583,7 @@ const ChallengeContributePage: React.FC = () => {
576
583
// 处理base64Url字段,确保正确映射
577
584
base64Url : challengeData [ 'base64-url' ] || '' ,
578
585
// 处理过期标志
579
- isExpired : challengeData [ 'is-expired' ] === true ,
586
+ isExpired : challengeData [ 'is-expired' ] === true || false ,
580
587
tags : challengeData . tags || [ ] ,
581
588
solutions : ( challengeData . solutions || [ ] ) . map ( ( solution : any ) => ( {
582
589
title : solution . title || '' ,
0 commit comments