guoziyun hace 9 meses
padre
commit
5302f6a6c0

+ 1 - 1
oms/public/app/index.html

@@ -9,5 +9,5 @@
   <style>body,html{width:100%;height:100%}*,:after,:before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;-ms-overflow-style:scrollbar;-webkit-tap-highlight-color:transparent}@-ms-viewport{width:device-width}body{margin:0;color:#000000d9;font-size:14px;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-variant:tabular-nums;line-height:1.5715;background-color:#fff;font-feature-settings:"tnum"}html{--antd-wave-shadow-color:#1890ff;--scroll-bar:0}</style><link rel="stylesheet" href="styles-LXBSU6DF.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles-LXBSU6DF.css"></noscript></head>
   <body>
     <app-root></app-root>
-  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-AE5IQ2RX.js" type="module"></script></body>
+  <script src="polyfills-B6TNHZQ6.js" type="module"></script><script src="main-NVZNF4PY.js" type="module"></script></body>
 </html>

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
oms/public/app/main-NVZNF4PY.js


+ 62 - 68
omsapp/src/app/pages/message-template.component.ts

@@ -601,7 +601,6 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
           },
           { emitEvent: false }
         );
-
         this.loadTemplates();
       }
     );
@@ -613,12 +612,10 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
     }
   }
 
-  //替换原来的方法
   getActionOptions(): { value: string; label: string }[] {
     return this.messageService.getActionOptions();
   }
 
-  // 替换原来的方法
   getParamPlaceholder(): string {
     const action = this.templateForm.get('action')?.value as ActionType;
     return this.messageService.getActionParamPlaceholder(action);
@@ -639,7 +636,6 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
     });
   }
 
-  // 应用筛选条件
   applyFilters(): void {
     const filterValue = this.filterForm.value;
     this.filteredTemplates = this.templates.filter((template) => {
@@ -648,29 +644,21 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
             .toLowerCase()
             .includes(filterValue.templateName.toLowerCase())
         : true;
-
       const typeMatch =
         filterValue.templateType !== null
           ? template.templateType === filterValue.templateType
           : true;
-
       return nameMatch && typeMatch;
     });
   }
 
-  // 更新URL参数
   private updateUrl(): void {
     const queryParams: any = {};
     const filterValue = this.filterForm.value;
-
-    if (filterValue.templateName) {
+    if (filterValue.templateName)
       queryParams.templateName = filterValue.templateName;
-    }
-
-    if (filterValue.templateType !== null) {
+    if (filterValue.templateType !== null)
       queryParams.templateType = filterValue.templateType;
-    }
-
     this.router.navigate([], {
       relativeTo: this.route,
       queryParams,
@@ -678,19 +666,12 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
     });
   }
 
-  // 点击类型标签筛选
   filterByType(type: TemplateType): void {
-    this.filterForm.patchValue({
-      templateType: type,
-    });
+    this.filterForm.patchValue({ templateType: type });
   }
 
