inleft
2022-08-16 f07ea7f9ce1e213addb9df00aec053945e909d3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<template>
    <div>
        <div class="visitInfo">
            <a-form-model ref="myForm" layout="inline" :rules="rules" :model="form" :label-col="labelCol"
                :wrapper-col="wrapperCol">
                <a-form-model-item label="昵称" prop="nickName">
                    <a-input v-model="form.nickName" placeholder="需填..">
                    </a-input>
                </a-form-model-item>
                <a-form-model-item label="邮箱" prop="eMail">
                    <a-input v-model="form.eMail" placeholder="保密项(选填)">
                    </a-input>
                </a-form-model-item>
                <a-form-model-item label="主页" prop="homePage">
                    <a-input v-model="form.homePage" placeholder="https:// or http://">
                    </a-input>
                </a-form-model-item>
                <a-form-model-item label="认证"
                    v-show="form.nickName=='inleft'||form.nickName=='笔墨'||form.nickName=='阿墨'">
                    <a-input v-model="form.authCode" autocomplete='new-password' type="password" placeholder="我的授权码">
                    </a-input>
                </a-form-model-item>
            </a-form-model>
        </div>
 
        <div class="replyMsgInfo" v-if="showReplyMsgInfo">
            <div>
                {{msgInfo.useName}}<span style="padding: 0px 3px;"> : </span>
            </div>
            <div>
                <span v-html="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>
 
                <div>
                    <a-button html-type="submit" type="primary" @click="send()" v-if="!showReplyMsgInfo"
                        :disabled="isSending || $attrs.isAllowedComment==0">
                        高低整两句
                    </a-button>
                    <a-button html-type="submit" type="primary" v-else @click="send()"
                        :disabled="isSending || $attrs.isAllowedComment==0">
                        回复Ta
                    </a-button>
                    <span class="myTip" v-if="$attrs.isAllowedComment==0">很遗憾,评论已关闭</span>
                </div>
 
                <div>
                    <a-checkbox v-model="form.isReceiveMail">
                        接收邮件回复通知
                    </a-checkbox>
                    <a-checkbox v-if="!showReplyMsgInfo" v-model="form.isSecretMsg">
                        悄悄说..<span class="myTip">(仅登录后可查看)</span>
                    </a-checkbox>
                </div>
            </div>
        </a-comment>
    </div>
 
</template>
 
