@@ -462,7 +462,6 @@ <h4>模型信息</h4>
462462 // 页面加载时初始化
463463 document . addEventListener ( 'DOMContentLoaded' , function ( ) {
464464 loadAvailableModels ( ) ;
465- loadEmotionMappingConfig ( ) ;
466465 } ) ;
467466
468467 // 全局错误处理
@@ -473,25 +472,6 @@ <h4>模型信息</h4>
473472
474473
475474
476- // 加载情绪映射配置
477- async function loadEmotionMappingConfig ( ) {
478- try {
479- const response = await fetch ( '/api/live2d/emotion_mapping' ) ;
480- const data = await response . json ( ) ;
481-
482- if ( data . success ) {
483- emotionMappingConfig = data . config || { } ;
484- showStatus ( '情绪映射配置加载成功' , 'success' ) ;
485- } else {
486- emotionMappingConfig = { } ;
487- showStatus ( '加载情绪映射配置失败: ' + data . error , 'error' ) ;
488- }
489- } catch ( error ) {
490- emotionMappingConfig = { } ;
491- showStatus ( '加载情绪映射配置时出错: ' + error . message , 'error' ) ;
492- }
493- }
494-
495475 // 加载可用的模型列表
496476 async function loadAvailableModels ( ) {
497477 try {
@@ -525,8 +505,7 @@ <h4>模型信息</h4>
525505 } ) ;
526506 }
527507
528- // 加载模型映射配置
529- async function loadModelMapping ( ) {
508+ async function loadModelMapping ( ) {
530509 const modelSelect = document . getElementById ( 'model-select' ) ;
531510 const selectedModel = modelSelect . value ;
532511
@@ -544,13 +523,15 @@ <h4>模型信息</h4>
544523 statusText . textContent = '正在加载配置和模型文件...' ;
545524 statusDot . className = 'status-dot info' ;
546525
547- const [ configResponse , filesResponse ] = await Promise . all ( [
526+ const [ configResponse , filesResponse , emotionMappingResponse ] = await Promise . all ( [
548527 fetch ( `/api/live2d/model_config/${ selectedModel } ` ) ,
549- fetch ( `/api/live2d/model_files/${ selectedModel } ` )
528+ fetch ( `/api/live2d/model_files/${ selectedModel } ` ) ,
529+ fetch ( `/api/live2d/emotion_mapping/${ selectedModel } ` )
550530 ] ) ;
551531
552532 const configData = await configResponse . json ( ) ;
553533 const filesData = await filesResponse . json ( ) ;
534+ const emotionMappingData = await emotionMappingResponse . json ( ) ;
554535
555536 if ( configData . success ) {
556537 currentModelConfig = configData . config ;
@@ -578,6 +559,13 @@ <h4>模型信息</h4>
578559 statusIndicator . classList . add ( 'hidden' ) ;
579560 } , 3000 ) ;
580561 }
562+
563+ if ( emotionMappingData . success ) {
564+ emotionMappingConfig [ currentModel ] = emotionMappingData . config || { motions : { } , expressions : { } } ;
565+ } else {
566+ emotionMappingConfig [ currentModel ] = { motions : { } , expressions : { } } ;
567+ showStatus ( '加载情绪映射配置失败: ' + emotionMappingData . error , 'error' ) ;
568+ }
581569
582570 // 自动为没有映射的模型添加映射
583571 autoAddModelMapping ( selectedModel ) ;
@@ -781,35 +769,21 @@ <h4>表情文件 (${expressions.length})</h4>
781769 try {
782770 showStatus ( '正在保存配置...' , 'info' ) ;
783771
784- // 保存模型配置
785- const configResponse = await fetch ( `/api/live2d/model_config/${ currentModel } ` , {
786- method : 'POST' ,
787- headers : {
788- 'Content-Type' : 'application/json' ,
789- } ,
790- body : JSON . stringify ( currentModelConfig )
791- } ) ;
792-
793- const configData = await configResponse . json ( ) ;
794-
795772 // 保存情绪映射配置
796- const emotionResponse = await fetch ( ' /api/live2d/emotion_mapping' , {
773+ const emotionResponse = await fetch ( ` /api/live2d/emotion_mapping/ ${ currentModel } ` , {
797774 method : 'POST' ,
798775 headers : {
799776 'Content-Type' : 'application/json' ,
800777 } ,
801- body : JSON . stringify ( emotionMappingConfig )
778+ body : JSON . stringify ( emotionMappingConfig [ currentModel ] )
802779 } ) ;
803780
804781 const emotionData = await emotionResponse . json ( ) ;
805782
806- if ( configData . success && emotionData . success ) {
783+ if ( emotionData . success ) {
807784 showStatus ( '配置保存成功' , 'success' ) ;
808785 } else {
809- const errors = [ ] ;
810- if ( ! configData . success ) errors . push ( '模型配置: ' + configData . error ) ;
811- if ( ! emotionData . success ) errors . push ( '情绪映射: ' + emotionData . error ) ;
812- showStatus ( '保存配置失败: ' + errors . join ( ', ' ) , 'error' ) ;
786+ showStatus ( '保存配置失败: ' + emotionData . error , 'error' ) ;
813787 }
814788 } catch ( error ) {
815789 showStatus ( '保存配置时出错: ' + error . message , 'error' ) ;
@@ -843,15 +817,7 @@ <h4>表情文件 (${expressions.length})</h4>
843817 const totalExpressionFiles = currentModelFiles . expression_files . length ;
844818 status . textContent = `动作文件: ${ totalMotionFiles } | 表情文件: ${ totalExpressionFiles } ` ;
845819 }
846-
847-
848-
849-
850-
851-
852-
853-
854-
820+
855821 // 显示toast通知
856822 function showStatus ( message , type ) {
857823 const toastContainer = document . getElementById ( 'toast-container' ) ;
0 commit comments