import { useEffect, useState } from "react"; import { sendToBackground } from "@plasmohq/messaging"; import Placeholder from "~components/ui/placeholder"; import Form from "~components/ui/form"; import { IconBack } from "~assets/icons"; import styles from "./popup.module.less"; import stylesB from "./bili.module.less"; import useForm from "~hooks/useForm"; import { add } from "~components/ui/message/utils"; interface ReadProps { onBack: () => void; } interface FormValue { name: string; ename: string; project: string; made: string; sale: string; type: number; desc: string; } const getInfo = async () => { let tab: chrome.tabs.Tab; [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true }); if (tab && !tab.url.includes("chrome")) { const a = await chrome.tabs.sendMessage(tab.id, { type: 'toolbox:getBiliToy' }); console.log('get toy:', a); return a; } } function Toy({ onBack }: ReadProps) { const { bindInput, setValues, onSubmit } = useForm({ initialValues: { type: 3, }, }); const [imgs, setImgs] = useState([]); const [currentImg, setCurrentImg] = useState(0); const [failed, setFailed] = useState(false); const submitForm = (body: FormValue) => { sendToBackground({ name: "bili", body: { action: "submitAddForm", values: { ...body, imageUrl: imgs[0], }, }, }).then((res) => { if (res.status === "Success") { add({ content: "提交成功", }); } else { add({ content: res.msg, }); } }); } useEffect(() => { getInfo().then((res) => { if (!res) { setFailed(true); return; } const { image, ...othors } = res; setValues(othors); setImgs(res.images); setCurrentImg(0); }) }, []); return (

添加手办

{imgs.map((item, index) => ( setCurrentImg(index)} /> ))}
); } export default Toy;