Browse Source

富文本编辑器优化

master
xuhuajiao 3 days ago
parent
commit
0567ec32f8
  1. 1
      package.json
  2. 206
      src/components/quillEditor/index.vue
  3. 374
      src/components/quillEditor/index2.vue
  4. 296
      src/components/quillEditor/indexlast.vue
  5. 10
      src/views/inquiryMachine/content.vue

1
package.json

@ -78,6 +78,7 @@
"qrcodejs2": "^0.0.2",
"qs": "^6.10.1",
"quill": "^2.0.0-dev.3",
"quill-better-table": "^1.2.10",
"quill-image-resize-module": "^3.0.0",
"screenfull": "4.2.0",
"sm-crypto": "^0.3.2",

206
src/components/quillEditor/index.vue

@ -12,6 +12,10 @@ import Quill from 'quill'
import 'quill/dist/quill.snow.css'
import '@/assets/styles/quillEditor.css'
import QuillBetterTable from 'quill-better-table'
import 'quill-better-table/dist/quill-better-table.css'
Quill.register({ 'modules/better-table': QuillBetterTable }, true)
var fonts = [
'SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'sans-serif'
]
@ -56,6 +60,31 @@ const titleConfig = {
'ql-table-delete-column': '删除列'
}
// better-table
const betterTable = {
//
operationMenu: {
items: {
insertColumnRight: { text: '右边插入一列' },
insertColumnLeft: { text: '左边插入一列' },
insertRowUp: { text: '上边插入一行' },
insertRowDown: { text: '下边插入一行' },
mergeCells: { text: '合并单元格' },
unmergeCells: { text: '拆分单元格' },
deleteColumn: { text: '删除列' },
deleteRow: { text: '删除行' },
deleteTable: { text: '删除表格' }
},
background: {
color: '#333'
},
color: {
colors: ['green', 'red', 'yellow', 'blue', 'white', '#558ff2', '#595959', '#9fd9c5'],
text: '背景色:'
}
}
}
export default {
name: 'Editor',
props: {
@ -84,13 +113,14 @@ export default {
[{ align: [] }],
['link', 'image'],
['clean'],
[
{ table: 'TD' },
{ 'table-insert-row': 'TIR' },
{ 'table-insert-column': 'TIC' },
{ 'table-delete-row': 'TDR' },
{ 'table-delete-column': 'TDC' }
]
['table']
// [
// { table: 'TD' },
// { 'table-insert-row': 'TIR' },
// { 'table-insert-column': 'TIC' },
// { 'table-delete-row': 'TDR' },
// { 'table-delete-column': 'TDC' }
// ]
],
handlers: {
image: function(value) {
@ -135,24 +165,37 @@ export default {
this.quill.format('image', false)
}
},
table: function(val) {
this.quill.getModule('table').insertTable(2, 3)
},
'table-insert-row': function() {
this.quill.getModule('table').insertRowBelow()
},
'table-insert-column': function() {
this.quill.getModule('table').insertColumnRight()
},
'table-delete-row': function() {
this.quill.getModule('table').deleteRow()
},
'table-delete-column': function() {
this.quill.getModule('table').deleteColumn()
table: function() {
// this.quill.getModule('better-table').insertTable(3, 4)
//
if (this.quill.getModule('better-table')) {
this.quill.getModule('better-table').insertTable(3, 4)
} else {
console.error('better-table模块未正确加载')
}
}
// table: function(val) {
// this.quill.getModule('table').insertTable(2, 3)
// },
// 'table-insert-row': function() {
// this.quill.getModule('table').insertRowBelow()
// },
// 'table-insert-column': function() {
// this.quill.getModule('table').insertColumnRight()
// },
// 'table-delete-row': function() {
// this.quill.getModule('table').deleteRow()
// },
// 'table-delete-column': function() {
// this.quill.getModule('table').deleteColumn()
// }
}
},
table: true
table: false,
'better-table': betterTable,
keyboard: {
bindings: QuillBetterTable.keyboardBindings
}
},
placeholder: ''
},
@ -161,48 +204,61 @@ export default {
},
watch: {
value(newVal) {
if (newVal === this.quill.root.innerHTML) return
this.quill.setContents([])
this.quill.clipboard.dangerouslyPasteHTML(0, newVal)
// if (newVal === this.quill.root.innerHTML) return
// this.quill.setContents([])
// this.quill.clipboard.dangerouslyPasteHTML(0, newVal)
if (newVal === this.quill?.root.innerHTML) return
//
if (this.quill) {
this.quill.deleteText(0, this.quill.getLength())
this.quill.clipboard.dangerouslyPasteHTML(0, newVal || '')
}
}
},
// QuillDOM
beforeDestroy() {
this.destroyEditor()
},
mounted() {
const dom = this.$refs.editorContainer
this.quill = new Quill(dom, this.options)
this.initEditor()
// const dom = this.$refs.editorContainer
// this.quill = new Quill(dom, this.options)
if (this.value) {
this.quill.clipboard.dangerouslyPasteHTML(this.value)
}
// if (this.value) {
// this.quill.clipboard.dangerouslyPasteHTML(this.value)
// }
//
// //
// this.quill.on('text-change', () => {
// const content = this.quill.root.innerHTML
// console.log('content', content)
// // console.log('content', content)
// // this.$emit('input', content)
// // this.$emit('contentData', content)
// this.$emit('contentData', content)
// })
//
this.$el.querySelector('.ql-table-insert-row').innerHTML =
`<svg t="1591862376726" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6306" width="18" height="18"><path d="M500.8 604.779L267.307 371.392l-45.227 45.27 278.741 278.613L779.307 416.66l-45.248-45.248z" p-id="6307"></path></svg>`
// this.addQuillTitle()
},
methods: {
//
initEditor() {
const dom = this.$refs.editorContainer
if (!dom) return
this.$el.querySelector('.ql-table-insert-column').innerHTML =
`<svg t="1591862238963" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6509" width="18" height="18"><path d="M593.450667 512.128L360.064 278.613333l45.290667-45.226666 278.613333 278.762666L405.333333 790.613333l-45.226666-45.269333z" p-id="6510"></path></svg>`
this.$nextTick(() => {
this.quill = new Quill(dom, this.options)
this.$el.querySelector('.ql-table-delete-row').innerHTML =
`<svg t="1591862253524" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6632" width="18" height="18"><path d="M500.8 461.909333L267.306667 695.296l-45.226667-45.269333 278.741333-278.613334L779.306667 650.026667l-45.248 45.226666z" p-id="6633"></path></svg>`
if (this.value) {
this.quill.clipboard.dangerouslyPasteHTML(this.value)
}
this.$el.querySelector('.ql-table-delete-column').innerHTML =
`<svg t="1591862261059" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6755" width="18" height="18"><path d="M641.28 278.613333l-45.226667-45.226666-278.634666 278.762666 278.613333 278.485334 45.248-45.269334-233.365333-233.237333z" p-id="6756"></path></svg>`
this.quill.on('text-change', () => {
const content = this.quill.root.innerHTML
this.$emit('contentData', content)
})
this.addQuillTitle()
},
// activated() {
// if (this.value && this.quill) {
// this.quill.clipboard.dangerouslyPasteHTML(this.value)
// }
// },
methods: {
this.addQuillTitle()
})
},
addQuillTitle() {
const oToolBar = document.querySelector('.ql-toolbar')
const aButton = oToolBar.querySelectorAll('button')
@ -222,6 +278,35 @@ export default {
item.parentNode.title = titleConfig[item.classList[0]]
})
},
//
destroyEditor() {
if (this.quill) {
// 1.
this.quill.off('text-change')
// 2.
this.quill.deleteText(0, this.quill.getLength())
// 3. DOM
const tableModule = this.quill.getModule('better-table')
if (tableModule && tableModule.destroy) {
tableModule.destroy()
}
// 4.
const container = this.$refs.editorContainer
if (container) {
container.innerHTML = ''
}
// 5.
this.quill = null
}
// 6.
const residualMenus = document.querySelectorAll('.qlbt-operation-menu, .quill-better-table')
residualMenus.forEach(menu => menu.remove())
},
getHtmlContent() {
return this.quill.root.innerHTML
},
@ -232,5 +317,24 @@ export default {
}
</script>
<style scoped>
<style>
/* 表格列宽拖动相关样式 */
.ql-editor table {
table-layout: fixed !important;
width: 100% !important;
border-collapse: collapse;
}
.ql-editor table td,
.ql-editor table th {
border: 1px solid #ccc;
padding: 8px;
overflow: hidden;
white-space: nowrap;
}
/* 右键菜单层级 */
.qlbt-operation-menu{
z-index: 99999 !important;
}
</style>

