LiuJ 1 周之前
父节点
当前提交
ba303f3ecb
共有 1 个文件被更改,包括 10 次插入7 次删除
  1. 10 7
      src/components/edit/myEditor.vue

+ 10 - 7
src/components/edit/myEditor.vue

@@ -31,13 +31,13 @@ export default {
         font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;宋体=simsun,serif',
         fontsize_formats: '12px 14px 16px 18px 20px 22px 24px 28px 32px 36px 42px 48px',
         branding: false,
-        images_upload_handler: function (blobInfo , success, failure) {
+        images_upload_handler: function (blobInfo, success, failure) {
           var xhr, formData;
           xhr = new XMLHttpRequest();
           xhr.withCredentials = false;
           //创建连接
           xhr.open('POST', url.baseUrl + '/public/uploadFile');
-          xhr.onload = function() {
+          xhr.onload = function () {
             var json;
             if (xhr.status < 200 || xhr.status >= 300) {
               failure('HTTP Error: ' + xhr.status);
@@ -45,18 +45,18 @@ export default {
             }
             json = JSON.parse(xhr.responseText);
             console.log(json)
-            if (json.code!=200) {
+            if (json.code != 200) {
               failure('图片上传失败! ' + json.message);
               return;
             }
             success(json.data.imgUrl);
             // Listen for the NodeChange event to set the alt attribute
             const editor = tinymce.activeEditor;
-            editor.on('NodeChange', function(e) {
+            editor.on('NodeChange', function (e) {
               const imgElm = e.element;
               if (imgElm.nodeName === 'IMG' && imgElm.src === json.data.imgUrl) {
-                console.log("Setting alt attribute to:",  json.data.oldName || '全国政务信息一体化应用平台'); // Debugging: Check the alt value
-                editor.dom.setAttrib(imgElm, 'alt',json.data.oldName || '全国政务信息一体化应用平台'); // Use oldName or a default value
+                console.log("Setting alt attribute to:", json.data.oldName || '全国政务信息一体化应用平台'); // Debugging: Check the alt value
+                editor.dom.setAttrib(imgElm, 'alt', json.data.oldName || '全国政务信息一体化应用平台'); // Use oldName or a default value
                 editor.off('NodeChange'); // Remove the event listener after setting the alt
               }
             });
@@ -89,10 +89,13 @@ export default {
     }
   },
   components: {
-      'tiny-editor': editor,
+    'tiny-editor': editor,
   },
   created() {
 
+  },
+  mounted() {
+    this.reinitEditor();
   },
   methods: {
     // 强制重新初始化编辑器(必要时使用)