123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <template>
- <div class="rich-text-editor">
- <Toolbar
- style="border-bottom: 1px solid #ccc"
- :editor="editor"
- :defaultConfig="toolbarConfig"
- :mode="mode"
- />
- <Editor
- style="height: 500px; overflow-y: hidden;"
- v-model="html"
- :defaultConfig="editorConfig"
- :mode="mode"
- @onCreated="onEditorCreated"
- />
- <div class="bottom-bar">
- <button
- class="ui-button"
- @click="onClickCancel"
- >
- {{$i18n.t('common.cancel')}}
- </button>
- <button
- class="ui-button submit"
- @click="onClickOk"
- >
- {{$i18n.t('common.ok')}}
- </button>
- </div>
- <div class="dialog" style="z-index: 2000" v-if="isShowImageSelectionWindow">
- <MaterialSelector
- :title="$i18n.t('gather.select_material')"
- @cancle="isShowImageSelectionWindow = false"
- @submit="onSubmitFromImageMaterialSelector"
- :selectableType="['image']"
- :initialMaterialType="'image'"
- :isMultiSelection="true"
- />
- </div>
- <div class="dialog" style="z-index: 2000" v-if="isShowVideoSelectionWindow">
- <MaterialSelector
- :title="$i18n.t('gather.select_material')"
- @cancle="isShowVideoSelectionWindow = false"
- @submit="onSubmitFromVideoMaterialSelector"
- :selectableType="['video']"
- :initialMaterialType="'video'"
- :isMultiSelection="true"
- />
- </div>
- </div>
- </template>
- <script>
- import Vue from 'vue'
- import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
- import MaterialSelector from "@/components/materialSelector.vue";
- export default Vue.extend({
- components: {
- Editor,
- Toolbar,
- MaterialSelector,
- },
- props: {
- initialHtml: {
- type: String,
- defaut: '',
- }
- },
- data() {
- return {
- editor: null,
- html: this.initialHtml,
- toolbarConfig: {
- },
- editorConfig: {
- placeholder: 'fdf',
- MENU_CONF: {
- uploadImage: {
- customBrowseAndUpload: (insertFn) => {
- this.isShowImageSelectionWindow = true
- this.insertFn = insertFn
- }
- },
- uploadVideo: {
- customBrowseAndUpload: (insertFn) => {
- this.isShowVideoSelectionWindow = true
- this.insertFn = insertFn
- }
- },
- },
- },
- mode: 'default', // or 'simple',
- isShowImageSelectionWindow: false,
- isShowVideoSelectionWindow: false,
- insertFn: null,
- }
- },
- methods: {
- onEditorCreated(editor) {
- this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
- },
- onClickOk() {
- this.$emit('ok', this.html)
- },
- onClickCancel() {
- this.$emit('cancel')
- },
- onSubmitFromImageMaterialSelector(selected) {
- this.isShowImageSelectionWindow = false
- for (const selectedItem of selected) {
- this.insertFn(selectedItem.icon, `[${this.$i18n.t('gather.image')}: ${selectedItem.name}]`)
- }
- },
- onSubmitFromVideoMaterialSelector(selected) {
- this.isShowVideoSelectionWindow = false
- for (const selectedItem of selected) {
- console.log(selectedItem);
- this.insertFn(selectedItem.ossPath, selectedItem.ossPath + this.$videoImgOriginalSize)
- }
- },
- },
- mounted() {
- },
- beforeDestroy() {
- const editor = this.editor
- if (editor == null) return
- editor.destroy() // 组件销毁时,及时销毁编辑器
- }
- })
- </script>
- <style src="@wangeditor/editor/dist/css/style.css"></style>
- <style lang="less" scoped>
- .rich-text-editor {
- // border: 1px solid #ccc;
- border-radius: 4px;
- overflow: hidden;
- > .bottom-bar {
- padding: 10px;
- background-color: #fff;
- border-top: 1px solid #ccc;
- display: flex;
- justify-content: flex-end;
- align-items: center;
- > button {
- margin-left: 10px;
- }
- }
- }
- </style>
|