index.vue 5.2 KB

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