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