editor.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div><vue-tinymce v-model="contentValue" :setting="setting" v-if="open" /></div>
  3. </template>
  4. <script>
  5. import { uploadFile } from '@/api/common';
  6. export default {
  7. props: {
  8. readonly: {
  9. type: Boolean,
  10. default: false
  11. },
  12. height: {
  13. type: Number,
  14. default: 450
  15. },
  16. value: {
  17. default: ''
  18. }
  19. },
  20. data() {
  21. return {
  22. open: false,
  23. contentValue: this.value,
  24. baseUrl: process.env.VUE_APP_BASE_API,
  25. setting: {
  26. menubar: false,
  27. ProgressState: true,
  28. readonly: this.readonly,
  29. toolbar:
  30. 'fullscreen preview code | undo redo | lineheight bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | numlist bullist | upfile image axupimgs media importword table | formatselect fontselect fontsizeselect forecolor backcolor | indent outdent | superscript subscript | removeformat | wordcount | help',
  31. toolbar_drawer: 'sliding',
  32. quickbars_selection_toolbar: 'removeformat | bold italic underline strikethrough | fontsizeselect forecolor backcolor',
  33. plugins: 'preview code lineheight wordcount upfile image axupimgs imagetools media table lists fullscreen quickbars help',
  34. language: 'zh_CN',
  35. content_style: 'img {max-width:100%;}', //编辑器内限制图片大小
  36. convert_urls: false,
  37. height: this.height,
  38. paste_data_images: true,
  39. //图片上传
  40. images_upload_handler: (blobInfo, succFun, failFun) => {
  41. let formData = new FormData();
  42. formData.append('file', blobInfo.blob());
  43. uploadFile(formData)
  44. .then((response) => {
  45. this.$modal.msgSuccess('上传成功');
  46. succFun(this.baseUrl + response.fileName);
  47. })
  48. .catch(() => {});
  49. },
  50. file_callback: (file, succFun) => {
  51. let formData = new FormData();
  52. formData.append('file', file);
  53. uploadFile(formData)
  54. .then((response) => {
  55. this.$modal.msgSuccess('上传成功');
  56. succFun(this.baseUrl + response.fileName);
  57. })
  58. .catch(() => {});
  59. },
  60. //文件上传
  61. file_picker_callback: (callback, value, meta) => {
  62. //文件分类
  63. let filetype;
  64. //为不同插件指定文件类型及后端地址
  65. switch (meta.filetype) {
  66. case 'image':
  67. filetype = '.jpg, .jpeg, .png, .gif';
  68. break;
  69. case 'media':
  70. filetype = '.mp3, .mp4';
  71. break;
  72. case 'file':
  73. default:
  74. }
  75. //模拟出一个input用于添加本地文件
  76. let input = document.createElement('input');
  77. input.setAttribute('type', 'file');
  78. input.setAttribute('accept', filetype);
  79. input.click();
  80. input.onchange = () => {
  81. let file = input.files[0];
  82. let formData = new FormData();
  83. formData.append('file', file, file.name);
  84. uploadFile(formData)
  85. .then((response) => {
  86. this.$modal.msgSuccess('上传成功');
  87. callback(this.baseUrl + response.fileName);
  88. })
  89. .catch(() => {});
  90. };
  91. }
  92. }
  93. };
  94. },
  95. watch: {
  96. value(newValue) {
  97. if (newValue) {
  98. this.contentValue = newValue;
  99. }
  100. },
  101. contentValue(newValue) {
  102. this.$emit('input', newValue);
  103. }
  104. },
  105. mounted() {
  106. setTimeout(() => {
  107. this.open = true;
  108. }, 1000);
  109. },
  110. beforeDestroy() {
  111. this.open = false;
  112. },
  113. methods: {}
  114. };
  115. </script>
  116. <style lang="scss">
  117. .tox.tox-tinymce.tox-fullscreen {
  118. width: 100% !important;
  119. }
  120. .tox-shadowhost.tox-fullscreen,
  121. .tox.tox-tinymce.tox-fullscreen {
  122. z-index: 1200000 !important;
  123. }
  124. </style>