import { sendToBackground } from "@plasmohq/messaging"; import { useEffect, useState } from "react"; import Form from "~components/ui/form"; import { IconBack } from "~assets/icons"; import styles from "./popup.module.less"; import useForm from "~hooks/useForm"; import { add } from "~components/ui/message/utils"; interface ReadProps { onBack: () => void; } interface FormValue { title: string; link: string; desc: string; tips: string; } const getInfo = async () => { const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true }); if (tab) { return await chrome.tabs.sendMessage(tab.id, { type: 'toolbox:getInfo' }); } } const submitForm = (body: FormValue) => { sendToBackground({ name: "read", body: { action: "submitAddForm", values: body, }, }).then((res) => { if (res.status === "Success") { add({ content: "提交成功", }); } else { add({ content: res.msg, }); } }); } function Read({ onBack }: ReadProps) { const [count, setCount] = useState(0); const { bindInput, setValues, onSubmit } = useForm({ initialValues: { test: 'test', }, onSubmit: (values) => { submitForm(values); }, }); useEffect(() => { getInfo().then((res) => { if (!res) { return; } setValues(res); }) }, []); return (

在看

{count}
); } export default Read;