import React, { useState, useEffect } from "react"; import Taro, { useRouter } from '@tarojs/taro'; import { View, Text, Input, Button } from "@tarojs/components"; import "./index.scss"; import httpService from "@/services/httpService"; interface FormFields { old_password?: string; new_password: string; confirm_password: string; sms_code?: string; } const SetTransactionPassword: React.FC = () => { const [handleType, setHandleType] = useState("set"); const router = useRouter(); const { type, phone, sms_code } = router.params; useEffect(() => { if (type) { setHandleType(type); } }, [type]); const [formData, setFormData] = useState({ old_password: "", new_password: "", confirm_password: "", sms_code: "", }); const handleInput = (e: any, field: string) => { setFormData({ ...formData, [field]: e.detail.value }); }; const handleConfirm = async () => { const { new_password, confirm_password } = formData; if (new_password !== confirm_password) { Taro.showToast({ title: "两次密码输入不一致", icon: "none", }); return; } try { await httpService.post("/wallet/set_payment_password", { password: new_password }); Taro.showToast({ title: "设置交易密码成功", icon: "success", }); Taro.navigateBack(); } catch (error) { Taro.showToast({ title: "设置交易密码失败", icon: "none", }); return; } }; return ( { // handleType === "reset" && ( // // 旧密码 // { handleInput(e, "old_password") }}> // // ) } 交易密码 { handleInput(e, "new_password") }}> 重复密码 { handleInput(e, "confirm_password") }}> { handleType === "set" && ( 手机验证 { handleInput(e, "sms_code") }}> ) } * 密码由6位数字组成 ); }; export default SetTransactionPassword;