Skip to content

Commit 66ab70f

Browse files
committed
🐛 修复弹出页面中后台脚本不展开的问题
1 parent 5073795 commit 66ab70f

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/pages/popup/App.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable prettier/prettier */
21
import { Discord, DocumentationSite, ExtVersion } from "@App/app/const";
32
import { Alert, Badge, Button, Card, Collapse, Dropdown, Menu, Switch } from "@arco-design/web-react";
43
import {
@@ -33,6 +32,7 @@ const iconStyle = {
3332
};
3433

3534
function App() {
35+
const [loading, setLoading] = useState(true);
3636
const [scriptList, setScriptList] = useState<ScriptMenu[]>([]);
3737
const [backScriptList, setBackScriptList] = useState<ScriptMenu[]>([]);
3838
const [showAlert, setShowAlert] = useState(false);
@@ -44,6 +44,7 @@ function App() {
4444
const [currentUrl, setCurrentUrl] = useState("");
4545
const [isEnableScript, setIsEnableScript] = useState(true);
4646
const [isBlacklist, setIsBlacklist] = useState(false);
47+
const [collapseActiveKey, setCollapseActiveKey] = useState<string[]>(["script"]);
4748
const { t } = useTranslation();
4849

4950
let url: URL | undefined;
@@ -84,6 +85,9 @@ function App() {
8485
setBackScriptList(resp.backScriptList || []);
8586
setIsBlacklist(resp.isBlacklist || false);
8687
checkScriptEnableAndUpdate();
88+
if (resp.backScriptList.length > 0) {
89+
setCollapseActiveKey(["script", "background"]);
90+
}
8791
})
8892
.catch((error) => {
8993
console.error("Failed to get popup data:", error);
@@ -92,6 +96,10 @@ function App() {
9296
setScriptList([]);
9397
setBackScriptList([]);
9498
setIsBlacklist(false);
99+
})
100+
.finally(() => {
101+
if (!isMounted) return;
102+
setLoading(false);
95103
});
96104
};
97105

@@ -201,8 +209,7 @@ function App() {
201209
const dropdown = dropdowns[0] as HTMLElement;
202210
console.log(dropdowns, dropdown.style.top);
203211
// 如果top是负数修改为0
204-
if (parseInt(dropdown
205-
.style.top) < 0) {
212+
if (parseInt(dropdown.style.top) < 0) {
206213
dropdown.style.top = "0px";
207214
}
208215
}
@@ -261,7 +268,10 @@ function App() {
261268
/>
262269
<Collapse
263270
bordered={false}
264-
defaultActiveKey={["script", ...(backScriptList.length > 0 ? ["background"] : [])]}
271+
activeKey={collapseActiveKey}
272+
onChange={(_, keys) => {
273+
setCollapseActiveKey(keys);
274+
}}
265275
style={{ maxWidth: 640, maxHeight: 500, overflow: "auto" }}
266276
>
267277
<CollapseItem
@@ -276,7 +286,11 @@ function App() {
276286
<CollapseItem
277287
header={t("enabled_background_scripts")}
278288
name="background"
279-
style={{ padding: "0" }}
289+
style={{
290+
padding: "0",
291+
// 未加载完成前不采用动画,避免collapseActiveKey变化时闪现
292+
...(loading ? { transform: "none" } : { transform: "height 0.2s cubic-bezier(0.34, 0.69, 0.1, 1)" }),
293+
}}
280294
contentStyle={{ padding: "0" }}
281295
>
282296
<ScriptMenuList script={backScriptList} isBackscript={true} currentUrl={currentUrl} />

0 commit comments

Comments
 (0)