From c14e3278893b9dd1022aa488cee53a888c2a4c7e Mon Sep 17 00:00:00 2001
From: inleft <inleft@qq.com>
Date: Tue, 16 Aug 2022 19:34:48 +0800
Subject: [PATCH] 表情组件优化

---
 src/components/mini/box13-reply.vue |  202 ++++++--------------------------------------------
 1 files changed, 25 insertions(+), 177 deletions(-)

diff --git a/src/components/mini/box13-reply.vue b/src/components/mini/box13-reply.vue
index 23e3380..7809b0b 100644
--- a/src/components/mini/box13-reply.vue
+++ b/src/components/mini/box13-reply.vue
@@ -28,17 +28,12 @@
 				{{msgInfo.useName}}<span style="padding: 0px 3px;"> : </span>
 			</div>
 			<div>
-				<span v-html="msgInfo.userComment.replace(/\n/g, '<br>')"></span>
+				<span v-html="parseContent(msgInfo.userComment).replace(/\n/g, '<br>')"></span>
 			</div>
 		</div>
 		<a-comment>
 			<div slot="content">
-				<a-form-item>
-					<a-textarea :rows="4" v-model="form.visitorContent" :placeholder="replyHolder"
-						class="OwO-textarea" />
-				</a-form-item>
-				<div class="OwO"></div>
-
+				<MyOwO :content.sync="form.visitorContent" :replyHolder="replyHolder"></MyOwO>
 				<div>
 					<a-button html-type="submit" type="primary" @click="send()" v-if="!showReplyMsgInfo"
 						:disabled="isSending || $attrs.isAllowedComment==0">
@@ -71,27 +66,23 @@
 	} from '../../api/blogArticleComment.js'
 	import md5 from 'js-md5';
 
