inleft
2022-08-31 3c71cc74e6dd5f1015329c64e11e8ec1cd7a97c1
commit | author | age
271ca6 1 <template>
I 2     <div id="area">
3         <a-form-item>
4             <a-textarea ref="targetArea" :rows="4" v-model="visitorContent" :placeholder="this.$attrs.replyHolder"
5                 class="OwO-textarea" />
6         </a-form-item>
7         <MyOwO @insertOwO="insertOwO"></MyOwO>
8     </div>
9 </template>
10
11 <script>
12     import MyOwO from './MyOwO.vue'
13
14     export default {
15         components: {
16             MyOwO
17         },
18         props: {
19             content: String
20         },
21         data() {
22             return {
23                 visitorContent: '',
24             }
25         },
26         watch: {
27             visitorContent: function(newValue, oldValue) {
28                 this.$emit("update:content", newValue)
29             },
30         },
31         methods: {
32             insertOwO(text) {
33                 console.log(text);
34                 this.insertInputTxt(text)
35             },
36             insertInputTxt(insertTxt) {
37                 var elInput = this.$refs.targetArea.$el
38                 var startPos = elInput.selectionStart
39                 var endPos = elInput.selectionEnd
40                 if (startPos === undefined || endPos === undefined) return
41                 var txt = elInput.value
42                 var result = txt.substring(0, startPos) + insertTxt + txt.substring(endPos)
43                 elInput.value = result
44                 this.visitorContent = result
45                 elInput.focus()
46                 elInput.selectionStart = startPos + insertTxt.length
47                 elInput.selectionEnd = startPos + insertTxt.length
48
49                 this.$emit("update:content", this.visitorContent)
50             }
51         }
52     }
53 </script>
54
55 <style>
56
57 </style>