@@ -49,6 +49,12 @@ function bindEvents() {
4949 document . getElementById ( 'cancelBtn' ) ?. addEventListener ( 'click' , closeModal ) ;
5050 document . querySelector ( '.modal-overlay' ) ?. addEventListener ( 'click' , closeModal ) ;
5151 document . getElementById ( 'promptForm' ) ?. addEventListener ( 'submit' , handleFormSubmit ) ;
52+
53+ // 详情页面模态框
54+ document . getElementById ( 'closeDetailModal' ) ?. addEventListener ( 'click' , closeDetailModal ) ;
55+ document . querySelector ( '#detailModal' ) ?. addEventListener ( 'click' , ( e ) => {
56+ if ( e . target === e . currentTarget ) closeDetailModal ( ) ;
57+ } ) ;
5258}
5359
5460// 加载提示词
@@ -87,22 +93,22 @@ function renderPrompts(prompts: any[]) {
8793 }
8894
8995 promptList . innerHTML = prompts . map ( prompt => `
90- <div class="prompt-card" data-id="${ prompt . id } ">
96+ <div class="prompt-card" data-id="${ prompt . id } " onclick="showPromptDetail( ${ prompt . id } )" >
9197 ${ prompt . pinned ? '<div class="pin-indicator"><i class="fas fa-thumbtack"></i></div>' : '' }
9298
9399 <div class="card-header">
94100 <h3 class="card-title">${ prompt . name } </h3>
95101 <div class="card-actions">
96- <button class="btn btn-icon" onclick="togglePin(${ prompt . id } )" title="${ prompt . pinned ? '取消置顶' : '置顶' } ">
102+ <button class="btn btn-icon" onclick="event.stopPropagation(); togglePin(${ prompt . id } )" title="${ prompt . pinned ? '取消置顶' : '置顶' } ">
97103 <i class="fas fa-thumbtack ${ prompt . pinned ? 'pinned' : '' } "></i>
98104 </button>
99- <button class="btn btn-icon" onclick="copyPrompt(${ prompt . id } )" title="复制">
105+ <button class="btn btn-icon" onclick="event.stopPropagation(); copyPrompt(${ prompt . id } )" title="复制">
100106 <i class="fas fa-copy"></i>
101107 </button>
102- <button class="btn btn-icon" onclick="editPrompt(${ prompt . id } )" title="编辑">
108+ <button class="btn btn-icon" onclick="event.stopPropagation(); editPrompt(${ prompt . id } )" title="编辑">
103109 <i class="fas fa-edit"></i>
104110 </button>
105- <button class="btn btn-icon" onclick="deletePrompt(${ prompt . id } )" title="删除">
111+ <button class="btn btn-icon" onclick="event.stopPropagation(); deletePrompt(${ prompt . id } )" title="删除">
106112 <i class="fas fa-trash"></i>
107113 </button>
108114 </div>
@@ -348,7 +354,107 @@ async function handleFormSubmit(e: Event) {
348354 }
349355}
350356
357+ // 显示提示词详情页面
358+ function showPromptDetail ( id : number ) {
359+ const prompt = currentPrompts . find ( p => p . id === id ) ;
360+ if ( ! prompt ) return ;
361+
362+ const detailModal = document . getElementById ( 'detailModal' ) ;
363+ const detailName = document . getElementById ( 'detailName' ) ;
364+ const detailSource = document . getElementById ( 'detailSource' ) ;
365+ const detailSourceItem = document . getElementById ( 'detailSourceItem' ) ;
366+ const detailUpdatedAt = document . getElementById ( 'detailUpdatedAt' ) ;
367+ const detailTags = document . getElementById ( 'detailTags' ) ;
368+ const detailTagsContainer = document . getElementById ( 'detailTagsContainer' ) ;
369+ const detailContent = document . getElementById ( 'detailContent' ) ;
370+ const detailNotes = document . getElementById ( 'detailNotes' ) ;
371+ const detailNotesContainer = document . getElementById ( 'detailNotesContainer' ) ;
372+ const detailPinBtn = document . getElementById ( 'detailPinBtn' ) ;
373+ const detailPinText = document . getElementById ( 'detailPinText' ) ;
374+
375+ if ( ! detailModal ) return ;
376+
377+ // 填充详情信息
378+ if ( detailName ) detailName . textContent = prompt . name ;
379+ if ( detailSource ) detailSource . textContent = prompt . source || '' ;
380+ if ( detailUpdatedAt ) detailUpdatedAt . textContent = formatDate ( prompt . updated_at ) ;
381+ if ( detailContent ) detailContent . textContent = prompt . content ;
382+ if ( detailNotes ) detailNotes . textContent = prompt . notes || '' ;
383+
384+ // 处理来源显示
385+ if ( detailSourceItem ) {
386+ detailSourceItem . style . display = prompt . source ? 'flex' : 'none' ;
387+ }
388+
389+ // 处理标签显示
390+ if ( detailTags && detailTagsContainer ) {
391+ if ( prompt . tags && prompt . tags . length > 0 ) {
392+ detailTags . innerHTML = prompt . tags . map ( ( tag : string ) =>
393+ `<span class="tag">${ tag } </span>`
394+ ) . join ( '' ) ;
395+ detailTagsContainer . style . display = 'block' ;
396+ } else {
397+ detailTagsContainer . style . display = 'none' ;
398+ }
399+ }
400+
401+ // 处理备注显示
402+ if ( detailNotesContainer ) {
403+ detailNotesContainer . style . display = prompt . notes ? 'block' : 'none' ;
404+ }
405+
406+ // 更新置顶按钮状态
407+ if ( detailPinText ) {
408+ detailPinText . textContent = prompt . pinned ? '取消置顶' : '置顶' ;
409+ }
410+ if ( detailPinBtn ) {
411+ detailPinBtn . className = prompt . pinned ? 'btn btn-outline pinned' : 'btn btn-outline' ;
412+ }
413+
414+ // 绑定详情页面的按钮事件
415+ const detailCopyBtn = document . getElementById ( 'detailCopyBtn' ) ;
416+ const detailEditBtn = document . getElementById ( 'detailEditBtn' ) ;
417+
418+ if ( detailCopyBtn ) {
419+ detailCopyBtn . onclick = ( ) => ( window as any ) . copyPrompt ( prompt . id ) ;
420+ }
421+
422+ if ( detailEditBtn ) {
423+ detailEditBtn . onclick = ( ) => {
424+ closeDetailModal ( ) ;
425+ ( window as any ) . editPrompt ( prompt . id ) ;
426+ } ;
427+ }
428+
429+ if ( detailPinBtn ) {
430+ detailPinBtn . onclick = async ( ) => {
431+ await ( window as any ) . togglePin ( prompt . id ) ;
432+ // 更新详情页面的置顶状态
433+ const updatedPrompt = currentPrompts . find ( p => p . id === id ) ;
434+ if ( updatedPrompt && detailPinText ) {
435+ detailPinText . textContent = updatedPrompt . pinned ? '取消置顶' : '置顶' ;
436+ detailPinBtn . className = updatedPrompt . pinned ? 'btn btn-outline pinned' : 'btn btn-outline' ;
437+ }
438+ } ;
439+ }
440+
441+ // 显示模态框
442+ detailModal . classList . add ( 'show' ) ;
443+ document . body . style . overflow = 'hidden' ;
444+ }
445+
446+ // 关闭详情页面模态框
447+ function closeDetailModal ( ) {
448+ const detailModal = document . getElementById ( 'detailModal' ) ;
449+ if ( detailModal ) {
450+ detailModal . classList . remove ( 'show' ) ;
451+ document . body . style . overflow = '' ;
452+ }
453+ }
454+
351455// 全局函数 - 确保这些函数在全局作用域中可用
456+ ( window as any ) . showPromptDetail = showPromptDetail ;
457+
352458( window as any ) . copyPrompt = async ( id : number ) => {
353459 try {
354460 const prompt = currentPrompts . find ( p => p . id === id ) ;
@@ -579,7 +685,11 @@ function initKeyboardShortcuts() {
579685 // Escape: 关闭模态框
580686 if ( e . key === 'Escape' ) {
581687 const modal = document . getElementById ( 'modal' ) ;
582- if ( modal && modal . classList . contains ( 'show' ) ) {
688+ const detailModal = document . getElementById ( 'detailModal' ) ;
689+
690+ if ( detailModal && detailModal . classList . contains ( 'show' ) ) {
691+ closeDetailModal ( ) ;
692+ } else if ( modal && modal . classList . contains ( 'show' ) ) {
583693 closeModal ( ) ;
584694 }
585695 }
0 commit comments