-	import 'owo/dist/OwO.min.css';
-	// import OwO from 'owo/dist/OwO.min.js';
-	// import OwO from '/public/OWO.js';
-
-
-	const VisitorDataKey = "visitorData.inleft.com"
+	import MyOwO from '../common/OwO.vue'
+	import myConstant from "../../config/myConstant.js"
 
 	export default {
-		mounted() {
-			var OwO_demo = new OwO({
-				logo: 'OωO表情',
-				container: document.getElementsByClassName('OwO')[0],
-				target: document.getElementsByClassName('OwO-textarea')[0],
-				api: './OwO.json',
-				// api: 'http://diygod.github.io/OwO/demo/OwO.json',
-				position: 'down',
-				width: '100%',
-				maxHeight: '250px'
-			});
+		components: {
+			MyOwO
+		},
+		props: {
+			parseContent: {
+				type: Function,
+				default: null
+			}
 		},
 		methods: {
+			// getTargetArea() {
+			// 	return this.$refs.targetArea;
+			// },
 			getMsgInfo(param) {
 				this.msgInfo = param;
 				this.showReplyMsgInfo = true;
@@ -126,7 +117,7 @@
 
 				if (this.form.nickName == 'inleft' || this.form.nickName == '笔墨' || this.form.nickName == '阿墨') {
 					if (this.form.authCode == null || this.form.authCode == "") {
-						this.$message.info("不要成为我,你就是真的自己..")
+						this.$message.info("此名称在这里使用需要正确的授权码..")
 						return
 					}
 				}
@@ -148,7 +139,7 @@
 					this.form.visitorId = year + (month > 10 ? month : '0' + month) + date + num
 				}
 
-				localStorage.setItem(VisitorDataKey, JSON.stringify(this.form))
+				localStorage.setItem(this.VisitorDataKey, JSON.stringify(this.form))
 
 				this.isSending = true;
 				blogCommentAdd({
@@ -190,7 +181,7 @@
 		},
 
 		data() {
-			let tempVisitorData = localStorage.getItem(VisitorDataKey);
+			let tempVisitorData = localStorage.getItem(this.VisitorDataKey);
 			let vistorData = {
 				nickName: "",
 				eMail: "",
@@ -216,6 +207,7 @@
 			}
 
 			return {
+				VisitorDataKey: myConstant.VisitorDataKey,
 				isSending: false,
 				replyHolder: "",
 				msgInfo: {
@@ -264,159 +256,15 @@
 			}
 		}
 	}
-	
-	;(() => {
-	    class OwO {
-	        constructor(option) {
-	            const defaultOption = {
-	                container: document.getElementsByClassName('OwO')[0],
-	                target: document.getElementsByTagName('textarea')[0],
-	                position: 'down',
-	                width: '100%',
-	                maxHeight: '250px',
-	                api: 'https://api.anotherhome.net/OwO/OwO.json'
-	            }
-	            for (let defaultKey in defaultOption) {
-	                if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
-	                    option[defaultKey] = defaultOption[defaultKey]
-	                }
-	            }
-	            this.container = option.container
-	            this.target = option.target
-	            if (option.position === 'up') {
-	                this.container.classList.add('OwO-up')
-	            }
-	            const xhr = new XMLHttpRequest()
-	            xhr.onreadystatechange = () => {
-	                if (xhr.readyState === 4) {
-	                    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
-	                        this.odata = JSON.parse(xhr.responseText)
-	                        this.init(option)
-	                    } else {
-	                        console.log('OwO data request was unsuccessful: ' + xhr.status)
-	                    }
-	                }
-	            }
-	            xhr.open('get', option.api, true)
-	            xhr.send(null)
-	        }
-	
-	        init(option) {
-	            this.area = option.target
-	            this.packages = Object.keys(this.odata)
-	
-	            // fill in HTML
-	            let html = `
-	            <div class="OwO-logo"><span>OωO</span></div>
-	            <div class="OwO-body" style="width: ${option.width}"><div class="OwO-jio"></div>`
-	
-	            for (let i = 0; i < this.packages.length; i++) {
-	                html += `
-	                <ul class="OwO-items OwO-items-${this.odata[this.packages[i]].type}" style="max-height: ${parseInt(option.maxHeight) - 53 + 'px'};">`
-	                var type = this.odata[this.packages[i]].type
-	                let opackage = this.odata[this.packages[i]].container
-	                for (let i = 0; i < opackage.length; i++) {
-	                    if (type == 'image') {
-	                        html += `
-	                    <li class="OwO-item" data-id="${opackage[i].data}" title="${opackage[i].text}"><img class="biaoqing ${opackage[i].css}" src="${opackage[i].icon}"></li>`
-	                    } else {
-	                        html += `
-	                    <li class="OwO-item" data-id="not-given" title="${opackage[i].text}">${opackage[i].icon}</li>`
-	                    } 
-	                }
-	
-	                html += `
-	                </ul>`
-	            }
-	
-	            html += `
-	                <div class="OwO-bar">
-	                    <ul class="OwO-packages">`
-	
-	            for (let i = 0; i < this.packages.length; i++) {
-	                html += `
-	                        <li><span>${this.packages[i]}</span></li>`
-	            }
-	
-	            html += `
-	                    </ul>
-	                </div>
-	            </div>
-	            `
-	            this.container.innerHTML = html
-	
-	            // bind event
-	            this.logo = document.getElementsByClassName('OwO-logo')[0]
-	            this.logo.addEventListener('click', e => {
-	                e.stopPropagation()
-	                this.toggle()
-	            })
-	
-	            this.container.getElementsByClassName('OwO-body')[0].addEventListener('click', e => {
-	                let target = null
-	                if (e.target.classList.contains('OwO-item')) {
-	                    target = e.target
-	                } else if (e.target.parentNode.classList.contains('OwO-item')) {
-	                    target = e.target.parentNode
-	                }
-	                if (target) {
-	                    const cursorPos = this.area.selectionEnd
-	                    let areaValue = this.area.value
-	                    //this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos);
-	                    if (target.dataset.id == 'not-given') {
-	                        this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos)
-	                    } else {
-	                        this.area.value = areaValue.slice(0, cursorPos) + target.dataset.id + areaValue.slice(cursorPos)
-	                    }
-	                    this.area.focus()
-	                    this.toggle()
-	                }
-	            })
-	            this.packagesEle = this.container.getElementsByClassName('OwO-packages')[0]
-	            for (let i = 0; i < this.packagesEle.children.length; i++) {
-	                ;(index => {
-	                    this.packagesEle.children[i].addEventListener('click', e => {
-	                        e.stopPropagation()
-	                        this.tab(index)
-	                    })
-	                })(i)
-	            }
-	            this.tab(0)
-	        }
-	
-	        toggle() {
-	            if (this.container.classList.contains('OwO-open')) {
-	                this.container.classList.remove('OwO-open')
-	            } else {
-	                this.container.classList.add('OwO-open')
-	            }
-	        }
-	
-	        tab(index) {
-	            const itemsShow = this.container.getElementsByClassName('OwO-items-show')[0]
-	            if (itemsShow) {
-	                itemsShow.classList.remove('OwO-items-show')
-	            }
-	            this.container.getElementsByClassName('OwO-items')[index].classList.add('OwO-items-show')
-	
-	            const packageActive = this.container.getElementsByClassName('OwO-package-active')[0]
-	            if (packageActive) {
-	                packageActive.classList.remove('OwO-package-active')
-	            }
-	            this.packagesEle.getElementsByTagName('li')[index].classList.add('OwO-package-active')
-	        }
-	    }
-	
-	    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
-	        module.exports = OwO
-	    } else {
-	        window.OwO = OwO
-	    }
-	})()
-	
 </script>
 
 <style lang="less">
+	.replyMsgInfo img {
+		margin-bottom: -0.125rem;
+		img min-height: 3.5rem;
+		height: 2em;
+	}
+
 	.replyMsgInfo {
 		display: flex;
 		flex-direction: column;

--
Gitblit v1.9.1