diff --git a/src/screens/auth/VerificationFormScreen.tsx b/src/screens/auth/VerificationFormScreen.tsx index 21fb50a..0140981 100644 --- a/src/screens/auth/VerificationFormScreen.tsx +++ b/src/screens/auth/VerificationFormScreen.tsx @@ -23,6 +23,7 @@ import * as ImagePicker from 'expo-image-picker'; import { useAppColors, type AppColors } from '../../theme'; import { useVerificationStore } from '../../stores/verificationStore'; import { showPrompt } from '../../services/promptService'; +import { uploadService } from '../../services/uploadService'; import type { UserIdentity } from '../../types/dto'; const THEME_COLORS = { @@ -45,6 +46,7 @@ export const VerificationFormScreen: React.FC = () => { const params = useLocalSearchParams<{ identity?: string }>(); const { submitVerification, isLoading } = useVerificationStore(); + const [uploading, setUploading] = useState(false); const [formData, setFormData] = useState({ real_name: '', student_id: '', @@ -110,29 +112,53 @@ export const VerificationFormScreen: React.FC = () => { const handleSubmit = async () => { if (!validateForm()) return; - const success = await submitVerification({ - identity, - real_name: formData.real_name.trim(), - student_id: formData.student_id.trim() || undefined, - employee_id: formData.employee_id.trim() || undefined, - department: formData.department.trim() || undefined, - proof_materials: formData.proof_materials, - }); + setUploading(true); + try { + let proofMaterialsUrl = formData.proof_materials; - if (success) { - showPrompt({ - title: '提交成功', - message: '您的认证申请已提交,请等待审核', - type: 'success', - }); - router.back(); - } else { - const error = useVerificationStore.getState().error; - showPrompt({ - title: '提交失败', - message: error || '请稍后重试', - type: 'error', + if (formData.proof_materials.startsWith('file://') || formData.proof_materials.startsWith('content://') || formData.proof_materials.startsWith('blob:')) { + const uploadResult = await uploadService.uploadImage({ + uri: formData.proof_materials, + }); + + if (!uploadResult || !uploadResult.url) { + showPrompt({ + title: '上传失败', + message: '证明材料图片上传失败,请重试', + type: 'error', + }); + return; + } + + proofMaterialsUrl = uploadResult.url; + } + + const success = await submitVerification({ + identity, + real_name: formData.real_name.trim(), + student_id: formData.student_id.trim() || undefined, + employee_id: formData.employee_id.trim() || undefined, + department: formData.department.trim() || undefined, + proof_materials: proofMaterialsUrl, }); + + if (success) { + showPrompt({ + title: '提交成功', + message: '您的认证申请已提交,请等待审核', + type: 'success', + }); + router.back(); + } else { + const error = useVerificationStore.getState().error; + showPrompt({ + title: '提交失败', + message: error || '请稍后重试', + type: 'error', + }); + } + } finally { + setUploading(false); } }; @@ -169,7 +195,7 @@ export const VerificationFormScreen: React.FC = () => { }} keyboardType={keyboardType} maxLength={maxLength} - editable={!isLoading} + editable={!isLoading && !uploading} /> {error && {error}} @@ -245,7 +271,7 @@ export const VerificationFormScreen: React.FC = () => { style={[styles.uploadButton, errors.proof_materials && styles.uploadButtonError]} onPress={handlePickImage} activeOpacity={0.8} - disabled={isLoading} + disabled={isLoading || uploading} > {formData.proof_materials ? ( { - {isLoading ? ( + {(isLoading || uploading) ? ( ) : ( 提交认证申请