tinymceTemplate.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Vue.component('tinymce', {
  2. props: ['value','img'],
  3. data(){
  4. return{
  5. flag:true,
  6. hasInit: false,
  7. hasChange: false,
  8. }
  9. },
  10. watch:{
  11. value(val){
  12. if(this.flag){
  13. tinyMCE.activeEditor.setContent(val);
  14. }
  15. this.flag=true;
  16. },
  17. img(){
  18. if(this.img){
  19. tinyMCE.activeEditor.insertContent(`<img src="${this.img}" >`)
  20. }
  21. }
  22. },
  23. created(){
  24. window.addEventListener('beforeunload', e => {
  25. window.onbeforeunload =null
  26. });
  27. },
  28. mounted: function(){
  29. var component = this;
  30. tinymce.init({
  31. selector: '#tinymceId',
  32. language: "zh_CN",
  33. hasChange: false,
  34. hasInit: false,
  35. menubar: false,
  36. body_class: 'panel-body ',
  37. object_resizing: false,
  38. end_container_on_empty_block: true,
  39. powerpaste_word_import: 'clean',
  40. code_dialog_height: 450,
  41. code_dialog_width: 1000,
  42. advlist_bullet_styles: 'square',
  43. advlist_number_styles: 'default',
  44. imagetools_cors_hosts: ['www.tinymce.com', 'codepen.io'],
  45. default_link_target: '_blank',
  46. link_title: false,
  47. nonbreaking_force_tab: true, // inserting nonbreaking space &nbsp; need Nonbreaking Space Plugin
  48. plugins: ['advlist anchor autolink code codesample colorpicker colorpicker contextmenu directionality emoticons fullscreen hr image imagetools insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars wordcount'],
  49. toolbar: ['searchreplace bold italic underline strikethrough alignleft aligncenter alignright outdent indent blockquote undo redo removeformat subscript superscript code codesample', 'hr bullist numlist link image charmap preview anchor pagebreak insertdatetime media table emoticons forecolor backcolor fullscreen'],
  50. init_instance_callback: editor => {
  51. if (this.value) {
  52. editor.setContent(this.value)
  53. }
  54. this.hasInit = true
  55. editor.on('NodeChange Change KeyUp SetContent', () => {
  56. this.hasChange = true
  57. // this.$emit('input', editor.getContent())
  58. })
  59. },
  60. setup: function(editor) {
  61. editor.on('input undo redo execCommand', function(e) {
  62. component.flag=false;
  63. component.$emit('input', editor.getContent());
  64. })
  65. }
  66. });
  67. },
  68. methods:{
  69. setContent(value) {
  70. window.tinymce.get(this.tinymceId).setContent(value)
  71. },
  72. getContent() {
  73. window.tinymce.get(this.tinymceId).getContent()
  74. },
  75. destroyTinymce() {
  76. const tinymce = window.tinymce.get(this.tinymceId)
  77. if (this.fullscreen) {
  78. tinymce.execCommand('mceFullScreen')
  79. }
  80. if (tinymce) {
  81. tinymce.destroy()
  82. }
  83. },
  84. },
  85. template: `<div>
  86. <textarea id="tinymceId" style="height:600px" v-model="value"></textarea>
  87. </div>`
  88. });