|
@@ -1,21 +1,35 @@
|
|
|
<!-- -->
|
|
|
<template>
|
|
|
- <div class="write-box" id="container">
|
|
|
- <div @click="onConfirm">确定</div>
|
|
|
- <!-- -->
|
|
|
- <div class="content" :style="`height:${inputHeight}px;`">
|
|
|
- <!-- <div contenteditable v-html="text" :style="`height:${lineCount * 40}px;`" @keydown="hanlderWrite($event)" id="write-info"></div> -->
|
|
|
- <textarea :style="`height:${lineCount * 40}px;`" @keydown="hanlderWrite($event)" id="write-info" v-model="text"> </textarea>
|
|
|
- <div id="msg" class="msg-box">{{ text }}</div>
|
|
|
- <div class="item" :style="`top:${index * 40}px;`" v-for="(i, index) in lineCount"></div>
|
|
|
+ <div class="warpper">
|
|
|
+ <div class="write-box" id="container">
|
|
|
+ <div @click="onConfirm">确定</div>
|
|
|
+ <!-- -->
|
|
|
+ <div class="content" id="content" :style="`height:${inputHeight}px;`">
|
|
|
+ <!-- <div contenteditable v-html="text" :style="`height:${lineCount * 40}px;`" @keydown="hanlderWrite($event)" id="write-info"></div> -->
|
|
|
+ <textarea maxLength="1000" :style="`height:${lineCount * 40}px;`" @paste="onPaste" @keydown="hanlderWrite($event)" id="write-info" v-model="inputText"> </textarea>
|
|
|
+ <div id="msg" class="msg-box">{{ inputText }}</div>
|
|
|
+ <div class="item" :style="`top:${index * 40}px;`" v-for="(i, index) in lineCount"></div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { reactive, ref, toRefs, onBeforeMount, onMounted, nextTick, defineEmits } from 'vue';
|
|
|
-const emits = defineEmits(['onConfirm']);
|
|
|
-const text = ref('');
|
|
|
+import { reactive, ref, toRefs, onBeforeMount, computed, onMounted, nextTick, defineEmits, defineProps } from 'vue';
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ text: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
+ textIndex: {
|
|
|
+ type: Number,
|
|
|
+ default: 0,
|
|
|
+ },
|
|
|
+
|
|
|
+});
|
|
|
+const emits = defineEmits(['onTextConfirm', 'onTextChange']);
|
|
|
+const inputText = ref('');
|
|
|
const lineCount = ref(1);
|
|
|
const inputHeight = ref(0);
|
|
|
const getLineCount = () => {
|
|
@@ -26,18 +40,26 @@ const getLineCount = () => {
|
|
|
// textAreaHeight.value = lineCount.value * 40;
|
|
|
};
|
|
|
const onConfirm = () => {
|
|
|
- emits('onConfirm', { text: text.value });
|
|
|
+ let page = 1;
|
|
|
+
|
|
|
+ if (msgHeight.value < 400) {
|
|
|
+ page = 1;
|
|
|
+ } else {
|
|
|
+ page = page + Math.ceil((msgHeight.value - 400) / 1080);
|
|
|
+ }
|
|
|
+ console.log(page);
|
|
|
+ emits('onTextConfirm', { text: inputText.value, msgHeight: msgHeight.value, page });
|
|
|
};
|
|
|
-const textAreaHeight = ref(40);
|
|
|
+const msgHeight = ref(40);
|
|
|
const hanlderWrite = (e) => {
|
|
|
let msgH = document.getElementById('msg').clientHeight;
|
|
|
+ msgHeight.value = msgH;
|
|
|
let msgCount = Math.floor(msgH / 40);
|
|
|
let containerH = document.getElementById('container').clientHeight;
|
|
|
let containerCount = Math.floor(containerH / 40);
|
|
|
// text.value = e.target.innerHTML;
|
|
|
- console.log(msgCount > containerCount);
|
|
|
if (msgCount > containerCount) {
|
|
|
- if (e.keyCode == 13) {
|
|
|
+ if (e && e.keyCode == 13) {
|
|
|
msgCount++;
|
|
|
}
|
|
|
|
|
@@ -46,19 +68,62 @@ const hanlderWrite = (e) => {
|
|
|
lineCount.value = containerCount;
|
|
|
}
|
|
|
|
|
|
+ emits('onTextChange', { text: inputText.value });
|
|
|
+
|
|
|
// textAreaHeight.value = msgH;
|
|
|
};
|
|
|
+const onPaste = (e) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ // let msgH = document.getElementById('msg').clientHeight;
|
|
|
+ hanlderWrite(e);
|
|
|
+ let content = document.getElementById('content');
|
|
|
+ content.scrollTo(0, 9999999);
|
|
|
+ }, 100);
|
|
|
+};
|
|
|
+const setFocusAt = (focusIndex) => {
|
|
|
+ let txtarea = document.getElementById('write-info');
|
|
|
+ setCaretPosition(txtarea, focusIndex);
|
|
|
+};
|
|
|
+
|
|
|
+//设置光标位置
|
|
|
+const setCaretPosition = (ctrl, pos) => {
|
|
|
+ if (ctrl.setSelectionRange) {
|
|
|
+ ctrl.focus();
|
|
|
+ ctrl.setSelectionRange(pos, pos);
|
|
|
+ } else if (ctrl.createTextRange) {
|
|
|
+ var range = ctrl.createTextRange();
|
|
|
+ range.collapse(true);
|
|
|
+ range.moveEnd('character', pos);
|
|
|
+ range.moveStart('character', pos);
|
|
|
+ range.select();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
onMounted(async () => {
|
|
|
await nextTick();
|
|
|
getLineCount();
|
|
|
+ inputText.value = props.text;
|
|
|
+ setTimeout(() => {
|
|
|
+ hanlderWrite();
|
|
|
+
|
|
|
+ if (props.text && props.textIndex) {
|
|
|
+ console.error(props.textIndex);
|
|
|
+ setFocusAt(props.textIndex);
|
|
|
+ }
|
|
|
+ }, 0);
|
|
|
});
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
+.warpper {
|
|
|
+ padding: 70px 50px 30px;
|
|
|
+}
|
|
|
.write-box {
|
|
|
width: 100%;
|
|
|
height: calc(100vh - 100px);
|
|
|
-
|
|
|
+ font-size:24px;
|
|
|
+ color:#000;
|
|
|
overflow: hidden;
|
|
|
+ font-family: sr, st;
|
|
|
.content {
|
|
|
overflow-y: auto;
|
|
|
overflow-x: hidden;
|
|
@@ -83,6 +148,8 @@ onMounted(async () => {
|
|
|
resize: none;
|
|
|
z-index: 2;
|
|
|
overflow: hidden;
|
|
|
+ font-size: 24px;
|
|
|
+ font-family: sr, st;
|
|
|
}
|
|
|
.msg-box {
|
|
|
min-height: 40px;
|