-  // 重置筛选条件
   resetFilters(): void {
-    this.filterForm.reset({
-      templateName: '',
-      templateType: null,
-    });
+    this.filterForm.reset({ templateName: '', templateType: null });
   }
 
   getTemplateTypeName(type: TemplateType): string {
@@ -699,18 +680,16 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
 
   showCreateModal(): void {
     this.isEditMode = false;
-    // 关键修复:确保新建时模板名称控件可编辑
     const templateNameControl = this.templateForm.get('templateName');
-    if (templateNameControl) {
-      templateNameControl.enable();
-    }
-    // 重置表单默认值
+    if (templateNameControl) templateNameControl.enable();
+    // 重置表单并启用所有核心字段
     this.templateForm.reset({
       templateType: TemplateType.OTHER,
       bigger: false,
+      selectedLanguages: [],
     });
+    this.enableCoreFields(); // 确保核心字段启用
     this.clearDynamicControls();
-    // 设置默认语言
     const defaultLanguages = ['en', 'zh-cn'];
     this.templateForm.get('selectedLanguages')?.setValue(defaultLanguages);
     this.onLanguageSelectionChange();
@@ -721,11 +700,15 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
     this.isEditMode = true;
     this.selectedTemplate = template;
 
+    // 1. 先清理动态控件,避免影响表单重置
+    this.clearDynamicControls();
+
+    // 2. 重置表单(显式禁用事件触发),并加载模板数据
     this.templateForm.reset(
       {
         templateName: template.templateName,
         templateType: template.templateType,
-        description: template.description,
+        description: template.description || '', // 处理null值,避免表单值缺失
         image: template.image || null,
         bigger: template.bigger || false,
         action: template.action || null,
@@ -736,27 +719,26 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
       { emitEvent: false }
     );
 
-    // 编辑时禁用模板名称
+    // 3. 启用所有核心字段(确保可编辑),仅禁用templateName
+    this.enableCoreFields();
     const templateNameControl = this.templateForm.get('templateName');
-    if (templateNameControl) {
-      templateNameControl.disable();
-    }
+    if (templateNameControl) templateNameControl.disable();
 
-    this.clearDynamicControls();
-
-    // 加载多语言内容
+    // 4. 加载多语言内容
     Object.keys(template.messageTitle).forEach((lang) => {
+      const normalizedLang = lang.toLowerCase();
       this.templateForm.addControl(
-        `title_${lang}`,
+        `title_${normalizedLang}`,
         new FormControl(template.messageTitle[lang], Validators.required)
       );
       this.templateForm.addControl(
-        `content_${lang}`,
+        `content_${normalizedLang}`,
         new FormControl(template.messageContent[lang], Validators.required)
       );
     });
 
-    this.cdr.detectChanges();
+    // 强制更新视图,确保表单值同步
+    this.cdr.markForCheck();
     this.isModalVisible = true;
   }
 
@@ -766,20 +748,14 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
   }
 
   onLanguageSelectionChange(): void {
-    // 统一语言代码为小写,避免大小写不一致导致的问题
     const selectedLanguages = (
       this.templateForm.get('selectedLanguages')?.value || []
     ).map((lang: string) => lang.toLowerCase());
     const currentLanguages = this.getCurrentLanguageControls();
 
-    // 添加新选择的语言控件
     selectedLanguages.forEach((lang: string) => {
-      if (!currentLanguages.includes(lang)) {
-        this.addLanguageControls(lang);
-      }
+      if (!currentLanguages.includes(lang)) this.addLanguageControls(lang);
     });
-
-    // 移除取消选择的语言控件
     currentLanguages.forEach((lang) => {
       if (!selectedLanguages.includes(lang)) {
         this.templateForm.removeControl(`title_${lang}`);
@@ -798,10 +774,14 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
     const formValue = this.templateForm.getRawValue();
     const selectedLanguages = formValue.selectedLanguages;
 
+    // 核心修复:显式提取核心字段值,避免依赖getRawValue()的不确定性
     const messageData = {
-      templateName: formValue.templateName,
-      templateType: formValue.templateType,
-      description: formValue.description,
+      templateName: this.isEditMode
+        ? this.selectedTemplate!.templateName
+        : formValue.templateName,
+      templateType: this.templateForm.get('templateType')
+        ?.value as TemplateType, // 直接获取控件值
+      description: this.templateForm.get('description')?.value || '', // 处理null
       image: formValue.image,
       bigger: formValue.bigger,
       action: formValue.action,
@@ -811,17 +791,18 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
       messageContent: {} as { [key: string]: string },
     };
 
+    // 处理多语言内容
     selectedLanguages.forEach((lang: string) => {
       const normalizedLang = lang.toLowerCase();
       const titleControl = this.templateForm.get(`title_${normalizedLang}`);
       const contentControl = this.templateForm.get(`content_${normalizedLang}`);
-
       if (titleControl && contentControl) {
         messageData.messageTitle[normalizedLang] = titleControl.value;
         messageData.messageContent[normalizedLang] = contentControl.value;
       }
     });
 
+    // 提交更新/创建请求
     if (this.isEditMode && this.selectedTemplate) {
       this.updateTemplate(messageData);
     } else {
@@ -834,7 +815,7 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
       next: () => {
         this.message.success('模板创建成功');
         this.loadTemplates();
-        this.isModalVisible = false;
+        this.handleCancel();
         this.isSubmitting = false;
       },
       error: (err) => {
@@ -845,7 +826,10 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
   }
 
   updateTemplate(templateData: any): void {
-    if (!this.selectedTemplate) return;
+    if (!this.selectedTemplate) {
+      this.isSubmitting = false;
+      return;
+    }
 
     this.messageService
       .updateTemplate(this.selectedTemplate.templateName, templateData)
@@ -853,7 +837,7 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
         next: () => {
           this.message.success('模板更新成功');
           this.loadTemplates();
-          this.isModalVisible = false;
+          this.handleCancel();
           this.isSubmitting = false;
         },
         error: (err) => {
@@ -886,16 +870,30 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
   handleCancel(): void {
     this.isModalVisible = false;
     this.clearDynamicControls();
-    // 重置表单状态,避免下次打开时显示错误提示
+    // 重置表单状态并启用所有字段,避免影响下次打开
     Object.values(this.templateForm.controls).forEach((control) => {
       control.markAsPristine();
       control.markAsUntouched();
+      if (control.disabled) control.enable();
+    });
+  }
+
+  // 新增:启用核心字段(确保编辑时可提交)
+  private enableCoreFields(): void {
+    const coreFields = [
+      'templateType',
+      'description',
+      'image',
+      'bigger',
+      'action',
+      'param',
+      'extend',
+      'selectedLanguages',
+    ];
+    coreFields.forEach((field) => {
+      const control = this.templateForm.get(field);
+      if (control && control.disabled) control.enable();
     });
-    // 确保下次打开新建时模板名称可编辑
-    const templateNameControl = this.templateForm.get('templateName');
-    if (templateNameControl) {
-      templateNameControl.enable();
-    }
   }
 
   private addLanguageControls(lang: string): void {
@@ -939,17 +937,13 @@ export class MessageTemplateComponent implements OnInit, OnDestroy {
   }
 
   private handleApiError(err: any, action: string): void {
-    if (err.status === 409) {
-      this.message.error('模板名称已存在');
-    } else if (err.status === 404) {
-      this.message.error('未找到指定的模板');
-    } else if (err.status === 400) {
+    if (err.status === 409) this.message.error('模板名称已存在');
+    else if (err.status === 404) this.message.error('未找到指定的模板');
+    else if (err.status === 400)
       this.message.error(
         '验证错误: ' + (err.error?.message || '请检查输入数据')
       );
-    } else {
-      this.message.error(`${action}模板失败: ${err.message}`);
-    }
+    else this.message.error(`${action}模板失败: ${err.message}`);
   }
 
   getLanguageName(code: string): string {

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio