"use client"; import React, { useState } from "react"; import { Form, Input, Toast, Checkbox } from "antd-mobile"; import { JSEncrypt } from "jsencrypt"; import { cryptoPassword, generateSignature } from "@/utils/crypto"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { signIn } from "@/utils/auth"; import baseRequest from "@/utils/baseRequest"; export default function PassWordLogin() { const router = useRouter(); //保存区号 const [regionCode, setRegionCode] = useState("86"); //设置checkbox const [checked, setChecked] = useState(false); //点击登录 const handleSubmit = async (value) => { if (!checked) { Toast.show({ content: "请先勾选同意《用户协议》和《隐私政策》后登录", }); return; } if (!value.mobile_phone || !value.password) { Toast.show({ content: "请完善信息", }); return; } if (!value.mobile_phone.match(/^1[3456789]\d{9}$/)) { Toast.show({ content: "手机号码格式错误", }); return; } if (value.password.length < 8) { Toast.show({ content: "密码不得小于8位", }); return; } if (value.password.length > 15) { Toast.show({ content: "密码不得大于15位", }); return; } //对手机号进行RSA加密 const encrypt = new JSEncrypt(); encrypt.setPublicKey(process.env.NEXT_PUBLIC_RSA_KEY); const mobile_phone = encrypt.encrypt(value.mobile_phone); //MD5加密password const encryptedPassword = cryptoPassword(value.password); //发送登录请求 try { const base = baseRequest(); const signature = generateSignature({ mobile_phone: mobile_phone, region_code: regionCode, password: encryptedPassword, ...base, }); const response = await fetch( `/api/login/login_by_pswd?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ mobile_phone: mobile_phone, region_code: regionCode, password: encryptedPassword, ...base, }), } ); const data = await response.json(); if (data.ret === -1) { Toast.show({ content: data.msg, }); return; } signIn(data); router.back(); } catch (error) { console.error(error); } }; return (

+{regionCode}


密码

忘记密码?
setChecked(!checked)} >

同意 《用户协议》 、 《隐私政策》

); }