@@ -140,7 +140,7 @@ const ChallengeContributePage: React.FC = () => {
140140 'difficulty-level' : values . difficultyLevel ,
141141 'description-markdown' : values . description || values . descriptionMarkdown ,
142142 'base64-url' : values . base64Url ,
143- 'is-expired' : values . isExpired ,
143+ 'is-expired' : values . isExpired === undefined ? false : values . isExpired ,
144144 'tags' : values . tags || [ ] ,
145145 'solutions' : ( values . solutions || [ ] ) ?. filter ( s => s . title && s . url ) . map ( s => ( {
146146 title : s . title ,
@@ -170,12 +170,12 @@ const ChallengeContributePage: React.FC = () => {
170170 'name' : values . name ,
171171 'name_en' : values . nameEn ,
172172 '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 || '' ,
175175 'base64-url' : values . base64Url ,
176- 'is-expired' : values . isExpired ,
176+ 'is-expired' : values . isExpired === undefined ? false : values . isExpired ,
177177 '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 ) => ( {
179179 title : s . title ,
180180 url : s . url ,
181181 ...( s . source ? { source : s . source } : { } ) ,
@@ -187,7 +187,7 @@ const ChallengeContributePage: React.FC = () => {
187187 const lines = values . rawYaml . split ( '\n' ) ;
188188
189189 // 新的方法:创建行类型映射,标记每行是什么类型
190- const lineTypes = lines . map ( line => {
190+ const lineTypes = lines . map ( ( line : string ) => {
191191 const trimmedLine = line . trim ( ) ;
192192 if ( trimmedLine === '' ) return 'empty' ;
193193 if ( trimmedLine . startsWith ( '#' ) ) return 'comment' ;
@@ -228,22 +228,22 @@ const ChallengeContributePage: React.FC = () => {
228228 if ( ! fieldRanges [ currentField ] ) {
229229 fieldRanges [ currentField ] = { start : - 1 , end : - 1 , valueStart : - 1 , valueEnd : - 1 } ;
230230 }
231- fieldRanges [ currentField ] . end = i - 1 ;
231+ fieldRanges [ currentField as string ] . end = i - 1 ;
232232 }
233233
234234 // 记录当前字段的开始位置
235235 currentField = fieldName ;
236236 if ( ! fieldRanges [ currentField ] ) {
237237 fieldRanges [ currentField ] = { start : i , end : - 1 , valueStart : - 1 , valueEnd : - 1 } ;
238238 } else {
239- fieldRanges [ currentField ] . start = i ;
239+ fieldRanges [ currentField as string ] . start = i ;
240240 }
241241
242242 // 找出值的开始位置
243243 const valueMatch = line . match ( / ^ ( \s * [ a - z A - Z 0 - 9 _ - ] + : ) ( \s * ) ( .* ) / ) ;
244244 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 ;
247247 }
248248
249249 // 处理tags和solutions字段
@@ -272,7 +272,7 @@ const ChallengeContributePage: React.FC = () => {
272272
273273 // 设置最后一个字段的结束位置
274274 if ( currentField && fieldRanges [ currentField ] ) {
275- fieldRanges [ currentField ] . end = lines . length - 1 ;
275+ fieldRanges [ currentField as string ] . end = lines . length - 1 ;
276276 }
277277
278278 console . log ( '字段范围:' , fieldRanges ) ;
@@ -288,6 +288,12 @@ const ChallengeContributePage: React.FC = () => {
288288 continue ; // 这些复杂字段单独处理
289289 }
290290
291+ // 特殊处理is-expired字段,确保它总是有值
292+ if ( fieldName === 'is-expired' && ( value === undefined || value === null ) ) {
293+ // 如果is-expired未定义,默认设为false
294+ fieldValueMap [ 'is-expired' ] = false ;
295+ }
296+
291297 if ( fieldRanges [ fieldName ] && fieldRanges [ fieldName ] . valueStart >= 0 ) {
292298 const lineIndex = fieldRanges [ fieldName ] . start ;
293299 const line = lines [ lineIndex ] ;
@@ -303,9 +309,10 @@ const ChallengeContributePage: React.FC = () => {
303309 if ( fieldValueMap [ 'description-markdown' ] && fieldRanges [ 'description-markdown' ] ) {
304310 const fieldRange = fieldRanges [ 'description-markdown' ] ;
305311 const startLine = fieldRange . start ;
306- const indent = fieldIndents [ 'description-markdown' ] ;
312+ const indent = fieldIndents [ 'description-markdown' ] || '' ;
307313
308- const descriptionValue = fieldValueMap [ 'description-markdown' ] ;
314+ // 获取最新的描述内容(确保使用最新表单值)
315+ const descriptionValue = form . getFieldValue ( 'description' ) || form . getFieldValue ( 'descriptionMarkdown' ) || '' ;
309316
310317 // 检查原始格式是否使用竖线(|)
311318 if ( lines [ startLine ] . includes ( '|' ) ) {
@@ -576,7 +583,7 @@ const ChallengeContributePage: React.FC = () => {
576583 // 处理base64Url字段,确保正确映射
577584 base64Url : challengeData [ 'base64-url' ] || '' ,
578585 // 处理过期标志
579- isExpired : challengeData [ 'is-expired' ] === true ,
586+ isExpired : challengeData [ 'is-expired' ] === true || false ,
580587 tags : challengeData . tags || [ ] ,
581588 solutions : ( challengeData . solutions || [ ] ) . map ( ( solution : any ) => ( {
582589 title : solution . title || '' ,
0 commit comments