修改导航
This commit is contained in:
@@ -12,19 +12,19 @@ export interface AiImportPopupProps {
|
||||
visible: boolean
|
||||
onClose: () => void
|
||||
onManualPublish?: () => void
|
||||
onPasteAndRecognize?: (text: string) => void
|
||||
}
|
||||
|
||||
const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
onManualPublish,
|
||||
onPasteAndRecognize
|
||||
}) => {
|
||||
const [text, setText] = useState('')
|
||||
const [uploadFailCount, setUploadFailCount] = useState(0)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [uploadLoading, setUploadLoading] = useState(false)
|
||||
const [keyboardHeight, setKeyboardHeight] = useState(0)
|
||||
const [isKeyboardVisible, setIsKeyboardVisible] = useState(false)
|
||||
const maxFailCount = 3
|
||||
|
||||
// 获取 actions(在组件顶层调用 Hook)
|
||||
@@ -33,12 +33,34 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
const textIdentification = async (text: string) => {
|
||||
setLoading(true)
|
||||
const res = await publishService.extract_tennis_activity({text})
|
||||
console.log(res)
|
||||
const {data} = res
|
||||
navigateToPublishBall(data)
|
||||
const { data } = res
|
||||
if (data && data?.length > 0) {
|
||||
navigateToPublishBall(data)
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: '未识别到球局信息',
|
||||
icon: 'error'
|
||||
})
|
||||
setUploadFailCount(prev => prev + 1)
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const initAiPopup = () => {
|
||||
setText('')
|
||||
setUploadFailCount(0)
|
||||
setLoading(false)
|
||||
setUploadLoading(false)
|
||||
setKeyboardHeight(0)
|
||||
setIsKeyboardVisible(false)
|
||||
}
|
||||
const handlePasteAndRecognize = async () => {
|
||||
if (text) {
|
||||
textIdentification(text)
|
||||
} else {
|
||||
getClipboardData()
|
||||
}
|
||||
}
|
||||
const getClipboardData = async () => {
|
||||
try {
|
||||
const res = await Taro.getClipboardData()
|
||||
@@ -75,6 +97,8 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
const navigateToPublishBall = (data: any) => {
|
||||
if (Array.isArray(data) && data.length > 0) {
|
||||
setPublishData(data)
|
||||
initAiPopup()
|
||||
onClose()
|
||||
Taro.navigateTo({
|
||||
url: '/publish_pages/publishBall/index?type=ai'
|
||||
})
|
||||
@@ -85,6 +109,32 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
setText(e.detail.value)
|
||||
}
|
||||
|
||||
// 监听键盘高度变化,保持弹窗贴合底部
|
||||
useEffect(() => {
|
||||
Taro.onKeyboardHeightChange?.((res: any) => {
|
||||
const height = Number(res?.height || 0)
|
||||
if (height > 0) {
|
||||
setIsKeyboardVisible(true)
|
||||
setKeyboardHeight(height)
|
||||
} else {
|
||||
setIsKeyboardVisible(false)
|
||||
setKeyboardHeight(0)
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
// Taro 里 onKeyboardHeightChange 返回的不是取消函数,这里通过置零兜底
|
||||
setIsKeyboardVisible(false)
|
||||
setKeyboardHeight(0)
|
||||
// 微信小程序环境可调用 offKeyboardHeightChange,如存在则尝试注销
|
||||
// @ts-ignore
|
||||
if (typeof Taro.offKeyboardHeightChange === 'function') {
|
||||
// @ts-ignore
|
||||
Taro.offKeyboardHeightChange()
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleImageRecognition = async () => {
|
||||
try {
|
||||
const res = await Taro.chooseMedia({
|
||||
@@ -103,8 +153,17 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
if (ossPath) {
|
||||
setUploadLoading(true)
|
||||
const publishData = await publishService.extract_tennis_activity_from_image({image_url: ossPath})
|
||||
const {data} = publishData
|
||||
navigateToPublishBall(data)
|
||||
const { data } = publishData
|
||||
if (data && data?.length > 0) {
|
||||
navigateToPublishBall(data)
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: '未识别到球局信息',
|
||||
icon: 'error'
|
||||
})
|
||||
setUploadFailCount(prev => prev + 1)
|
||||
setUploadLoading(false)
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
@@ -138,6 +197,7 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
closeable={false}
|
||||
onClose={onClose}
|
||||
className={styles.aiImportPopup}
|
||||
style={{ paddingBottom: isKeyboardVisible ? `${keyboardHeight}px` : undefined }}
|
||||
>
|
||||
<View className={styles.popupContent}>
|
||||
{/* 头部 */}
|
||||
@@ -157,11 +217,15 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
className={styles.textArea}
|
||||
value={text}
|
||||
onInput={handleTextChange}
|
||||
onFocus={() => setIsKeyboardVisible(true)}
|
||||
onBlur={() => setIsKeyboardVisible(false)}
|
||||
placeholder="在此「粘贴识别」或输入文本,智能拆分球局时间、费用、地点和其他信息,并帮你智能生成球局标题"
|
||||
maxlength={100}
|
||||
showConfirmBar={false}
|
||||
placeholderClass={styles.textArea_placeholder}
|
||||
autoHeight
|
||||
// 关闭系统自动上推,改为手动根据键盘高度加内边距
|
||||
adjustPosition={false}
|
||||
/>
|
||||
<View className={styles.charCount}>
|
||||
<Text className={styles.charCountText}>{text.length}/100</Text>
|
||||
@@ -186,7 +250,7 @@ const AiImportPopup: React.FC<AiImportPopupProps> = ({
|
||||
<Text className={styles.manualButtonText}>手动发布球局</Text>
|
||||
</View>
|
||||
)}
|
||||
<View className={styles.pasteButton} onClick={getClipboardData}>
|
||||
<View className={styles.pasteButton} onClick={handlePasteAndRecognize}>
|
||||
{
|
||||
loading ? (
|
||||
<View className={styles.loadingContainer}>
|
||||
|
||||
Reference in New Issue
Block a user