TinyEditor.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <TinyEditor v-model="content" :placeholder="placeholder" api-key="ushn75pw8xd7ec18wwdatp7bi75o98pm0ob10zncyyrbkj4k" :init="options" />
  3. </template>
  4. <script>
  5. import TinyEditor from '@tinymce/tinymce-vue'
  6. import { publicFileSaveAPI } from '@/api/common'
  7. import { publicFileGetUrl } from "@/api/common"
  8. import { getToken } from '@/utils/auth'
  9. export default {
  10. components: {
  11. TinyEditor
  12. },
  13. props: {
  14. value: {
  15. default: '',
  16. type: String
  17. },
  18. height: {
  19. default: 800,
  20. type: Number
  21. },
  22. placeholder: {
  23. default: '',
  24. type: String
  25. }
  26. },
  27. data() {
  28. return {
  29. options: {
  30. base_url: '//itie-static.oss-cn-hangzhou.aliyuncs.com/assets/tinymce/',
  31. language: 'zh_CN',
  32. language_url: '//itie-static.oss-cn-hangzhou.aliyuncs.com/assets/tinymce/zh_CN.js',
  33. height: 500,
  34. resize: true,
  35. statusbar: false,
  36. // skin_url: '//itie-static.oss-cn-hangzhou.aliyuncs.com/assets/tinymce/oxide-dark', // 暗色皮肤
  37. // content_css: '//itie-static.oss-cn-hangzhou.aliyuncs.com/assets/tinymce/content.css',
  38. plugins: ['advlist anchor autolink autosave code codesample directionality emoticons fullscreen hr image imagetools importcss insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus table template textpattern visualblocks visualchars wordcount placeholder indent2em'], // 插件
  39. image_advtab: true,
  40. images_upload_handler: this.updateImage,
  41. imagetools_toolbar: '',
  42. fontsize_formats: '8px 10px 12px 14px 16px 18px 20px 22px 24px 36px',
  43. 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 indent2em']
  44. }
  45. }
  46. },
  47. computed: {
  48. content: {
  49. get() {
  50. return this.value
  51. },
  52. set(val) {
  53. this.$emit('input', val)
  54. }
  55. }
  56. },
  57. methods: {
  58. updateImage(blobInfo, success, failure) {
  59. publicFileSaveAPI(
  60. { file: blobInfo.blob() },
  61. {
  62. "Authorization": "Bearer " + getToken(),
  63. "x-zz-timestamp": new Date().valueOf()
  64. }).then(res => {
  65. success(publicFileGetUrl + res.data.fileName)
  66. }).catch(err => {
  67. failure(err)
  68. })
  69. }
  70. }
  71. }
  72. </script>