<script>
    import {
        blogCommentAdd
    } 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"
 
    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'
            });
        },
        methods: {
            getMsgInfo(param) {
                this.msgInfo = param;
                this.showReplyMsgInfo = true;
                this.replyHolder = "@" + this.msgInfo.useName;
            },
            send() {
                if (this.form.nickName === "") {
                    this.$message.info("怎么称呼..")
                    return
                }
 
                if (this.form.visitorContent === "") {
                    this.$message.info("你可能需要说点什么..")
                    return
                }
 
                if (this.form.isReceiveMail && this.form.eMail == "") {
                    this.$message.info("如果是想接收通知的话,你可能需要填上一个邮箱..")
                    return
                }
 
                var res;
                this.$refs.myForm.validate(valid => {
                    if (valid) {
                        //this.$message.info("校验通过")
                        res = true;
                    } else {
                        this.$message.info("校验失败")
                        res = false;
                    }
                });
 
                if (this.form.nickName == 'inleft' || this.form.nickName == '笔墨' || this.form.nickName == '阿墨') {
                    if (this.form.authCode == null || this.form.authCode == "") {
                        this.$message.info("不要成为我,你就是真的自己..")
                        return
                    }
                }
 
 
                var articleId = this.$attrs.articleId;
                let commentType = (articleId == null || articleId == undefined) ? 1 : 2;
 
                //记录最新访客信息
                if (this.form.visitorId == 1) {
                    var today = new Date();
                    var year = today.getFullYear() + "";
                    var month = today.getMonth() + 1 + "";
                    var date = today.getDate() + "";
                    var num = "";
                    for (var i = 0; i < 4; i++) {
                        num = num + Math.floor(Math.random() * 9) + "";
                    }
                    this.form.visitorId = year + (month > 10 ? month : '0' + month) + date + num
                }
 
                localStorage.setItem(VisitorDataKey, JSON.stringify(this.form))
 
                this.isSending = true;
                blogCommentAdd({
                    parentId: this.msgInfo.parentId,
                    replyId: this.msgInfo.replyId,
                    "visitorId": this.form.visitorId,
                    "articleId": articleId,
                    "commentType": commentType,
                    "authStatus": this.form.isSecretMsg ? 2 : 1,
                    "isReceiveMail": this.form.isReceiveMail ? 1 : 0,
                    "visitorEmail": this.form.eMail,
                    "visitorHomePage": this.form.homePage,
                    "visitorNickName": this.form.nickName,
                    "commentContent": this.form.visitorContent,
                    "authCode": this.form.authCode != null && this.form.authCode != "" ? md5(this.form.authCode) :
                        ''
                }).then((res) => {
                    this.isSending = false;
                    if (res.code == 200) {
                        this.$emit("sendMsg");
                        this.$message.info("信息已送达..")
                    } else {
                        this.$notification.error({
                            message: '好像哪里不对劲..',
                            description: res.message,
                            placement: 'bottomRight'
                        });
                    }
                }).catch((error) => {
                    this.$message.error("请求失败")
                    this.isSending = false;
                })
                // setTimeout(() => {
                //     this.$message.info("发送成功")
                //     this.isSending = false;
                // }, 3000);
 
            }
        },
 
        data() {
            let tempVisitorData = localStorage.getItem(VisitorDataKey);
            let vistorData = {
                nickName: "",
                eMail: "",
                homePage: "",
                isReceiveMail: false,
                isSecretMsg: false,
                visitorContent: "",
                parentId: 0,
                replyId: 0,
                visitorId: 1,
                authCode: ''
            };
 
            if (tempVisitorData != null && tempVisitorData != undefined) {
                tempVisitorData = JSON.parse(tempVisitorData);
                vistorData.nickName = tempVisitorData.nickName;
                vistorData.eMail = tempVisitorData.eMail;
                vistorData.homePage = tempVisitorData.homePage;
                vistorData.isReceiveMail = tempVisitorData.isReceiveMail;
                vistorData.isSecretMsg = tempVisitorData.isSecretMsg;
                vistorData.visitorId = tempVisitorData.visitorId;
                vistorData.authCode = tempVisitorData.authCode;
            }
 
            return {
                isSending: false,
                replyHolder: "",
                msgInfo: {
                    useName: "",
                    userComment: "",
                    parentId: 0,
                    replyId: 0
                },
                showReplyMsgInfo: false,
                labelCol: {
                    span: 6,
                    offset: 0,
                },
                wrapperCol: {
                    span: 15,
                    offset: 0
                },
                form: vistorData,
                rules: {
                    "nickName": [{
                        message: '怎么称呼?',
                    }, {
                        trigger: 'blur',
                        max: 20,
                        message: '你的名字也太长了..'
                    }],
                    "eMail": [{
                        trigger: 'blur',
                        pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/,
                        message: '你这邮箱有问题??'
                    }, {
                        trigger: 'blur',
                        max: 50,
                        message: '邮箱不要超过50字符..'
                    }],
                    "homePage": [{
                        trigger: 'blur',
                        pattern: /^((https|http)?:\/\/)+/,
                        message: '仅支持 https:// | http://'
                    }, {
                        trigger: 'blur',
                        max: 50,
                        message: '网址不要超过50字符..'
                    }]
                },
            }
        }
    }
    
    ;(() => {
        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 {
        display: flex;
        flex-direction: column;
        border-radius: 4px;
        box-shadow: 0px 9px 10px 0 rgba(0, 0, 0, 0.24), 1px 3px 15px 0 rgba(0, 0, 0, 0.19);
        padding: 20px 25px 20px;
        margin-left: 15px;
        margin-top: 10px;
    }
 
    .OwO {
        padding: 0px 0px 20px 0px;
    }
 
    .OwO .OwO-logo {
        height: 30px;
    }
 
    .OwO .quyin,
    .OwO img {
        margin-bottom: -0.125rem;
        min-height: 3.5rem;
        height: 1em;
    }
</style>