diff --git a/components/ui/tab/index.tsx b/components/ui/tab/index.tsx
new file mode 100644
index 0000000..54b8333
--- /dev/null
+++ b/components/ui/tab/index.tsx
@@ -0,0 +1,38 @@
+import { IconBack } from "~assets/icons";
+import type { ReactNode, PropsWithChildren } from "react";
+
+import styles from "./tab.module.less";
+
+interface HeaderProps {
+ title: ReactNode;
+ onBack: () => void;
+}
+
+function Tab({ children }: PropsWithChildren) {
+ return (
+
+ {children}
+
+ );
+}
+
+Tab.Header = function Header({ title, onBack }: HeaderProps) {
+ return (
+
+ );
+}
+
+Tab.Body = function Body({ children }: PropsWithChildren) {
+ return (
+
+ {children}
+
+ );
+}
+
+export default Tab;
diff --git a/components/ui/tab/tab.module.less b/components/ui/tab/tab.module.less
new file mode 100644
index 0000000..f9b194c
--- /dev/null
+++ b/components/ui/tab/tab.module.less
@@ -0,0 +1,30 @@
+.tab {
+ .header {
+ padding: .75em;
+ position: relative;
+ text-align: center;
+ border-bottom: 1px solid #eee;
+
+ .back {
+ top: 0;
+ left: 0;
+ bottom: 0;
+ width: 2em;
+ font-size: 1.3em;
+ position: absolute;
+ transition: background-color .3s;
+
+ &:hover {
+ background-color: #eee;
+ }
+
+ svg {
+ width: 1em;
+ }
+ }
+ }
+
+ .body {
+ padding: 1em;
+ }
+}
diff --git a/popup/bili.module.less b/popup/bili.module.less
index 8fd02dc..eef7058 100644
--- a/popup/bili.module.less
+++ b/popup/bili.module.less
@@ -1,5 +1,6 @@
.bili {
gap: 1em;
+ width: 600px;
display: flex;
.image {
diff --git a/popup/bili.tsx b/popup/bili.tsx
index 4299bba..9eccce8 100644
--- a/popup/bili.tsx
+++ b/popup/bili.tsx
@@ -1,12 +1,12 @@
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 Tab from "~components/ui/tab";
+import Form from "~components/ui/form";
import { add } from "~components/ui/message/utils";
+import Placeholder from "~components/ui/placeholder";
+
+import styles from "./bili.module.less";
interface ReadProps {
onBack: () => void;
@@ -45,7 +45,6 @@ function Toy({ onBack }: ReadProps) {
const [imgs, setImgs] = useState([]);
const [currentImg, setCurrentImg] = useState(0);
- const [failed, setFailed] = useState(false);
const submitForm = (body: FormValue) => {
sendToBackground({
@@ -74,37 +73,35 @@ function Toy({ onBack }: ReadProps) {
useEffect(() => {
getInfo().then((res) => {
if (!res) {
- setFailed(true);
return;
}
- const { image, ...othors } = res;
+ const { images, ...others } = res;
- setValues(othors);
- setImgs(res.images);
+ setImgs(images);
setCurrentImg(0);
+
+ // ! 必须等组件渲染出来才能设置值,这里是个问题
+ window.requestAnimationFrame(() => {
+ setValues(others);
+ });
})
}, []);
return (
-
-
-
-
-
+
+
+
+
+

-
+
{imgs.map((item, index) => (

setCurrentImg(index)} />
))}
-
- {count}
-
-
-
+
+
);
}