-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d004346
commit 12574cd
Showing
27 changed files
with
338 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import React from "react"; | ||
|
||
export default function AboutLayout({children,}: { | ||
children: React.ReactNode; | ||
}) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,46 @@ | ||
'use client' | ||
|
||
import { useState } from "react"; | ||
import {useState} from "react"; | ||
import IOC from "@/providers"; | ||
import { Button } from "@nextui-org/react"; | ||
import {Button} from "@nextui-org/react"; | ||
import CountDown from "./count-down"; | ||
|
||
const CheckCode = (props: {type: 'email' | 'phone' | 'unknown', userInput: string}) => { | ||
const CheckCode = (props: { type: 'email' | 'phone' | 'unknown', userInput: string }) => { | ||
const {type} = props; | ||
const [cd, setCD] = useState(0) | ||
const onCountdownFinish = () => { | ||
setCD(0) | ||
} | ||
const getCode = () => { | ||
if (type === 'email'){ | ||
if (type === 'email') { | ||
IOC.user.getCheckCodeByEmail(props.userInput) | ||
.then((val)=>{ | ||
setCD(val.data.cd + 1); | ||
}) | ||
.catch((err)=>{ | ||
console.log(err); | ||
setCD(60 * 1000); | ||
}) | ||
.then((val) => { | ||
setCD(val.data.cd + 1); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
setCD(60 * 1000); | ||
}) | ||
} | ||
if (type === 'phone'){ | ||
if (type === 'phone') { | ||
IOC.user.getCheckCodeByPhone(props.userInput) | ||
.then((val)=>{ | ||
setCD(val.data.cd + 1); | ||
console.log(val.data.cd) | ||
}) | ||
.catch(()=>{ | ||
setCD(60 * 1000); | ||
}) | ||
.then((val) => { | ||
setCD(val.data.cd + 1); | ||
console.log(val.data.cd) | ||
}) | ||
.catch(() => { | ||
setCD(60 * 1000); | ||
}) | ||
} | ||
} | ||
return ( | ||
<Button onClick={getCode} isDisabled={cd > 0} size="lg" className="flex gap-2 flex-grow-0 flex-shrink-0 basis-auto px-2 w-32 break-words"> | ||
<Button onClick={getCode} isDisabled={cd > 0} size="lg" | ||
className="flex gap-2 flex-grow-0 flex-shrink-0 basis-auto px-2 w-32 break-words"> | ||
{ | ||
cd > 0 ? <CountDown countDown={cd} onFinish={onCountdownFinish} /> : '发送验证码' | ||
cd > 0 ? <CountDown countDown={cd} onFinish={onCountdownFinish}/> : '发送验证码' | ||
} | ||
</Button> | ||
) | ||
} | ||
|
||
export default CheckCode; | ||
export default CheckCode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
'use client' | ||
|
||
import { useEffect, useRef, useState } from "react"; | ||
import { useCountDown } from "../hooks" | ||
import {useEffect, useState} from "react"; | ||
import {useCountDown} from "../hooks" | ||
|
||
const CountDown = ( | ||
props: {countDown: number, onFinish: () => void} | ||
props: { countDown: number, onFinish: () => void } | ||
) => { | ||
const [cd, setCD] = useState( | ||
const [cd] = useState( | ||
Number((props.countDown / 1000).toFixed()) | ||
); | ||
const [time, start] = useCountDown(cd); | ||
useEffect(()=>{ | ||
useEffect(() => { | ||
start(); | ||
},[]) | ||
useEffect(()=>{ | ||
if (time === 0){ | ||
}, []) | ||
useEffect(() => { | ||
if (time === 0) { | ||
props.onFinish(); | ||
} | ||
},[time, props]) | ||
}, [time, props]) | ||
return ( | ||
<span>{time}秒后重新获取</span> | ||
) | ||
} | ||
|
||
export default CountDown; | ||
export default CountDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import {useEffect, useState} from "react"; | ||
|
||
export function useCountDown(ms: number):[number, ()=>void,()=>void,()=>void] { | ||
const [time, setTime] = useState(ms); | ||
const [isRunning, setIsRunning] = useState(false); | ||
useEffect(() => { | ||
if (isRunning && time > 0) { | ||
const timerId = setTimeout(() => { | ||
setTime(time - 1); | ||
}, 1000); | ||
return () => { | ||
clearTimeout(timerId); | ||
}; | ||
export function useCountDown(ms: number): [number, () => void, () => void, () => void] { | ||
const [time, setTime] = useState(ms); | ||
const [isRunning, setIsRunning] = useState(false); | ||
useEffect(() => { | ||
if (isRunning && time > 0) { | ||
const timerId = setTimeout(() => { | ||
setTime(time - 1); | ||
}, 1000); | ||
return () => { | ||
clearTimeout(timerId); | ||
}; | ||
} else { | ||
setIsRunning(false); | ||
} | ||
}, [isRunning, time]); | ||
const start = () => { | ||
setIsRunning(true) | ||
} | ||
else { | ||
setIsRunning(false); | ||
const pause = () => { | ||
setIsRunning(false); | ||
} | ||
}, [isRunning, time]); | ||
const start = () => { | ||
setIsRunning(true) | ||
} | ||
const pause = ()=>{ | ||
setIsRunning(false); | ||
} | ||
const reset = () => { | ||
setTime(ms); | ||
setIsRunning(false); | ||
} | ||
return [time, start, pause, reset]; | ||
const reset = () => { | ||
setTime(ms); | ||
setIsRunning(false); | ||
} | ||
return [time, start, pause, reset]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { SetStateAction, useEffect, useState } from "react" | ||
import React, {SetStateAction, useEffect, useState} from "react" | ||
|
||
export const useType = ( | ||
isPhone: boolean, | ||
isEmail: boolean | ||
):['email'|'phone'|'unknown', React.Dispatch<SetStateAction<'email'|'phone'|'unknown'>>] => { | ||
const [type,setType] = useState<'email'|'phone'|'unknown'>('email') | ||
useEffect(()=>{ | ||
if (!isPhone && !isEmail){ | ||
): ['email' | 'phone' | 'unknown', React.Dispatch<SetStateAction<'email' | 'phone' | 'unknown'>>] => { | ||
const [type, setType] = useState<'email' | 'phone' | 'unknown'>('email') | ||
useEffect(() => { | ||
if (!isPhone && !isEmail) { | ||
setType('unknown'); | ||
return; | ||
} | ||
if (isPhone){ | ||
if (isPhone) { | ||
setType('phone'); | ||
return; | ||
} | ||
if (isEmail){ | ||
if (isEmail) { | ||
setType('email'); | ||
return ; | ||
return; | ||
} | ||
},[isPhone, isEmail]); | ||
}, [isPhone, isEmail]); | ||
return [type, setType] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import { useMemo } from "react" | ||
import {useMemo} from "react" | ||
|
||
export const useIsEmail = (userInput: string) => { | ||
const validateEmail = (val: string)=>val.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,10}$/i); | ||
return useMemo(()=>{ | ||
if (!userInput){ | ||
const validateEmail = (val: string) => val.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,10}$/i); | ||
return useMemo(() => { | ||
if (!userInput) { | ||
return false; | ||
} | ||
return validateEmail(userInput) ? true : false; | ||
return !!validateEmail(userInput); | ||
}, [userInput]); | ||
} | ||
|
||
export const useIsPhone = (userInput: string) => { | ||
const validatePhone = (val:string)=>val.match(/^1[3-9]\d{9}$/i); | ||
const isPhone = useMemo(()=>{ | ||
if (!userInput){ | ||
const validatePhone = (val: string) => val.match(/^1[3-9]\d{9}$/i); | ||
return useMemo(() => { | ||
if (!userInput) { | ||
return false; | ||
} | ||
return validatePhone(userInput) ? true : false; | ||
}, [userInput]) | ||
return isPhone; | ||
} | ||
return !!validatePhone(userInput); | ||
}, [userInput]); | ||
} |
Oops, something went wrong.