修复日记长文输入布局并减少输入时正文回传

This commit is contained in:
2026-10-11 09:22:29 +08:00
parent 5365e13963
commit 1bafb01741
7 changed files with 25 additions and 8 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ Page({
},
onContentInput: function(e) {
var val = e.detail.value || '';
this.setData({ 'form.content': val, contentLength: val.length });
// 正文只存于逻辑层,避免每次敲字回传长文本影响原生输入。
this.data.form.content = val;
this.setData({ contentLength: val.length });
},
chooseImages: function() {
+1 -1
View File
@@ -15,7 +15,7 @@
<label>内容</label>
<text class="char-count {{contentLength > 5000 ? 'char-warn' : ''}}">{{contentLength}}/5000</text>
</view>
<textarea placeholder-class="handwritten-placeholder" class="input textarea diary-editor" placeholder="想写些什么..." value="{{editorContent}}" bindinput="onContentInput" maxlength="{{5000}}" auto-height="{{false}}" cursor-spacing="24" />
<textarea placeholder-class="handwritten-placeholder" class="input textarea diary-editor" placeholder="想写些什么..." value="{{editorContent}}" bindinput="onContentInput" maxlength="5000" auto-height="{{true}}" cursor-spacing="24" />
</view>
<!-- 图片(可删除) -->
+2 -2
View File
@@ -141,8 +141,8 @@ page { background: linear-gradient(180deg, #FDE4EC 0%, #FFF0F5 48%, #FFF7FA 100%
@import '../../styles/journal.wxss';
/* 长正文在输入框内滚动,避免输入时整页不断增高。 */
textarea.diary-editor { height:420rpx; min-height:420rpx; box-sizing:border-box; }
/* 正文随输入增高,长文由外层页面滚动,避免嵌套原生输入框滚动。 */
textarea.diary-editor { min-height:420rpx; box-sizing:border-box; }
@import '../../styles/button-theme.wxss';
+3 -1
View File
@@ -259,7 +259,9 @@ Page({
onDateInput: function(e) { this.setData({ 'form.date': e.detail.value }); this._saveDraft(); },
onContentInput: function(e){
var val = e.detail.value || '';
this.setData({ 'form.content': val, contentLength: val.length });
// 正文只存于逻辑层,避免每次敲字回传长文本影响原生输入。
this.data.form.content = val;
this.setData({ contentLength: val.length });
this._saveDraft();
},
onLocationInput: function(e){ this.setData({ 'form.location': e.detail.value }); this._saveDraft(); },
+1 -1
View File
@@ -101,7 +101,7 @@
<label>内容</label>
<text class="char-count {{contentLength > 5000 ? 'char-warn' : ''}}">{{contentLength}}/5000</text>
</view>
<textarea placeholder-class="handwritten-placeholder" class="input textarea diary-editor" placeholder="今天发生了什么有趣的事呢?写下你的心情和感受吧…" value="{{editorContent}}" bindinput="onContentInput" maxlength="{{5000}}" auto-height="{{false}}" cursor-spacing="24" />
<textarea placeholder-class="handwritten-placeholder" class="input textarea diary-editor" placeholder="今天发生了什么有趣的事呢?写下你的心情和感受吧…" value="{{editorContent}}" bindinput="onContentInput" maxlength="5000" auto-height="{{true}}" cursor-spacing="24" />
</view>
<!-- 图片选择(可删除) -->
+2 -2
View File
@@ -207,8 +207,8 @@ page { background: linear-gradient(180deg, #FDE4EC 0%, #FFF0F5 48%, #FFF7FA 100%
@import '../../styles/journal.wxss';
/* 长正文在输入框内滚动,避免输入时整页不断增高。 */
textarea.diary-editor { height:420rpx; min-height:420rpx; box-sizing:border-box; }
/* 正文随输入增高,长文由外层页面滚动,避免嵌套原生输入框滚动。 */
textarea.diary-editor { min-height:420rpx; box-sizing:border-box; }
@import '../../styles/button-theme.wxss';
+13
View File
@@ -1,6 +1,7 @@
const test=require('node:test');
const assert=require('node:assert/strict');
const path=require('node:path');
const fs=require('node:fs');
const createLoader=require('./load-module.cjs');
function setup(file,api={}) {
let definition,id=0;const timers=new Map(),storage=new Map(),writes=[];
@@ -15,6 +16,18 @@ test('diary input continues past 100 characters and never rewrites the native te
e.patches.length=0;
for(const length of [100,101,140,1000,5000]){const value='字'.repeat(length);e.page.onContentInput({detail:{value}});assert.equal(e.page.data.form.content,value);assert.equal(e.page.data.contentLength,length);}
assert.ok(e.patches.every(patch=>!('editorContent' in patch)));
assert.ok(e.patches.every(patch=>!('form.content' in patch)));
}
});
test('both diary templates explicitly allow 5000 characters and grow with long text',()=>{
for(const file of ['publish/publish','diary_edit/diary_edit']){
const base=path.join(__dirname,'../pages',file);
const template=fs.readFileSync(base+'.wxml','utf8');
const editor=template.match(/<textarea\b[^>]*class="[^"]*diary-editor[^"]*"[^>]*\/>/)[0];
assert.match(editor,/maxlength="5000"/);
assert.match(editor,/auto-height="\{\{true\}\}"/);
const styles=fs.readFileSync(base+'.wxss','utf8');
assert.doesNotMatch(styles,/textarea\.diary-editor\s*\{[^}]*[;{]\s*height\s*:/);
}
});
test('rapid typing writes a single draft, and leaving the page flushes the newest content',()=>{