From 059ea79a981eb6a807c5711f639f1916eb4629cd Mon Sep 17 00:00:00 2001 From: zhangjing1 Date: Fri, 27 Mar 2026 10:33:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(mdugc):=20=E8=AF=84=E8=AE=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=88=86=E9=A1=B5=E4=B8=8E=20SpInput=20=E5=9B=9E?= =?UTF-8?q?=E8=BD=A6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - note-detail:fetchComment 分页追加列表,commentTotal 使用接口 total_count - sp-input:detail.keyCode 为回车时走 onConfirm;H5 回车用 input 当前值避免 iOS 滞后 - i18n:补充「发送」文案键 f1ow2 Made-with: Cursor --- src/components/sp-input/index.js | 36 +++++++++++++++++++++++++------ src/subpages/i18n/lang/index.json | 8 ++++++- src/subpages/mdugc/note-detail.js | 6 ++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/components/sp-input/index.js b/src/components/sp-input/index.js index cb0589543..f61cfe1e6 100644 --- a/src/components/sp-input/index.js +++ b/src/components/sp-input/index.js @@ -17,13 +17,36 @@ function SpInput(props) { const containerRef = useRef(null) const handleInput = async (event) => { - console.log('sp-input', event, event.detail.value, props.maxLength) - if (props.maxLength && event.detail.value?.length > props.maxLength) { + const detail = event.detail || {} + let value = detail.value + const maxLen = props.maxLength + + // 回车发送:部分端在 input 的 detail 中带 keyCode(与 H5 keydown、原生监听互为补充) + if (props.onConfirm) { + const keyCode = detail.keyCode + const isEnter = keyCode === 13 || keyCode === 'Enter' + if (isEnter) { + const clean = + typeof value === 'string' ? value.replace(/\r\n/g, '').replace(/\r/g, '').replace(/\n/g, '') : value + props.onConfirm({ + detail: { + value: clean ?? '' + } + }) + await props.onChange(clean ?? '') + throttle(() => { + setCursor(typeof detail.cursor === 'number' ? detail.cursor : -1) + }, 100) + return + } + } + + if (maxLen && value?.length > maxLen) { return } - await props.onChange(event.detail.value) + await props.onChange(value) throttle(() => { - setCursor(event.detail.cursor) + setCursor(detail.cursor) }, 100) } @@ -40,15 +63,16 @@ function SpInput(props) { } } - // H5环境下处理回车键,触发onConfirm + // H5:回车触发 onConfirm(读 DOM 当前值,避免 iOS 受控 props 滞后) const handleKeyDown = (event) => { if (isWeb && (event.key === 'Enter' || event.keyCode === 13)) { event.preventDefault() event.stopPropagation() if (props.onConfirm) { + const domVal = event.target?.value props.onConfirm({ detail: { - value: props.value || '' + value: domVal != null ? domVal : props.value || '' } }) } diff --git a/src/subpages/i18n/lang/index.json b/src/subpages/i18n/lang/index.json index 55994fb4e..1a50b3251 100644 --- a/src/subpages/i18n/lang/index.json +++ b/src/subpages/i18n/lang/index.json @@ -15940,5 +15940,11 @@ "en": "", "zh-tw": "", "ar": "" + }, + "f1ow2": { + "zh-cn": "发送", + "en": "", + "zh-tw": "", + "ar": "" } -} \ No newline at end of file +} diff --git a/src/subpages/mdugc/note-detail.js b/src/subpages/mdugc/note-detail.js index 5c921d938..17f9eb87a 100644 --- a/src/subpages/mdugc/note-detail.js +++ b/src/subpages/mdugc/note-detail.js @@ -125,10 +125,8 @@ function UgcNoteDetail(props) { const { list, total_count: total } = await mdugcApi.commentlist(params) const _commentList = pickBy(list, mdugcDoc.COMMENT_INFO) setState((draft) => { - draft.commentList = _commentList - draft.commentTotal = _commentList.reduce((previous, current) => { - return previous + current.child.length + 1 - }, 0) + draft.commentList = [...draft.commentList, ..._commentList] + draft.commentTotal = total }) return { total