-
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.
feat(certify): add certify page (#48)
* feat(certify): add certify page * feat(certify): add certify page * fix: fix type error * chore: do not commit fucking lock file!!!
- Loading branch information
1 parent
0a6514c
commit 8f8d36c
Showing
11 changed files
with
233 additions
and
6,244 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 |
---|---|---|
|
@@ -37,3 +37,4 @@ next-env.d.ts | |
# IDE | ||
.vscode/* | ||
.idea/* | ||
*-lock.yaml |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use client' | ||
|
||
import { Button, Input, Modal, ModalBody, ModalContent, ModalHeader, useDisclosure, useModal } from "@nextui-org/react" | ||
import { Component, Dispatch, SetStateAction, useEffect, useMemo, useState } from "react" | ||
import {QRCodeSVG} from 'qrcode.react'; | ||
import useCert from "../hooks/use-cert"; | ||
|
||
interface CertInitProps { | ||
onClick: ()=>void; | ||
certName: string; | ||
certNo: string; | ||
setCertName: Dispatch<SetStateAction<string>> | ||
setCertNo: Dispatch<SetStateAction<string>> | ||
} | ||
|
||
const CertInit = (props: CertInitProps) => { | ||
const {certNo,certName,setCertNo,setCertName} = props; | ||
return ( | ||
<> | ||
<Input label="真实姓名" onValueChange={setCertName} value={certName} isRequired /> | ||
<Input label="身份证号" onValueChange={setCertNo} value={certNo} isRequired /> | ||
<Button className="w-fit mx-auto" onClick={props.onClick}>下一步</Button> | ||
</> | ||
) | ||
} | ||
|
||
const CertVerify = (props: {cert_url: string}) => { | ||
const {cert_url} = props; | ||
const [qrUrl, setQrUrl] = useState(cert_url); | ||
return ( | ||
<> | ||
<QRCodeSVG value={qrUrl} size={320} bgColor="#000" fgColor="#fff" includeMargin={false} /> | ||
<span>请使用支付宝扫描二维码</span> | ||
<Button>我已扫描</Button> | ||
</> | ||
) | ||
} | ||
|
||
export default function Cert(){ | ||
const {isOpen, onOpenChange, onOpen} = useDisclosure(); | ||
const {step, addStep, certInitHook, certVerifyHook} = useCert(); | ||
const CertSteps = (step: number) => { | ||
const steps = [ | ||
<CertInit key='init' {...certInitHook} />, | ||
<CertVerify key='verify' cert_url={certVerifyHook.certUrl} /> | ||
]; | ||
return steps[step]; | ||
} | ||
useEffect(()=>{ | ||
onOpen(); | ||
},[]) | ||
return ( | ||
<Modal backdrop="blur" isOpen={isOpen} onOpenChange={onOpenChange}> | ||
<ModalContent> | ||
{(close) => ( | ||
<> | ||
<ModalHeader> | ||
实名认证 | ||
</ModalHeader> | ||
<ModalBody> | ||
<div className="w-full flex flex-col justify-center items-center justify-items-center content-center text-center gap-2"> | ||
{CertSteps(step)} | ||
</div> | ||
</ModalBody> | ||
</> | ||
)} | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Message } from "@/components/message"; | ||
import IOC from "@/providers"; | ||
import { Dispatch, SetStateAction, useEffect, useState } from "react"; | ||
|
||
interface CertInitProps { | ||
next: ()=>void; | ||
certName: string; | ||
certId: string; | ||
setCertName: Dispatch<SetStateAction<string>> | ||
setCertId: Dispatch<SetStateAction<string>> | ||
} | ||
|
||
export const useCertInit = ( | ||
certId: string, | ||
setCertId: Dispatch<SetStateAction<string>>, | ||
next: ()=>void | ||
) => { | ||
const [certName, setCertName] = useState(''); | ||
const [certNo, setCertNo] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
const onClick = () => { | ||
setLoading(true); | ||
IOC.certify.initialize({ | ||
identity_param:{ | ||
cert_name: certName, | ||
cert_no: certNo | ||
} | ||
}) | ||
.then(({data})=>{ | ||
setCertId(data.certify_id) | ||
next() | ||
}) | ||
.finally(()=>setLoading(false)); | ||
} | ||
return { | ||
certNo, | ||
certName, | ||
loading, | ||
setCertNo, | ||
setCertName, | ||
setLoading, | ||
onClick | ||
} | ||
} | ||
|
||
export const useCertVerify = (certId: string) => { | ||
const [certUrl, setCertUrl] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
useEffect(()=>{ | ||
if (certId){ | ||
IOC.certify.start({certify_id: certId}) | ||
.then(({data}) => { | ||
setCertUrl(data.certify_url); | ||
}) | ||
} | ||
}, [certId]) | ||
const onClick = () => { | ||
setLoading(true) | ||
IOC.certify.queryCertifyResult(certId) | ||
.finally(()=>{ | ||
setLoading(false); | ||
}) | ||
} | ||
return { | ||
certUrl, | ||
loading, | ||
setCertUrl, | ||
setLoading, | ||
onClick | ||
} | ||
} | ||
|
||
const useCert = () => { | ||
const [step, setStep] = useState(0); | ||
const addStep = () => setStep(step+1); | ||
const [certId, setCertId] = useState(''); | ||
const certInitHook = useCertInit(certId, setCertId, addStep); | ||
const certVerifyHook = useCertVerify(certId); | ||
return { | ||
certInitHook, | ||
certVerifyHook, | ||
step, | ||
setStep, | ||
addStep, | ||
} | ||
} | ||
|
||
export default useCert; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { UserModel } from '../interface/model/user'; | ||
import {atom} from 'jotai'; | ||
|
||
export const profile = atom<null | UserModel>(null); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export interface CertifyInitializeRequest { | ||
identity_param: IdentityParam; | ||
} | ||
export interface StartCertifyRequest { | ||
certify_id: string; | ||
} | ||
export interface QueryCertifyRequest { | ||
certify_id: string | ||
} | ||
|
||
export interface CertifyInitializeResponse { | ||
certify_id: string; | ||
} | ||
export interface StartCertifyResponse { | ||
certify_url: string | ||
} | ||
|
||
export interface IdentityParam { | ||
/** | ||
* 真实姓名 | ||
*/ | ||
cert_name: string; | ||
/** | ||
* 身份证号 | ||
*/ | ||
cert_no: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CertifyInitializeRequest, CertifyInitializeResponse, StartCertifyRequest, StartCertifyResponse } from "@/interface/model/certify"; | ||
import { Axios } from "axios"; | ||
|
||
export class Certify{ | ||
private axios: Axios; | ||
constructor(axios:Axios){ | ||
this.axios = axios; | ||
} | ||
initialize({identity_param}: CertifyInitializeRequest){ | ||
return this.axios.post<CertifyInitializeResponse>('/certify/initialize', identity_param); | ||
} | ||
start(data: StartCertifyRequest){ | ||
return this.axios.post<StartCertifyResponse>('/certify/verify', data); | ||
} | ||
queryCertifyResult(certify_id: string){ | ||
return this.axios.get('/certify/query', {params: {certify_id}}); | ||
} | ||
getCertifyState(){ | ||
return this.axios.get('/certify'); | ||
} | ||
} |
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,10 +1,12 @@ | ||
import { Certify } from './certify'; | ||
import {http} from './http'; | ||
import {Picture} from './picture'; | ||
import {User} from './user'; | ||
|
||
const IOC = { | ||
user: new User(http), | ||
picture: new Picture(http) | ||
picture: new Picture(http), | ||
certify: new Certify(http) | ||
} | ||
|
||
export default IOC; |
Oops, something went wrong.