index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div>
  3. <div v-show="!monacoBox">
  4. <div ref="wang-editor" class="wang-editor" />
  5. </div>
  6. <div v-if="monacoBox">
  7. <el-button type="primary" class="bottom" @click="getHtmlint">可视化界面</el-button>
  8. <monaco class="monaco-box" @change="changeValue" :value="newHtml" />
  9. </div>
  10. <el-dialog :visible.sync="modalPic" width="1024px" title="上传图片" :close-on-click-modal="false">
  11. <uploadPictures v-if="modalPic" :isChoice="isChoice" @getPic="getPic" @getPicD="getPicD"></uploadPictures>
  12. </el-dialog>
  13. <el-dialog :visible.sync="modalVideo" width="720px" title="上传视频" :close-on-click-modal="false">
  14. <uploadVideo v-if="modalVideo" @getVideo="getvideo"></uploadVideo>
  15. </el-dialog>
  16. </div>
  17. </template>
  18. <script>
  19. import monaco from './monaco';
  20. import E from 'wangeditor';
  21. import AlertMenu from './editor';
  22. import HtmlMenu from './html';
  23. import uploadPictures from '@/components/uploadPictures';
  24. import uploadVideo from '@/components/uploadVideo2';
  25. import { getCookies } from '@/libs/util';
  26. import util from '../../utils/bus';
  27. export default {
  28. name: 'Index',
  29. components: {
  30. uploadPictures,
  31. uploadVideo,
  32. monaco,
  33. },
  34. props: {
  35. content: {
  36. type: String,
  37. default: '',
  38. },
  39. },
  40. data() {
  41. return {
  42. monacoBox: false,
  43. value: '',
  44. modalPic: false,
  45. isChoice: '多选',
  46. picTit: 'danFrom',
  47. img: '',
  48. modalVideo: false,
  49. editor: null,
  50. uploadSize: 2,
  51. video: '',
  52. // header: {
  53. // "Authori-zation": "Bearer " + getCookies("token"),
  54. // },
  55. };
  56. },
  57. watch: {
  58. content(val) {
  59. this.editor.txt.html(val);
  60. },
  61. },
  62. created() {
  63. // window.getvideoint = this.getvideoint;
  64. // window.getHtmlint = this.getHtmlint;
  65. },
  66. mounted() {
  67. this.createEditor();
  68. util.$on('Video', (Video) => {
  69. this.getvideoint();
  70. });
  71. util.$on('Html', (Html) => {
  72. this.getHtmlint();
  73. });
  74. },
  75. methods: {
  76. changeValue(value) {
  77. this.newHtml = value;
  78. this.$emit('editorContent', value);
  79. this.$emit('input', value);
  80. },
  81. // 获取多张图信息
  82. getPic(pc) {
  83. let _this = this;
  84. _this.img = pc.att_dir;
  85. _this.modalPic = false;
  86. this.editor.cmd.do('insertHTML', `<img src="${_this.img}" style="max-width:100%;"/>`);
  87. },
  88. getimg() {
  89. this.modalPic = true;
  90. this.isChoice = '多选';
  91. },
  92. getvideoint() {
  93. this.modalVideo = true;
  94. },
  95. getHtmlint() {
  96. this.monacoBox = !this.monacoBox;
  97. this.value = this.newHtml;
  98. if (!this.monacoBox) {
  99. this.editor.txt.html(this.newHtml);
  100. }
  101. },
  102. getPicD(data) {
  103. let _this = this;
  104. _this.modalPic = false;
  105. data.map((d) => {
  106. this.editor.cmd.do('insertHTML', `<img src="${d.att_dir}" style="max-width:100%;"/>`);
  107. });
  108. },
  109. getvideo(data) {
  110. let _this = this;
  111. _this.modalVideo = false;
  112. this.video = data;
  113. let videoHTML =
  114. '<video src="' + this.video + '" controls style="max-width:100%;min-height:500rpx"></video><p><br></p>';
  115. this.editor.cmd.do('insertHTML', videoHTML);
  116. },
  117. createEditor() {
  118. let _this = this;
  119. const menuKey = 'alertMenuKey';
  120. const html = 'alertHtml';
  121. this.editor = new E(this.$refs['wang-editor']);
  122. this.editor.menus.extend(menuKey, AlertMenu);
  123. this.editor.menus.extend(html, HtmlMenu);
  124. this.editor.config.menus = this.editor.config.menus.concat(html);
  125. this.editor.config.menus = this.editor.config.menus.concat(menuKey);
  126. this.editor.config.uploadImgFromMedia = function () {
  127. _this.getimg();
  128. };
  129. // this.editor.config.uploadVideoHeaders = _this.header;
  130. this.editor.config.height = 600;
  131. this.editor.config.menus = [
  132. 'alertHtml',
  133. 'head',
  134. 'bold',
  135. 'fontSize',
  136. 'fontName',
  137. 'italic',
  138. 'underline',
  139. 'strikeThrough',
  140. 'indent',
  141. 'lineHeight',
  142. 'foreColor',
  143. 'backColor',
  144. 'link',
  145. 'list',
  146. // "todo",
  147. 'justify',
  148. 'quote',
  149. 'emoticon',
  150. 'image',
  151. 'alertMenuKey',
  152. // "table",
  153. 'code',
  154. 'splitLine',
  155. ];
  156. // 配置全屏功能按钮是否展示
  157. // this.editor.config.showFullScreen = false
  158. this.editor.config.uploadImgShowBase64 = false;
  159. // this.editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']
  160. this.editor.config.zIndex = 0;
  161. // this.editor.config.uploadImgMaxSize = this.uploadSize * 1024 * 1024
  162. this.editor.config.compatibleMode = () => {
  163. // 返回 true 表示使用兼容模式;返回 false 使用标准模式
  164. return true;
  165. };
  166. this.editor.config.onchange = (newHtml) => {
  167. this.newHtml = newHtml;
  168. this.$emit('editorContent', newHtml);
  169. };
  170. this.editor.config.onchangeTimeout = 300; // change后多久更新数据
  171. this.editor.create();
  172. },
  173. },
  174. };
  175. </script>
  176. <style lang="stylus" scoped>
  177. .bottom {
  178. margin-bottom: 10px;
  179. cursor: pointer;
  180. }
  181. .monaco-box ::v-deep .el-textarea__inner {
  182. height: 600px;
  183. }
  184. ::v-deep .w-e-toolbar {
  185. z-index: 2 !important;
  186. }
  187. </style>