WIN-2308041133\Administrator 1 неделя назад
Родитель
Сommit
8b533c7734
1 измененных файлов с 38 добавлено и 5 удалено
  1. 38 5
      app/admin/view/store/store_product/create.php

+ 38 - 5
app/admin/view/store/store_product/create.php

@@ -1802,15 +1802,48 @@
 
             // 监听编辑器内容变化,更新到formData
             that.$nextTick(function() {
-                // 使用setTimeout确保编辑器已初始化
+                // 延迟初始化编辑器,确保textarea存在
                 setTimeout(function() {
+                    // 检查textarea是否存在
+                    var editorElement = document.getElementById('myEditor');
+                    if (!editorElement) {
+                        console.error('找不到编辑器元素 #myEditor');
+                        return;
+                    }
+
+                    // 如果已经存在编辑器实例,先销毁
                     if (that.um) {
-                        that.um.addListener('contentChange', function() {
-                            that.formData.description = that.um.getContent();
-                        });
+                        that.um.destroy();
                     }
-                }, 1000);
+
+                    // 创建新的编辑器实例
+                    that.um = UM.getEditor('myEditor', {
+                        initialFrameWidth: '99%',
+                        initialFrameHeight: 400,
+                        autoHeightEnabled: true
+                    });
+
+                    // 编辑器就绪后设置内容
+                    that.um.addListener('ready', function() {
+                        console.log('UMEditor已就绪');
+                        // 设置内容(如果有)
+                        if (that.formData.description) {
+                            console.log('设置编辑器内容:', that.formData.description.substring(0, 50) + '...');
+                            that.um.setContent(that.formData.description);
+                        } else {
+                            console.log('没有商品详情内容');
+                            that.um.setContent('');
+                        }
+                    });
+
+                    // 监听内容变化
+                    that.um.addListener('contentChange', function() {
+                        that.formData.description = that.um.getContent();
+                        console.log('编辑器内容已更新');
+                    });
+                }, 800); // 适当延迟
             });
+
         }
     });
 </script>