normalArea.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div>
  3. <article :id="id" :style="fullScreen ? { ...fullPositionStyle, ...styles } : styles" class="article" :class="getClass">
  4. <!-- <textEditor :id="id" :value="inputValue" /> -->
  5. <span v-show="fullScreen" class="changeSizeBtn" @click="changeSize">
  6. <svg-icon
  7. icon-class="icon-sx"
  8. class="icon"
  9. />
  10. </span>
  11. <span v-show="!fullScreen" class="changeSizeBtn" @click="changeSize">
  12. <svg-icon
  13. icon-class="icon-qp"
  14. class="icon"
  15. />
  16. </span>
  17. <editor :id="'tinymce_'+id" ref="editor" v-model="inputValue" :init="init" @input="changeText" />
  18. </article>
  19. </div>
  20. </template>
  21. <script>
  22. import tinymce from 'tinymce/tinymce'
  23. import Editor from '@tinymce/tinymce-vue'
  24. import 'tinymce/themes/silver/theme'
  25. import 'tinymce/icons/default/icons'
  26. // import textEditor from './editor'
  27. export default {
  28. components: {
  29. Editor
  30. // textEditor
  31. },
  32. props: {
  33. id: {
  34. type: String,
  35. default: '',
  36. required: true
  37. },
  38. value: {
  39. type: String,
  40. default: '',
  41. required: false
  42. },
  43. height: {
  44. type: Number,
  45. default: 200,
  46. required: false
  47. },
  48. fullPositionStyle: {
  49. type: Object,
  50. default: () => {
  51. return { }
  52. },
  53. required: false
  54. },
  55. styles: {
  56. type: Object,
  57. default: () => {
  58. return { }
  59. },
  60. required: false
  61. },
  62. bottomMargin: {
  63. type: Boolean,
  64. default: false,
  65. required: false
  66. }
  67. },
  68. data() {
  69. return {
  70. fullScreen: false,
  71. inputValue: '',
  72. edit: false,
  73. init: {
  74. auto_focus: true,
  75. language_url: '/tinymce/langs/zh_CN.js',
  76. language: 'zh_CN',
  77. skin_url: '/tinymce/skins/ui/oxide', // 编辑器需要一个skin才能正常工作,所以要设置一个skin_url指向之前复制出来的skin文件
  78. height: this.height,
  79. browser_spellcheck: true, // 拼写检查
  80. branding: false, // 去水印
  81. elementpath: false, // 禁用编辑器底部的状态栏
  82. statusbar: false, // 隐藏编辑器底部的状态栏
  83. paste_data_images: true, // 允许粘贴图像
  84. menubar: false, // 隐藏最上方menu
  85. fontsize_formats: '14px 16px 18px 20px 24px 26px 28px 30px 32px 36px', // 字体大小
  86. file_picker_types: 'image',
  87. images_upload_credentials: true,
  88. plugins: 'fullscreen lists table textcolor wordcount contextmenu', // 引入插件
  89. toolbar: 'fullscreen bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent table | undo redo | removeformat formatselect',
  90. table_toolbar: 'tableprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol | tablemergecells tablesplitcells'
  91. }
  92. }
  93. },
  94. computed: {
  95. getClass() {
  96. let className = ''
  97. if (this.fullScreen) {
  98. className += 'fullScreen'
  99. }
  100. if (this.bottomMargin) {
  101. className += ' bottomMargin'
  102. }
  103. return className
  104. }
  105. },
  106. watch: {
  107. value: {
  108. handler(newV, oldV) {
  109. this.inputValue = newV
  110. },
  111. immediate: true
  112. }
  113. },
  114. mounted() {
  115. tinymce.init({ selector: `#tinymce_${this.id}` })
  116. },
  117. methods: {
  118. changeText(e) { // 富文本内容改变
  119. this.inputValue = e
  120. this.$emit('update:value', this.inputValue)
  121. this.$emit('change', this.inputValue)
  122. },
  123. changeSize() {
  124. this.fullScreen = !this.fullScreen
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped lang="scss">
  130. .article {
  131. position: relative;
  132. .changeSizeBtn {
  133. position: absolute;
  134. top: 3px;
  135. right: 4px;
  136. z-index: 1000;
  137. height: 34px;
  138. width: 34px;
  139. text-align: center;
  140. line-height: 34px;
  141. border-radius: 3px;
  142. .icon {
  143. color: #409eff;
  144. font-weight: 700;
  145. font-size: 18px;
  146. }
  147. &:hover {
  148. background: #c8cbcf;
  149. border: 0;
  150. box-shadow: none;
  151. }
  152. }
  153. }
  154. .fullScreen {
  155. position: fixed;
  156. top: 0px;
  157. bottom: 0;
  158. left: 225px;
  159. right: 0;
  160. z-index: 1000;
  161. height: 100vh!important;
  162. /deep/.tox-tinymce {
  163. height: 100vh!important;
  164. }
  165. &.bottomMargin {
  166. /deep/.tox-tinymce {
  167. height: calc(100vh - 40px)!important;
  168. }
  169. }
  170. }
  171. .editor {
  172. border: 1px solid #666;
  173. }
  174. </style>