Commit fd7a537b by 杨明

fixed

1 parent b27cddad
......@@ -141,17 +141,20 @@
</div>
</template>
</div>
<div class="btn-group">
<div class="add-btn" v-for="item in btnList" :key="item.type">
<!-- <i class="el-icon-circle-plus-outline"></i> -->
<img :src="require(`../../../assets/welcomeWord/add-${checkedType(item.type)}.png`)" alt v-if="item.type == 'expression'" @click="selectEmotion" />
<img :src="require(`../../../assets/welcomeWord/add-${checkedType(item.type)}.png`)" v-else alt />
<span v-if="item.type == 'expression'" @click.stop="selectEmotion">{{ item.name }}</span>
<span v-else>{{ item.name }}</span>
<input v-if="item.type == 'img'" type="file" style="opacity: 0" :id="item.type + 'file'" ref="file" class="welcome-input upload-img" :accept="item.accept || 'image/png, image/jpeg, image/jpg'" @change="e => handleImgChange(e)" />
<input v-else-if="item.type == 'video'" type="file" style="opacity: 0" :id="item.type + 'file'" ref="file" class="welcome-input" :accept="item.accept || 'video/*'" @change="e => handleVideoChange(e)" />
<el-link v-else-if="item.type == 'link' || item.type == 'nickname' || item.type == 'message' || item.type == 'activity' || item.type == 'material'" style="opacity: 0" @click="handleFun(item.type)">{{ item.name }}</el-link>
<div class="btn-group-panel">
<div class="btn-group">
<div class="add-btn" v-for="item in btnList" :key="item.type">
<!-- <i class="el-icon-circle-plus-outline"></i> -->
<img class="emotion-item" :src="require(`../../../assets/welcomeWord/add-${checkedType(item.type)}.png`)" alt v-if="item.type == 'expression'" @click="selectEmotion" />
<img :src="require(`../../../assets/welcomeWord/add-${checkedType(item.type)}.png`)" v-else alt />
<span class="emotion-item" v-if="item.type == 'expression'" @click.stop="selectEmotion">{{ item.name }}</span>
<span v-else>{{ item.name }}</span>
<input v-if="item.type == 'img'" type="file" style="opacity: 0" :id="item.type + 'file'" ref="file" class="welcome-input upload-img" :accept="item.accept || 'image/png, image/jpeg, image/jpg'" @change="e => handleImgChange(e)" />
<input v-else-if="item.type == 'video'" type="file" style="opacity: 0" :id="item.type + 'file'" ref="file" class="welcome-input" :accept="item.accept || 'video/*'" @change="e => handleVideoChange(e)" />
<el-link v-else-if="item.type != 'video' && item.type != 'img' && item.type != 'expression'" style="opacity: 0" @click="handleFun(item)">{{ item.name }}</el-link>
</div>
</div>
<div class="text-num">{{ textNum }}/{{ maxNum }}</div>
</div>
</div>
<div v-show="emotionStatus" class="emotion-panel">
......@@ -179,7 +182,7 @@ const ATT_TYPE = {
ACTIVITY: 7,
MATERIAL: 10
}
const wordType = ['expression', 'img', 'video', 'nickname', 'activity', 'material', 'message', 'link']
const wordType = ['expression', 'img', 'video', 'nickname', 'activity', 'material', 'message', 'link', 'code']
import emoji from '../../../utils/emo'
import ActivityModel from './activityModel'
import MessageModel from './messageModel'
......@@ -212,6 +215,8 @@ export default {
},
data() {
return {
textNum: 0,
maxNum: 600,
myArr: [{ name: 888 }, { name: 888 }],
dialogVisibleImg: false,
dialogSrc: '',
......@@ -229,7 +234,12 @@ export default {
}
},
mounted() {
console.log(vuedraggable)
document.addEventListener('click', e => {
console.log(e.target.className)
if (e.target.className != 'emotion-item') {
this.emotionStatus = false
}
})
},
computed: {
activityList() {
......@@ -426,9 +436,12 @@ export default {
}
})
},
handleFun(name) {
handleFun(type) {
const name = type.type
if (name == 'nickname') {
this.$refs.textContent.addTag('@昵称')
} else if (name == 'code') {
this.$refs.textContent.addTag('#兑换码')
} else if (name == 'activity') {
this.$refs.activity.init()
} else if (name == 'message') {
......@@ -444,6 +457,12 @@ export default {
},
textInput(val) {
val = val.replace(/&nbsp;/g, '')
this.textNum = val.replace(/(\[.*?\]|\n|\s)/g, '').length
if (this.textNum > this.maxNum) {
this.textNum = this.maxNum
this.updateList(this.previewList, 1)
return
}
const hasText = this.previewList.some(item => item.attType == this.ATT_TYPE.TEXT)
if (hasText) {
this.$set(this.previewList, 0, {
......@@ -508,15 +527,20 @@ export default {
})
})
}
console.log(html)
const idx = this.previewList.findIndex(item => item.attType == this.ATT_TYPE.TEXT)
if (idx !== -1) {
if (!this.previewList[idx].attContent) {
html = html.replace('\n', '').replace(/<br\/>/g, '')
}
html = html.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>')
let textLen = this.previewList[idx].attContent + html
if (textLen.replace(/(\n|\s)/g, '').length > this.maxNum) {
textLen = this.previewList[idx].attContent
} else {
this.textNum = textLen.replace(/(\n|\s)/g, '').length
}
this.$set(this.previewList, 0, {
attContent: (this.previewList[idx].attContent + html).substring(0, 600),
attContent: textLen,
attType: this.ATT_TYPE.TEXT
})
} else {
......@@ -526,8 +550,14 @@ export default {
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
let textLen = html
if (textLen.replace(/(\n|\s)/g, '').length > this.maxNum) {
textLen = ''
} else {
this.textNum = textLen.replace(/(\n|\s)/g, '').length
}
this.previewList.unshift({
attContent: html.substring(0, 600),
attContent: textLen,
attType: this.ATT_TYPE.TEXT
})
}
......@@ -538,34 +568,6 @@ export default {
this.updateText(content)
this.textValue = content
},
insertHtmlAtCaret(html) {
var sel, range, frag
if (window.getSelection) {
sel = window.getSelection()
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0)
range.deleteContents()
var el = document.createElement('span')
el.innerHTML = '<span contenteditable="false" class="nickname">@昵称<i class="el-icon-error"></i></span>'
// var el = document.createElement('div')
// el.innerHTML = html
frag = document.createDocumentFragment()
var node
var lastNode
while ((node = el.firstChild)) {
lastNode = frag.appendChild(node)
}
range.insertNode(frag)
if (lastNode) {
range = range.cloneRange()
range.setEndAfter(lastNode)
range.collapse(true)
sel.removeAllRanges()
sel.addRange(range)
}
}
}
},
changeInput: utils.debounce(function () {
var allNodes = document.getElementById('editor').childNodes
var str = ''
......@@ -580,14 +582,17 @@ export default {
}, 300),
updateList(val, status) {
this.previewList = utils.deepClone(val)
// this.eventBus.$emit('update', this.previewList)
const obj = val.find(item => item.attType == this.ATT_TYPE.TEXT)
if (obj) {
let attContent
if (status) {
attContent = obj.attContent.replace(/@昵称/g, '<wise id="1" contenteditable="false">@昵称</wise>')
attContent = obj.attContent.replace(/(@昵称|#兑换码)/g, '<wise id="1" contenteditable="false">$1</wise>')
} else {
attContent = obj.attContent.replace(/\[@昵称\]/g, '<wise id="1" contenteditable="false">@昵称</wise>')
this.textNum = obj.attContent
.replace(/(\n|\s)/g, '')
.replace(/\[(@昵称|#兑换码)\]/g, '$1')
.replace(/\[[\u4E00-\u9FA56]{1,4}]/g, '').length
attContent = obj.attContent.replace(/\[(@昵称|#兑换码)\]/g, '<wise id="1" contenteditable="false">$1</wise>')
}
let htm = attContent.replace(/\[[\u4E00-\u9FA56]{1,4}]/gi, function (res) {
let word = res.replace(/\[|\]/gi, '')
......@@ -807,44 +812,52 @@ export default {
margin-bottom: 0;
}
}
.btn-group {
.btn-group-panel {
display: flex;
justify-content: space-between;
padding: 10px 0 10px 20px;
border: 1px solid #e5e5e5;
border-top: 0;
background: #fafbfe;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
.add-btn {
display: inline-flex;
position: relative;
align-items: center;
padding-right: 25px;
font-size: 16px;
color: #666;
cursor: pointer;
span {
font-size: 14px;
margin-left: 5px;
cursor: pointer;
}
input {
position: absolute;
width: 100%;
cursor: pointer;
font-size: 0;
height: 40px;
}
img {
width: 16px;
height: 16px;
.btn-group {
.add-btn {
display: inline-flex;
position: relative;
align-items: center;
padding-right: 25px;
font-size: 16px;
color: #666;
cursor: pointer;
}
.el-link {
position: absolute;
width: 100%;
span {
font-size: 14px;
margin-left: 5px;
cursor: pointer;
}
input {
position: absolute;
width: 100%;
cursor: pointer;
font-size: 0;
height: 40px;
}
img {
width: 16px;
height: 16px;
cursor: pointer;
}
.el-link {
position: absolute;
width: 100%;
}
}
}
.text-num {
padding-right: 10px;
}
}
.date-picker {
margin-top: 10px;
font-size: 14px;
......
......@@ -127,7 +127,7 @@ export default {
this.selectItem = item
},
getimgsrc(htmlstr) {
var reg = /<img.+?src=('|")?([^'"]+)('|")?(?:\s+|>)/gim
var reg = /<img.+?src=('|")?([^'"]+)('|")?(?:\s+|\/?>)/gim
var arr = []
var tem
while ((tem = reg.exec(htmlstr))) {
......
<template>
<div class="w-textarea" ref="wTextarea" v-bind="$attr">
<div contenteditable="true" class="w-textarea_input" ref="wTextareaContent" :id="contentId" @keydown="textareaKeydown($event)" @click="inputClick($event)" @focus="onFocus" @blur="onBlur" @keydown.delete="handleDelete($event)" @input="handleInput($event.target)"></div>
<!-- <div class="w-textarea_tools" v-if="tools.length > 0 || maxlength">
<button
class="w-textarea_tools__item"
v-for="item in tools"
:key="item.type"
@click="openTagDialog(item.type)"
>{{item.text}}</button>
<span
:class="['w-textarea_tools__text',
count.num < 0 ? '__danger' : '']"
v-if="maxlength"
>{{count.text}}</span>
</div>-->
<!-- <div class="w-textarea_dialog">
<slot></slot>
</div>-->
</div>
</template>
......@@ -187,30 +171,6 @@ export default {
}, num * 100)
})
},
addContent(attContent) {
attContent.forEach(async (item, index) => {
await this.promiseAdd(item, index)
this.addTag('@昵称')
// await this.promiseAddNode(item, index)
// this.addNode()
// t2(item)
})
// for (let i = 0; i < attContent.length; i++) {
// if (attContent[i] || (i == 0 && !attContent[i])) {
// document.querySelector('.w-textarea_input').innerHTML += attContent[i]
// document.querySelector('.w-textarea_input').focus()
// document.querySelector('.w-textarea_input').click()
// this.$nextTick(()=>{
// this.addTag('@昵称')
// })
// }
// // 代码格式
// // (function(a) {})(b)
// }
},
addLink(text, url) {
// 创建a标签
let node = document.createElement('a')
......@@ -250,7 +210,7 @@ export default {
const list = emoji.flat(Infinity)
const cutImg = htm
.replace(/<img src="https:\/\/img01.glsx.com.cn\/weapp\/resource\/saas\/scrm\/emoji\//g, '')
.replace(/<wise.+?(?:<\/wise>)/g, '@昵称')
.replace(/<wise.+?>(.+?)(?:<\/wise>)/g, '$1')
.replace(/<br>/g, '\n')
const replaceImg = cutImg.replace(/(\d){3}.png">/g, function (str) {
let s = list[parseInt(str.split('.')[0]) - 1]
......@@ -258,7 +218,7 @@ export default {
})
let Textnode = document.createElement('div')
Textnode.innerHTML = replaceImg
this.currentText = replaceImg.substring(0, 600)
this.currentText = replaceImg
this.$emit('updateText', this.currentText)
},
insertNodeFirst(node) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!