inleft
2022-08-30 271ca6cb0ee2ff0a789bf74d1821e7891a7043bb
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
<template>
    <div id="area">
        <a-form-item>
            <a-textarea ref="targetArea" :rows="4" v-model="visitorContent" :placeholder="this.$attrs.replyHolder"
                class="OwO-textarea" />
        </a-form-item>
        <MyOwO @insertOwO="insertOwO"></MyOwO>
    </div>
</template>
 
<script>
    import MyOwO from './MyOwO.vue'
 
    export default {
        components: {
            MyOwO
        },
        props: {
            content: String
        },
        data() {
            return {
                visitorContent: '',
            }
        },
        watch: {
            visitorContent: function(newValue, oldValue) {
                // if (newValue.length > 0) {
                //     if (!this.init) {
                //         this.showTip = true;
                //         setTimeout(() => {
                //             this.showTip = false;
                //         }, 5000);
                //     }
                //     this.init = true;
                //     this.initOwO();
                // }
                this.$emit("update:content", newValue)
            },
        },
        methods: {
            insertOwO(text) {
                console.log(text);
                this.insertInputTxt(text)
            },
            insertInputTxt(insertTxt) {
                var elInput = this.$refs.targetArea.$el
                var startPos = elInput.selectionStart
                var endPos = elInput.selectionEnd
                if (startPos === undefined || endPos === undefined) return
                var txt = elInput.value
                var result = txt.substring(0, startPos) + insertTxt + txt.substring(endPos)
                elInput.value = result
                this.visitorContent = result
                elInput.focus()
                elInput.selectionStart = startPos + insertTxt.length
                elInput.selectionEnd = startPos + insertTxt.length
 
                this.$emit("update:content", this.visitorContent)
            }
        }
    }
</script>
 
<style>
 
</style>