fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<template>
  <div class="editor-container">
    <div :id="id"></div>
  </div>
</template>
<script>
import ClassicEditor from '.././../../public/editor-video/ckeditor'
import UploadAdapter from './uploadAdapter'
function UploadAdapterPlugin (editor) {
  editor.plugins.get('FileRepository').createUploadAdapter = (loader) => {
    return new UploadAdapter(loader)
  }
}
export default {
  name: 'editor',
  props: {
    content: {
      type: String,
      default: ''
    },
    id: {
      default: 'editor'
    }
  },
  data () {
    return {
      editor: null
    }
  },
  watch: {
    content: {
      handler () {
        this.content && this.editor && this.editor.setData(this.content)
      },
      immediate: true
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    init () {
      ClassicEditor.create(document.querySelector(`#${this.id}`), {
        extraPlugins: [UploadAdapterPlugin]
      })
        .then(editor => {
          this.editor = editor
          this.content && this.editor && this.editor.setData(this.content)
        })
        .catch(error => {
          console.error('There was a problem initializing the editor.', error)
        })
    },
    getData () {
      let content = this.editor.getData()
      content = content.replace(/<video /g, '<video controls muted ')
      return content
    }
  }
}
</script>
<style lang="scss">
.ck-content {
  height:500px;
  font-size: 16px;
}
.editor-container .ck.ck-editor__editable_inline {
  border: 1px solid var(--ck-color-toolbar-border);
  // border-top: none;
  padding: 0 30px;
}
</style>