Commit d7ec1baf by zhangquan

修改富文本插件

1 parent a48b5f4b
This diff could not be displayed because it is too large.
......@@ -8,6 +8,8 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^1.0.2",
"core-js": "^3.4.4",
"dayjs": "^1.10.7",
"el-tree-transfer": "^2.2.6",
......@@ -17,8 +19,7 @@
"lodash": "^4.17.21",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuex": "^3.1.2",
"wangeditor": "^4.7.12"
"vuex": "^3.1.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",
......@@ -36,6 +37,7 @@
"number-precision": "^1.6.0",
"prettier": "^1.19.1",
"sass-loader": "^8.0.0",
"snabbdom": "^3.5.1",
"vue-cli-plugin-element": "^1.0.1",
"vue-quill-editor": "^3.0.6",
"vue-template-compiler": "^2.6.10"
......
export function attachmentToHtml(elem, childrenHtml) {
// JS 语法
// 获取附件元素的数据
const { key = '', name = '' } = elem
// 生成 HTML 代码
const html = `<span data-w-e-type="text" data-key="${key}" data-name="${name}">${name}</span>`
return html
}
<template>
<div>
<div :id="'div-demo' + idName"></div>
<div @click="setHtml">456456</div>
<div class="editor-ctnr">
<!-- <el-button @click="insertNode">插入元素</el-button>
<el-button @click="insertOtherNode">插入其他元素</el-button>
<el-button @click="getData">获取内容</el-button>
<el-button @click="setData">设置内容</el-button> -->
<label v-if="label" for="" :class="['content-label', { 'required-field': required }]">{{ label }}</label>
<div class="editor" style="border: 1px solid #ccc;">
<Toolbar v-if="hasTool" style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" :mode="mode" />
<Editor style="min-height: 52px; overflow-y: hidden;" @onChange="onChange" v-model="value" :defaultConfig="editorConfig" :mode="mode" @onCreated="onCreated" />
</div>
</div>
</template>
<script>
import E from 'wangeditor'
export default {
name: 'textBox',
data() {
return {
editor: '',
content: '',
editorOption: {}
}
import Vue from 'vue'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
import { Boot, DomEditor } from '@wangeditor/editor'
import { withBreakAndDelete } from './withimage'
Boot.registerPlugin(withBreakAndDelete)
import { attachmentToHtml } from './attachmentToHtml'
const elemToHtmlConf = {
type: 'text', // 新元素的 type ,重要!!!
elemToHtml: attachmentToHtml
}
Boot.registerElemToHtml(elemToHtmlConf)
import { renderAttachment } from './renderAttachment'
const renderElemConf = {
type: 'text', // 新元素 type ,重要!!!
renderElem: renderAttachment
}
Boot.registerRenderElem(renderElemConf)
import { parseAttachmentHtml } from './parseAttachmentHtml'
const parseHtmlConf = {
selector: 'span[data-w-e-type="text"]', // CSS 选择器,匹配特定的 HTML 标签
parseElemHtml: parseAttachmentHtml
}
Boot.registerParseElemHtml(parseHtmlConf)
export default Vue.extend({
components: { Editor, Toolbar },
model: {
prop: 'value',
event: 'change'
},
props: {
excludeMenus: {
type: Array,
default: () => ['code', 'video']
required: {
type: Boolean,
default: false
},
hasTool: {
type: Boolean,
default: true
},
boxHeight: {
type: Number,
default: 240
value: {
type: Object
},
idName: {
label: {
type: String,
default: ''
},
operateList: {
type: Array,
default: () => {
return (Math.random(5) * 10000).toFixed(0)
return []
}
},
disabled: {
type: Boolean,
default: false
}
},
mounted() {
this.getEdit()
data() {
return {
editor: null,
html: '',
toolbarConfig: {
toolbarKeys: ['fontSize', 'lineHeight', 'underline', 'through', 'color', 'bgColor', 'insertTable', 'undo', 'redo', 'clearStyle']
// toolbarKeys: ['fontSize', 'lineHeight', 'underline', 'through', 'color', 'bgColor', 'insertTable', 'undo', 'redo', 'clearStyle']
},
editorConfig: {
placeholder: '请输入内容...'
},
mode: 'default' // or 'simple'
}
},
methods: {
getEdit() {
const _this = this
this.editor = new E(`#div-demo${this.idName}`)
this.editor.config.uploadImgShowBase64 = true
this.editor.config.showMenuTooltips = true
this.editor.config.menuTooltipPosition = 'down'
this.editor.config.height = this.boxHeight
this.editor.config.width = 500
this.editor.config.excludeMenus = this.excludeMenus
this.editor.config.onchange = html => {
// console.log(html);
this.content = html // 绑定当前逐渐地值
this.$emit('change', this.content) // 将内容同步到父组件中
}
this.editor.config.onfocus = () => {
this.$emit('focus')
}
// 上传图片
this.editor.config.customUploadImg = function(resultFiles, insertImgFn) {
var file = resultFiles[0]
var reader = new FileReader()
// 默认1MB
const limitSize = 10
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
_this.$message.error('上传图片大小不能超过' + limitSize + 'MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
const imgFile = e.target.result
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
_this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
// console.log(res)
insertImgFn(res)
}
})
// resultFiles 是 input 中选中的文件列表
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
// 上传图片,返回结果,将图片插入到编辑器中
}
}
// 上传视频
this.editor.config.customUploadVideo = function(resultFiles, insertVideoFn) {
var file = resultFiles[0]
var reader = new FileReader()
// 默认1MB
const limitSize = 10
const isLt = file.size / 1024 / 1024 < limitSize
if (!isLt) {
_this.$message.error('上传视频大小不能超过' + limitSize + 'MB!')
return true
}
reader.readAsDataURL(file)
reader.onload = e => {
const videoFile = e.target.result
const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + videoFile.split(',')[1]
_this.$apis.common.pictureUpload({ file: base64 }).then(res => {
if (res) {
// console.log(res)
insertVideoFn(res)
}
})
// resultFiles 是 input 中选中的文件列表
// insertImgFn 是获取图片 url 后,插入到编辑器的方法
// 上传图片,返回结果,将图片插入到编辑器中
}
}
this.editor.config.onchangeTimeout = 5000
this.editor.create()
onChange(editer) {
this.$emit('change', this.editor.getHtml())
},
onCreated(editor) {
this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
},
setEdit(html) {
this.$nextTick(() => {
this.editor.txt.html(`<div contenteditable="false">456456</div>`)
})
setData() {
this.editor.setHtml(`<p>模拟 Ajax 异步设置内容 HTML<span data-w-e-type="text" data-key="#{sadasd}" data-name="张三">张三</span>`)
},
setHtml() {
this.$nextTick(() => {
console.log(this.editor)
this.editor.txt.append(`<span contenteditable="false">456456</span>`)
})
getData() {
const toolbar = DomEditor.getToolbar(this.editor)
const curToolbarConfig = toolbar.getConfig()
console.log(curToolbarConfig.toolbarKeys)
event.preventDefault()
console.log(this.editor.getHtml())
// return false
},
forbidEdit() {
// this.editor.$textElem.attr('contenteditable', false)
this.editor.disable()
insertNode() {
event.preventDefault()
// const dom = {
// // JS 语法
// type: 'text',
// name: '张三',
// key: '#{packagdasdasdiod}',
// children: [{ text: '' }]
// }
const resume = {
// JS 语法
type: 'text',
name: '张三',
key: '#{packagePeriod}',
children: [{ text: '' }]
}
this.editor.insertNode(resume)
setTimeout(() => {
this.editor.focus()
this.editor.move(1)
}, 300)
},
insertOtherNode() {
event.preventDefault()
const dom = {
// JS 语法
type: 'text',
name: '李四',
key: '#{packageP三生三世骚eriod}',
children: [{ text: '' }]
}
this.editor.insertNode(dom)
setTimeout(() => {
this.editor.focus()
this.editor.move(1)
}, 300)
}
},
mounted() {},
beforeDestroy() {
const editor = this.editor
if (editor == null) return
editor.destroy() // 组件销毁时,及时销毁编辑器
}
}
})
</script>
<style lang="scss" scoped>
#div-demo {
// margin: 16px 300px 0 0;
}
.el-form .editor {
margin-top: 20px;
}
.myQuillEditor {
background-color: #fff;
height: 200px;
}
</style>
<style>
.w-e-text-container {
z-index: 1 !important;
}
.w-e-toolbar {
z-index: 2 !important;
<style src="@wangeditor/editor/dist/css/style.css"></style>
<style scoped lang="scss">
.editor-ctnr {
width: 100%;
height: 100%;
display: flex;
.editor {
background: #fff;
}
.content-label {
flex-shrink: 0;
width: 154px;
display: inline-block;
vertical-align: top;
height: 20px;
font-weight: 400;
font-size: 14px;
color: #333333;
text-align: right;
line-height: 20px;
}
/deep/ .w-e-text-container {
p {
margin: 0;
}
}
}
</style>
export function parseAttachmentHtml(domElem, children, editor) {
const key = domElem.getAttribute('data-key') || ''
const name = domElem.getAttribute('data-name') || ''
console.log(domElem, children, editor)
// 生成“附件”元素(按照此前约定的数据结构)
const myResume = {
type: 'text',
name,
key,
children: [{ text: '' }]
}
return myResume
}
import { h } from 'snabbdom'
/**
* 渲染“附件”元素到编辑器
* @param elem 附件元素,即上文的 myResume
* @param children 元素子节点,void 元素可忽略
* @param editor 编辑器实例
* @returns vnode 节点(通过 snabbdom.js 的 h 函数生成)
*/
export function renderAttachment(elem, children, editor) {
const { name = '' } = elem
const Vnode = h(
'span',
{
props: { contentEditable: false },
style: { color: '#5f5efb' }
},
// 子节点
[name]
)
return Vnode
}
import { DomEditor } from '@wangeditor/editor'
export function withBreakAndDelete(editor) {
const { isInline, isVoid } = editor
const newEditor = editor
newEditor.isInline = elem => {
const type = DomEditor.getNodeType(elem)
if (type === 'text') return true
return isInline(elem)
}
newEditor.isVoid = elem => {
const type = DomEditor.getNodeType(elem)
if (type === 'text') return true
return isVoid(elem)
}
return newEditor // 返回 newEditor ,重要!!!
}
......@@ -4,33 +4,33 @@
<div class="main">
<div class="edit-bar">
<FoldFrame :name="item.title" v-for="item in contentList" :key="item.key">
<div v-if="item.type=='img'" class="bar-content">
<div v-if="item.key=='electronicSealUrl'" class="input-content">
<div v-if="item.type == 'img'" class="bar-content">
<div v-if="item.key == 'electronicSealUrl'" class="input-content">
<label class="required-field" for="">服务主体:</label>
<el-input size="small" type="text" v-model="contentObj.serviceSubject" ></el-input>
<el-input size="small" type="text" v-model="contentObj.serviceSubject"></el-input>
</div>
<Upload :required="true" @uploadSuccess="uploadSuccess" @delImage="delImage" class="upload" :name="item.label+':'" :attr="item.key" :url="contentObj[item.key]" :defaultStyle="{width:'208px'}"></Upload>
<Upload :required="true" @uploadSuccess="uploadSuccess" @delImage="delImage" class="upload" :name="item.label + ':'" :attr="item.key" :url="contentObj[item.key]" :defaultStyle="{ width: '208px' }"></Upload>
<span class="upload-tip">建议高度:48px</span>
</div>
<div v-if="item.type=='richText'" class="bar-content">
<div v-if="item.key=='contractIntroduce'" class="input-content">
<div v-if="item.type == 'richText'" class="bar-content">
<div v-if="item.key == 'contractIntroduce'" class="input-content">
<label class="required-field" for="">合同标题:</label>
<el-input size="small" type="text" v-model="contentObj.contractTitle"></el-input>
</div>
<Editor :required="true" :ref="item.key+'Ref'" :operateList="item.key=='useConditions' ? placeholderList : []" :label="item.label" v-model="contentObj[item.key]"></Editor>
<Editor :required="true" :ref="item.key + 'Ref'" :operateList="item.key == 'useConditions' ? placeholderList : []" :label="item.label" v-model="contentObj[item.key]"></Editor>
</div>
</FoldFrame>
</div>
<div class="footer-btn-wrap">
<el-button @click="handelCancel">取消</el-button>
<el-button type="primary" @click="commitTemplate('preview')">预览</el-button>
<el-button type="primary" @click="commitTemplate">提交</el-button>
</div>
<el-button @click="handelCancel">取消</el-button>
<el-button type="primary" @click="commitTemplate('preview')">预览</el-button>
<el-button type="primary" @click="commitTemplate">提交</el-button>
</div>
</div>
<pdf-dialog :isVisible="isPdfVisible" title="合同" :pdfUrl="pdfUrl" @closeDialog="handlePdfClose"></pdf-dialog>
</div>
</template>
<script>
const errorTipObj = {
contractTitle: '合同标题',
......@@ -49,7 +49,7 @@ import Editor from '@/components/Editor'
import pdfDialog from '@/views/beforeSale/pdfDialog'
export default {
name: 'AddTmpl',
components:{
components: {
Editor,
Upload,
FoldFrame,
......@@ -60,7 +60,7 @@ export default {
isPdfVisible: false,
pdfUrl: '',
placeholderList: [],
pdfObj :{
pdfObj: {
merchantId: '',
packageCode: ''
},
......@@ -138,13 +138,12 @@ export default {
label: '电子章图片',
key: 'electronicSealUrl',
type: 'img'
},
}
]
}
},
created(){
},
created() {},
mounted() {
this.getContractDetail()
......@@ -152,49 +151,55 @@ export default {
methods: {
getContractDetail() {
this.$apis.contractManager.getContractDetailApi({id: this.$route.params.id}).then(res => {
if(res && res.templateConfig){
this.$apis.contractManager.getContractDetailApi({ id: this.$route.params.id }).then(res => {
if (res && res.templateConfig) {
this.placeholderList = res.placeholderList
for(const key in this.contentObj){
this.contentObj[key] = res.templateConfig[key]
for (const key in this.contentObj) {
if (key != 'useConditions') {
this.contentObj[key] = res.templateConfig[key]
} else {
for (var i = 0; i < res.placeholderList.length; i++) {
var placeholder = res.placeholderList[i]
let targetStr = `<span data-w-e-type="text" data-key="${placeholder.key}" data-name="${placeholder.name}">${placeholder.name}</span>`
res.templateConfig.useConditions = res.templateConfig.useConditions.replace(new RegExp(placeholder.key, 'g'), targetStr)
}
this.contentObj.useConditions = res.templateConfig.useConditions
}
}
this.pdfObj = {
this.pdfObj = {
merchantId: res.templateConfig.merchantId,
packageCode: res.templateConfig.packageCode
},
this.$nextTick(()=>{
this.$refs.useConditionsRef[0].replaceText()
})
}
}
})
},
handelCancel(){
handelCancel() {
this.$router.push('/ContractManager/index')
},
getParams(){
getParams() {
let params = this.$common.utils.deepClone(this.contentObj)
let errorTip = '';
params.useConditions = params.useConditions?.replace(/<span.*?class.*?keyname="(.*?)".*?<\/span>/g,'$1')
for(const key in params){
if(key!='id' && !params[key]){
if(key == 'electronicSealUrl' || key == 'logoUrl'){
errorTip = `请上传${key == 'logoUrl' ? 'Logo图': '电子章图片'}`
}else{
let errorTip = ''
params.useConditions = params.useConditions?.replace(/<span.*?data-w-e-type.*?data-key="(.*?)".*?<\/span>/g, '$1')
for (const key in params) {
if (key != 'id' && !params[key]) {
if (key == 'electronicSealUrl' || key == 'logoUrl') {
errorTip = `请上传${key == 'logoUrl' ? 'Logo图' : '电子章图片'}`
} else {
errorTip = `${errorTipObj[key]}不能为空`
}
}
}
if(errorTip) return {status: -1, errorTip}
if (errorTip) return { status: -1, errorTip }
return params
},
commitTemplate(type){
commitTemplate(type) {
const params = this.getParams()
if(params.status == -1) return this.$message.error(params.errorTip)
this.$apis.contractManager.saveContractTemplateApi({...params}).then(res => {
if(res){
if(type=='preview'){
if (params.status == -1) return this.$message.error(params.errorTip)
this.$apis.contractManager.saveContractTemplateApi({ ...params }).then(res => {
if (res) {
if (type == 'preview') {
this.handlePdf()
}else{
} else {
this.$message.success('编辑成功')
this.$router.push('/ContractManager/index')
}
......@@ -211,27 +216,27 @@ export default {
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.3)'
})
this.$apis.contractManager.printContractApi({ packageCode : this.pdfObj.packageCode , merchantId: this.pdfObj.merchantId }).then(res => {
this.$apis.contractManager.printContractApi({ packageCode: this.pdfObj.packageCode, merchantId: this.pdfObj.merchantId }).then(res => {
this.pdfUrl = res
this.handlePdfClose()
loading.close()
})
},
uploadSuccess(e){
uploadSuccess(e) {
this.contentObj[e.attr] = e.url
},
delImage(e){
delImage(e) {
this.contentObj[e.attr] = ''
},
}
}
}
</script>
<style lang="scss" scoped>
.container{
.container {
background-color: #fff;
margin-bottom: 60px;
.footer-btn-wrap{
.footer-btn-wrap {
width: 100%;
height: 60px;
line-height: 60px;
......@@ -243,15 +248,15 @@ export default {
right: 0;
box-shadow: 0 -2px 10px 0 #7a7a7a33;
}
.footer-btn{
.footer-btn {
text-align: center;
margin-top: 16px;
}
.input-content{
.input-content {
display: flex;
align-items: center;
margin-bottom: 24px;
label{
label {
flex-shrink: 0;
width: 154px;
white-space: nowrap;
......@@ -260,24 +265,24 @@ export default {
font-size: 14px;
color: #333333;
}
/deep/ .el-input__inner{
/deep/ .el-input__inner {
width: 342px;
}
}
.main{
.main {
padding: 10px 20px 32px;
.edit-bar{
.bar-content{
background: #F9F9F9;
.edit-bar {
.bar-content {
background: #f9f9f9;
padding: 20px;
margin-bottom: 10px;
/deep/ .editor{
width: 935px!important;
/deep/ .editor {
width: 935px !important;
}
.upload{
.upload {
display: inline-block;
}
.upload-tip{
.upload-tip {
height: 20px;
font-weight: 400;
font-size: 14px;
......@@ -290,4 +295,3 @@ export default {
}
}
</style>
\ No newline at end of file
......@@ -8,6 +8,7 @@
<!-- <el-button size="small" @click="toggleAll">全选</el-button> -->
<!-- <el-checkbox v-model="checkbox" @change="toggleAll" style="margin-left:20px">全选</el-checkbox> -->
<div style="float: right;" class="primary_plain_btn">
<el-button size="small" plain @click="batchOpenSale()">批量开通驻店销售</el-button>
<el-button size="small" plain @click="batchOperation(1)">批量开通</el-button>
<el-button size="small" @click="batchOperation(2)">批量关闭</el-button>
<el-button size="small" @click="exportTable">导出</el-button>
......@@ -259,6 +260,11 @@ export default {
this.searchForm[this.searchSelectObj.idOrName.attr] = this.searchSelectObj.idOrName.value
this.$refs.table.refreshTable()
},
batchOpenSale(){
const data = this.$refs.table?.mutiSelectArr?.[this.tableParams.mutiSelectName] || []
const ids = data.map(item => item.id)
console.log(ids)
},
// ['开通', '关闭'] //
batchOperation(status) {
let { configIndexMutiTable } = this.$refs.table.$refs
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!