374
src/components/quillEditor/index2.vue

@ -0,0 +1,374 @@
<template>
<div>
<div ref="editorContainer" class="editor" style="height: 450px; overflow-y: scroll;" />
</div>
</template>
<script>
import { upload } from '@/utils/upload'
import Quill from 'quill'
import 'quill/dist/quill.snow.css'
import '@/assets/styles/quillEditor.css'
import QuillBetterTable from 'quill-better-table'
import 'quill-better-table/dist/quill-better-table.css'
Quill.register({ 'modules/better-table': QuillBetterTable }, true)
//
var fonts = [
'SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'sans-serif'
]
//
var sizes = [false, '14px', '16px', '18px', '20px', '22px', '26px', '28px', '30px']
//
var Size = Quill.import('formats/size')
Size.whitelist = sizes
var Font = Quill.import('formats/font')
Font.whitelist = fonts
Quill.register(Font, true)
//
const titleConfig = {
'ql-bold': '加粗',
'ql-color': '颜色',
'ql-font': '字体',
'ql-code': '插入代码',
'ql-italic': '斜体',
'ql-link': '添加链接',
'ql-background': '背景色',
'ql-size': '字体大小',
'ql-strike': '删除线',
'ql-script': '上标/下标',
'ql-underline': '下划线',
'ql-blockquote': '引用',
'ql-header': '标题',
'ql-indent': '缩进',
'ql-list': '列表',
'ql-align': '文本对齐',
'ql-direction': '文本方向',
'ql-code-block': '代码块',
'ql-formula': '公式',
'ql-image': '图片',
'ql-video': '视频',
'ql-clean': '清除字体样式',
'ql-upload': '文件',
'ql-table': '插入表格',
'ql-table-insert-row': '插入行',
'ql-table-insert-column': '插入列',
'ql-table-delete-row': '删除行',
'ql-table-delete-column': '删除列'
}
//
const betterTable = {
operationMenu: {
items: {
insertColumnRight: { text: '右边插入一列' },
insertColumnLeft: { text: '左边插入一列' },
insertRowUp: { text: '上边插入一行' },
insertRowDown: { text: '下边插入一行' },
mergeCells: { text: '合并单元格' },
unmergeCells: { text: '拆分单元格' },
deleteColumn: { text: '删除列' },
deleteRow: { text: '删除行' },
deleteTable: { text: '删除表格' }
},
background: {
color: '#333'
},
color: {
colors: ['green', 'red', 'yellow', 'blue', 'white', '#558ff2', '#595959', '#9fd9c5'],
text: '背景色:'
}
}
}
export default {
name: 'Editor',
props: {
value: {
type: String,
default: ''
}
},
data() {
return {
quill: null,
file: null,
options: {
theme: 'snow',
modules: {
toolbar: {
container: [
['bold', 'italic', 'underline', 'strike'],
[{ header: 1 }, { header: 2 }],
[{ list: 'ordered' }, { list: 'bullet' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ color: [] }, { background: [] }],
[{ size: sizes }],
[{ font: fonts }],
[{ align: [] }],
['link', 'image'],
['clean'],
['table']
],
handlers: {
image: function(value) {
if (value) {
const input = document.createElement('input')
input.setAttribute('type', 'file')
input.setAttribute('accept', 'image/*')
input.addEventListener('change', (e) => {
const file = e.target.files[0]
if (file) {
this.file = file
//
const linkSrc = process.env.NODE_ENV === 'production' ? window.g.ApiUrl : process.env.VUE_APP_BASE_API
upload(linkSrc + '/api/fileRelevant/uploadOtherImg', this.file).then(res => {
if (res.data.code === 200) {
const imageUrl = linkSrc + '/api/fileRelevant/getImg?imgType=1&imgId=' + res.data.data
const range = this.quill.getSelection()
if (range) {
//
this.quill.insertEmbed(range.index, 'image', imageUrl)
//
this.quill.setSelection(range.index + 1)
} else {
this.quill.insertEmbed(this.quill.getLength(), 'image', imageUrl)
}
}
}).catch(err => {
console.error('上传失败:', err)
})
}
})
input.click()
} else {
this.quill.format('image', false)
}
},
table: function() {
this.quill.getModule('better-table').insertTable(3, 4)
}
}
},
table: false,
'better-table': betterTable,
keyboard: {
bindings: QuillBetterTable.keyboardBindings
}
},
placeholder: ''
},
titleConfig
}
},
watch: {
value(newVal) {
if (newVal === this.quill.root.innerHTML) return
this.quill.setContents([])
this.quill.clipboard.dangerouslyPasteHTML(0, newVal)
}
},
mounted() {
const dom = this.$refs.editorContainer
this.quill = new Quill(dom, this.options)
if (this.value) {
this.quill.clipboard.dangerouslyPasteHTML(this.value)
}
this.addQuillTitle()
//
this.initTableResize()
//
this.quill.on('text-change', (delta, oldDelta, source) => {
if (source === 'user') {
this.initTableResize()
}
})
},
methods: {
//
addQuillTitle() {
const oToolBar = document.querySelector('.ql-toolbar')
const aButton = oToolBar.querySelectorAll('button')
const aSelect = oToolBar.querySelectorAll('select')
aButton.forEach(function(item) {
if (item.className === 'ql-script') {
item.value === 'sub' ? (item.title = '下标') : (item.title = '上标')
} else if (item.className === 'ql-indent') {
item.value === '+1' ? (item.title = '向右缩进') : (item.title = '向左缩进')
} else {
item.title = titleConfig[item.classList[0]]
}
})
aSelect.forEach(function(item) {
item.parentNode.title = titleConfig[item.classList[0]]
})
},
// HTML
getHtmlContent() {
return this.quill.root.innerHTML
},
// Delta
getDeltaContent() {
return this.quill.getContents()
},
/**
* 初始化表格列宽拖动功能
*/
initTableResize() {
//
const tables = this.quill.root.querySelectorAll('.ql-editor table')
tables.forEach(table => {
// 使
table.style.tableLayout = 'fixed'
table.style.width = '100%'
// //
// const headers = table.querySelectorAll('th')
// headers.forEach((header, colIndex) => {
// //
// if (!header.querySelector('.table-resize-handle')) {
// this.addResizeHandle(header, table, colIndex)
// }
// })
// // (th)
// if (headers.length === 0) {
// const firstRowCells = table.querySelectorAll('tr:first-child td')
// firstRowCells.forEach((cell, colIndex) => {
// if (!cell.querySelector('.table-resize-handle')) {
// this.addResizeHandle(cell, table, colIndex)
// }
// })
// }
})
},
/**
* 为单元格添加拖动手柄和事件监听
* @param {HTMLElement} cell - 单元格元素
* @param {HTMLElement} table - 表格元素
* @param {number} colIndex - 列索引
*/
addResizeHandle(cell, table, colIndex) {
//
const handle = document.createElement('div')
handle.className = 'table-resize-handle'
cell.appendChild(handle)
//
let isResizing = false
let startX = 0
let startWidth = 0
// -
handle.addEventListener('mousedown', (e) => {
isResizing = true
startX = e.clientX
//
const columnCells = table.querySelectorAll(`tr td:nth-child(${colIndex + 1}), tr th:nth-child(${colIndex + 1})`)
startWidth = columnCells[0].offsetWidth
handle.classList.add('active')
//
e.stopPropagation()
e.preventDefault()
})
// -
document.addEventListener('mousemove', (e) => {
if (!isResizing) return
// 50px
const widthDiff = e.clientX - startX
const newWidth = Math.max(50, startWidth + widthDiff)
//
const columnCells = table.querySelectorAll(`tr td:nth-child(${colIndex + 1}), tr th:nth-child(${colIndex + 1})`)
columnCells.forEach(cell => {
cell.style.width = `${newWidth}px`
cell.style.minWidth = `${newWidth}px`
cell.style.maxWidth = `${newWidth}px`
})
e.stopPropagation()
e.preventDefault()
})
// -
document.addEventListener('mouseup', () => {
if (isResizing) {
isResizing = false
handle.classList.remove('active')
}
})
// -
document.addEventListener('mouseleave', () => {
if (isResizing) {
isResizing = false
handle.classList.remove('active')
}
})
}
}
}
</script>
<style>
/* 表格列宽拖动相关样式 */
.ql-editor table {
table-layout: fixed !important;
width: 100% !important;
border-collapse: collapse;
}
.ql-editor table td,
.ql-editor table th {
border: 1px solid #ccc;
padding: 8px;
overflow: hidden;
white-space: nowrap;
}
.table-resize-handle {
position: absolute;
top: 0;
right: 0;
width: 6px;
height: 100%;
cursor: col-resize;
background-color: transparent;
z-index: 10;
}
.table-resize-handle:hover,
.table-resize-handle.active {
background-color: #558ff2;
}
.ql-editor table th,
.ql-editor table tr:first-child td {
position: relative;
}
/* 右键菜单层级 */
.qlbt-operation-menu{
z-index: 99999 !important;
}
</style>

