jinx 1 年之前
父節點
當前提交
b6cea87051

+ 1 - 0
server/test/a0k4xu045_202305311600080410/attach/sceneStore

@@ -0,0 +1 @@
+{"measures":[],"baseLines":[],"sceneSeting":{"top":4,"rotate":0,"scale":100},"basePoints":[],"fixPoints":[],"photos":[],"uses":[{"count":0,"key":"keche_p.svg"},{"count":0,"key":"keche_s.svg"},{"count":0,"key":"jiaoche_p.svg"},{"count":0,"key":"jiaoche_s.svg"},{"count":0,"key":"huoche_p.svg"},{"count":0,"key":"huoche_s1.svg"},{"count":0,"key":"huoche_s2.svg"},{"count":0,"key":"rt_rt.svg"},{"count":0,"key":"rt_st.svg"}],"accidentPhotos":[],"roadPhotos":[]}

+ 1 - 0
src/views/tables/ask.vue

@@ -267,6 +267,7 @@ div[contenteditable] {
         z-index: 2;
         white-space: pre-wrap;
         text-align: justify;
+        word-break: break-all;
       }
       .more-line-box {
         width: 100%;

+ 43 - 1
src/views/tables/write/index.vue

@@ -96,6 +96,42 @@ const setCaretPosition = (ctrl, pos) => {
     range.moveStart('character', pos);
     range.select();
   }
+
+  nextTick(() => {
+    getSelectionDistance();
+  });
+};
+
+// 获取 textarea 元素
+
+const getSelectionDistance = () => {
+  var textarea = document.getElementById('write-info'); // 替换 'yourTextareaId' 为您的 textarea 元素的实际 ID
+  // // 获取 textarea 的样式属性
+  var textareaStyle = getComputedStyle(textarea);
+  // // 计算光标位置距离顶部的距离
+  var lineHeight = parseInt(textareaStyle.lineHeight, 10); // 获取行高,如果没有设置,会返回默认值
+  // 获取光标的起始位置
+  var cursorPosition = textarea.selectionStart;
+  // 获取 textarea 内容
+  var textareaValue = textarea.value;
+  // 将内容分割成行
+  var lines = textareaValue.split('\n');
+  // 计算光标所在的行数1
+  var cursorLine = 1; // 初始化行数为1
+  for (var i = 0; i < lines.length; i++) {
+    if (cursorPosition <= lines[i].length) {
+      break; // 找到光标所在的行后退出循环
+    }
+    cursorPosition -= lines[i].length + 1; // 加1是为了包括换行符
+    cursorLine++;
+  }
+  let scrollBox = document.getElementById('content');
+  let scrollHeight = cursorLine * lineHeight;
+  let scrollBoxHeight = scrollBox.offsetHeight;
+  if (scrollHeight > scrollBoxHeight) {
+    console.log('光标所在的行数:', cursorLine);
+    scrollBox.scrollTo(0, scrollHeight - scrollBoxHeight);
+  }
 };
 
 onMounted(async () => {
@@ -106,10 +142,16 @@ onMounted(async () => {
     hanlderWrite();
 
     if (props.text && props.textIndex) {
-      console.error(props.textIndex);
+      // console.error(props.textIndex);
       setFocusAt(props.textIndex);
     }
   }, 0);
+  nextTick(() => {
+    let scrollBox = document.getElementById('content');
+    scrollBox.addEventListener('scroll', (data) => {
+      // console.error(data);
+    });
+  });
 });
 </script>
 <style lang="scss" scoped>