2 Коммиты 432d961a10 ... a02107b254

Автор SHA1 Сообщение Дата
  mcbaiyun a02107b254 feat(news-edit): 为 textarea 组件添加 maxlength 和 auto-height 属性,优化长文本输入体验 2 недель назад
  mcbaiyun 476c3b9523 feat(news-detail): 优化页面参数获取逻辑,使用 onLoad 钩子和 ref 处理参数 2 недель назад

+ 32 - 0
docs/uni-app textarea 内容截断问题与修复.md

@@ -0,0 +1,32 @@
+# uni-app textarea 内容截断问题与修复
+
+## 问题描述
+在 uni-app Vue 3 环境中,编辑页面加载长文本内容时,`textarea` 组件只显示部分内容,后续内容被截断。
+
+## 问题原因
+uni-app 的 `textarea` 组件在小程序平台,`value` 属性默认最大长度为 140 字符。即使数据完整加载,也会在显示时被截断。H5 平台可能不受此限制,但小程序环境会强制截断。
+
+## 解决方法
+在 `textarea` 标签上添加 `maxlength` 属性,设置为足够大的值,如 `maxlength="999999"`,以允许显示完整内容。
+
+```vue
+<textarea
+  v-model="content"
+  auto-height="true"
+  maxlength="999999"
+  placeholder="在此输入 Markdown 内容"
+/>
+```
+
+## 经验教训
+- uni-app 组件在不同平台(如小程序、H5)有特定限制,需查阅官方文档确认默认行为。
+- 调试时,通过 `console.log` 检查数据完整性,但显示问题需考虑组件属性限制。
+- 对于长文本输入,务必设置 `maxlength` 以避免平台默认截断。
+- 结合 `auto-height="true"` 可实现动态高度调整,提升用户体验。
+
+## 相关代码片段
+```typescript
+// 数据加载后检查内容长度
+console.log('Loaded content length:', content.value.length)
+console.log('Assigned content:', content.value)
+```

+ 2 - 0
src/pages/doctor/manage/news-edit.vue

@@ -23,6 +23,8 @@
           class="markdown-area"
           :style="textareaStyle"
           placeholder="在此输入 Markdown 内容"
+          maxlength="999999"
+          auto-height="true"
           @input="onInput"
           @focus="onFocus"
         ></textarea>

+ 8 - 2
src/pages/public/news-detail.vue

@@ -51,10 +51,17 @@
 
 <script setup lang="ts">
 import { ref, computed, onMounted, watch, onUnmounted } from 'vue'
+import { onLoad } from '@dcloudio/uni-app'
 import { downloadWithAuth } from '@/utils/downloadWithAuth'
 import CustomNav from '@/components/custom-nav.vue'
 import { getNewsById } from '@/api/news'
 
+const query = ref<Record<string, string>>({})
+
+onLoad((options) => {
+  query.value = options || {}
+})
+
 // 处理内联markdown
 const processInline = (text: string) => {
   return text.replace(/\*\*(.*?)\*\*/g, '$1').replace(/\*(.*?)\*/g, '$1');
@@ -356,8 +363,7 @@ const onImageError = async (src?: string, e?: any) => {
 }
 
 onMounted(async () => {
-  const query: Record<string, string> = (((globalThis as any).getCurrentPages ? (globalThis as any).getCurrentPages().slice(-1)[0]?.options : {}) as Record<string, string>) || {}
-  const id = query.id || ''
+  const id = query.value.id || ''
   if (!id) {
     isLoading.value = false
     return