296
src/components/quillEditor/indexlast.vue

@ -0,0 +1,296 @@
<template>
<div style="width: 100%; height: 100%;">
<!-- 回显-->
<div v-if="disabled" style="width: 100%; height: 100%;" class="ql-editor" v-html="content" />
<!-- 编辑-->
<quill-editor
v-else
ref="quillEditor"
v-model="content"
:options="options"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)"
@change="onEditorChange($event)"
/>
<div v-if="!disabled" style="float:right; margin: 10px 0;">
{{ currentLength + ' / ' + max }}
</div>
</div>
</template>
<script>
import ResourcesService from '../../../util/ResourcesService'
const resourcesServer = new ResourcesService()
import { quillEditor } from 'vue-quill-editor'
import Quill from 'quill'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 2.0.0dev线
// z-indexwangEditor
// npm install quill ^2.0.0-dev.4
// npm install quill-better-table
import QuillBetterTable from 'quill-better-table'
import 'quill-better-table/dist/quill-better-table.css'
Quill.register({ 'modules/better-table': QuillBetterTable }, true)
// ,https://www.cnblogs.com/meiyanstar/p/13346355.html
const titleConfig = [
{ Choice: '.ql-bold', title: '加粗' },
{ Choice: '.ql-italic', title: '斜体' },
{ Choice: '.ql-underline', title: '下划线' },
{ Choice: '.ql-header', title: '段落格式' },
{ Choice: '.ql-strike', title: '删除线' },
{ Choice: '.ql-blockquote', title: '块引用' },
{ Choice: '.ql-code', title: '插入代码' },
{ Choice: '.ql-code-block', title: '插入代码段' },
{ Choice: '.ql-font', title: '字体' },
{ Choice: '.ql-size', title: '字体大小' },
{ Choice: '.ql-list[value="ordered"]', title: '编号列表' },
{ Choice: '.ql-list[value="bullet"]', title: '项目列表' },
{ Choice: '.ql-direction', title: '文本方向' },
{ Choice: '.ql-header[value="1"]', title: 'h1' },
{ Choice: '.ql-header[value="2"]', title: 'h2' },
{ Choice: '.ql-align', title: '对齐方式' },
{ Choice: '.ql-color', title: '字体颜色' },
{ Choice: '.ql-background', title: '背景颜色' },
{ Choice: '.ql-image', title: '图像' },
{ Choice: '.ql-video', title: '视频' },
{ Choice: '.ql-link', title: '添加链接(请先选中文字)' },
{ Choice: '.ql-formula', title: '插入公式' },
{ Choice: '.ql-clean', title: '清除字体格式' },
{ Choice: '.ql-table', title: '表格' },
{ Choice: '.ql-script[value="sub"]', title: '下标' },
{ Choice: '.ql-script[value="super"]', title: '上标' },
{ Choice: '.ql-indent[value="-1"]', title: '向左缩进' },
{ Choice: '.ql-indent[value="+1"]', title: '向右缩进' },
{ Choice: '.ql-header .ql-picker-label', title: '标题大小' },
{ Choice: '.ql-header .ql-picker-item[data-value="1"]', title: '标题一' },
{ Choice: '.ql-header .ql-picker-item[data-value="2"]', title: '标题二' },
{ Choice: '.ql-header .ql-picker-item[data-value="3"]', title: '标题三' },
{ Choice: '.ql-header .ql-picker-item[data-value="4"]', title: '标题四' },
{ Choice: '.ql-header .ql-picker-item[data-value="5"]', title: '标题五' },
{ Choice: '.ql-header .ql-picker-item[data-value="6"]', title: '标题六' },
{ Choice: '.ql-header .ql-picker-item:last-child', title: '标准' },
{ Choice: '.ql-size .ql-picker-item[data-value="small"]', title: '小号' },
{ Choice: '.ql-size .ql-picker-item[data-value="large"]', title: '大号' },
{ Choice: '.ql-size .ql-picker-item[data-value="huge"]', title: '超大号' },
{ Choice: '.ql-size .ql-picker-item:nth-child(2)', title: '标准' },
{ Choice: '.ql-align .ql-picker-item:first-child', title: '居左对齐' },
{ Choice: '.ql-align .ql-picker-item[data-value="center"]', title: '居中对齐' },
{ Choice: '.ql-align .ql-picker-item[data-value="right"]', title: '居右对齐' },
{ Choice: '.ql-align .ql-picker-item[data-value="justify"]', title: '两端对齐' }
]
// css
const fontFamily = ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'pingfang']
Quill.imports['formats/font'].whitelist = fontFamily
Quill.register(Quill.imports['formats/font'])
// css
const fontSize = ['10px', '12px', '14px', '16px', '20px', '24px', '26px', '30px', '36px']
Quill.imports['attributors/style/size'].whitelist = fontSize
Quill.register(Quill.imports['attributors/style/size'])
//
import apiUrl from '../../../api/apiUrl'
const baseURL = apiUrl.baseAddr
/* 富文本编辑图片上传配置*/
const uploadConfig = {
action: '/api/files/v1/upEdit', //
methods: 'POST', //
token: sessionStorage.getItem('token'), // tokentokensessionStorage
name: 'file', //
size: 10240, // Kb, 1M = 1024Kb
accept: 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon' //
}
// quill
const handlers = {
//
image: function image() {
var self = this
var fileInput = this.container.querySelector(
'input.ql-image[type=file]'
)
if (fileInput === null) {
fileInput = document.createElement('input')
fileInput.setAttribute('type', 'file')
//
if (uploadConfig.name) fileInput.setAttribute('name', uploadConfig.name)
//
fileInput.setAttribute('accept', uploadConfig.accept)
fileInput.classList.add('ql-image')
//
fileInput.addEventListener('change', async function() {
const res = await resourcesServer.uploadFile('med-main-svc', 'C006', 1, fileInput.files[0])
if (res.code === '0000') {
const length = self.quill.getSelection(true).index
// imgsrcres.path
const img = res.list[0]
self.quill.insertEmbed(length, 'image', baseURL + '/res-svc/res/v3/download?fileId=' + img.fileId + '&applicationName=med-main-svc&businessTypeCode=C006&free=1')
self.quill.setSelection(length + 1)
fileInput.value = ''
}
})
this.container.appendChild(fileInput)
}
fileInput.click()
},
//
table: function() {
this.quill.getModule('better-table').insertTable(3, 4)
}
}
// quill
const container = [
[{ 'font': fontFamily }], //
[{ 'size': fontSize }], //
['bold', 'italic', 'underline', 'strike'], // 线线
// ['blockquote', 'code-block'], //
// [{ 'header': 1 }, { 'header': 2 }], // 12
[{ 'list': 'ordered' }, { 'list': 'bullet' }], //
[{ 'script': 'sub' }, { 'script': 'super' }], //
[{ 'indent': '-1' }, { 'indent': '+1' }], //
// [{ 'direction': 'rtl' }], //
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], //
[{ 'color': [] }, { 'background': [] }], //
[{ 'align': [] }], //
['clean'], //
['image'], //
['table'] //
]
// better-table
const betterTable = {
//
operationMenu: {
items: {
insertColumnRight: { text: '右边插入一列' },
insertColumnLeft: { text: '左边插入一列' },
insertRowUp: { text: '上边插入一行' },
insertRowDown: { text: '下边插入一行' },
mergeCells: { text: '合并单元格' },
unmergeCells: { text: '拆分单元格' },
deleteColumn: { text: '删除列' },
deleteRow: { text: '删除行' },
deleteTable: { text: '删除表格' }
},
background: {
color: '#333'
},
color: {
colors: ['green', 'red', 'yellow', 'blue', 'white', '#558ff2', '#595959', '#9fd9c5'],
text: '背景色:'
}
}
}
export default {
// quill-editor
name: 'QuillEditorPackage',
components: { quillEditor },
props: {
//
disabled: {
type: Boolean,
default: false
},
//
max: {
type: Number || String,
default: 10000
}
},
data() {
return {
content: '',
lastContent: '', //
currentLength: '0', //
// quill
options: {
placeholder: '请在这里输入',
modules: {
toolbar: {
container: container,
handlers: handlers
},
table: false,
'better-table': betterTable,
keyboard: {
bindings: QuillBetterTable.keyboardBindings
}
},
theme: 'snow'
}
}
},
mounted() {
//
this.autotip()
},
methods: {
//
onEditorBlur(e) {
// console.log('quill', e)
},
//
onEditorFocus(e) {
// console.log('quill', e)
},
//
onEditorReady(e) {
// console.log('quill', e)
},
//
onEditorChange(e) {
const allText = e.text.replace('\n', '')
this.currentLength = allText.length
if (this.currentLength > Number(this.max)) {
this.$nextTick(() => {
this.content = this.lastContent
})
this.$message({
type: 'error',
message: '超出最大字数'
})
} else {
this.lastContent = this.content
}
},
//
backShow(content) {
if (this.disabled) {
this.content = content
return
}
// this.content this.quill.pasteHTML(newVal) is not a function
const editor = this.$refs.quillEditor.quill
const delta = editor.clipboard.convert({ html: content })
editor.setContents(delta)
this.content = content
},
autotip() {
document.getElementsByClassName('ql-editor')[0].dataset.placeholder = ''
for (const item of titleConfig) {
const tip = document.querySelector('.quill-editor ' + item.Choice)
if (!tip) continue
tip.setAttribute('title', item.title)
}
}
}
}
</script>
<style scoped lang="less">
</style>

10
src/views/inquiryMachine/content.vue

@ -80,6 +80,9 @@
<quill-editor
v-if="currentKeyColumn.type !== 4"
v-model="editorContent"
:editor-content="editorContent"
:editor-ref="editorRef"
@contentData="contentData"
/>
</el-form>
<div slot="footer" class="dialog-footer">
@ -217,6 +220,10 @@ export default {
changeEditor(val) {
this.editorContent = val
},
contentData(val) {
console.log('contentData', val)
this.editorContent = val
},
handleCover(value) {
console.log(value)
if (value) {
@ -284,10 +291,11 @@ export default {
},
//
[CRUD.HOOK.afterValidateCU](crud) {
console.log(crud.form)
crud.form.libcode = this.user.fonds.fondsNo
crud.form.topicId = this.currentKeyColumn.id
this.form.introHtml = this.editorContent
console.log(crud.form)
console.log('editorContent', this.editorContent)
return true
},
[CRUD.HOOK.afterSubmit]() {

Loading…
Cancel
Save