Skip to content

Commit 3e8f2ce

Browse files
committed
✨ 菜单自动隐藏配置 #269
1 parent b8f679d commit 3e8f2ce

4 files changed

Lines changed: 61 additions & 3 deletions

File tree

src/locales/zh-CN/translation.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,7 @@
351351
"guide_setting_sync_content": "脚本同步功能可以方便的将本设备的脚本内容同步至云端,如果有多台设备请勾选同步删除选项,当本设备脚本删除时,会从云端删除对应的脚本,也会将其它设备的脚本删除。",
352352
"auto": "自动",
353353
"hide": "隐藏",
354-
"resize_column_width": "调整列宽"
354+
"resize_column_width": "调整列宽",
355+
"collapse": "收起",
356+
"expand": "展开"
355357
}

src/pages/components/ScriptMenuList/index.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-nested-ternary */
12
import React, { useEffect, useState } from "react";
23
import MessageInternal from "@App/app/message/internal";
34
import { MessageSender } from "@App/app/message/message";
@@ -12,6 +13,8 @@ import {
1213
Switch,
1314
} from "@arco-design/web-react";
1415
import {
16+
IconCaretDown,
17+
IconCaretUp,
1518
IconDelete,
1619
IconEdit,
1720
IconMenu,
@@ -24,6 +27,7 @@ import { SCRIPT_RUN_STATUS_RUNNING } from "@App/app/repo/scripts";
2427
import { RiPlayFill, RiStopFill } from "react-icons/ri";
2528
import RuntimeController from "@App/runtime/content/runtime";
2629
import { useTranslation } from "react-i18next";
30+
import { SystemConfig } from "@App/pkg/config/config";
2731

2832
const CollapseItem = Collapse.Item;
2933

@@ -49,6 +53,10 @@ const ScriptMenuList: React.FC<{
4953
const message = IoC.instance(MessageInternal) as MessageInternal;
5054
const scriptCtrl = IoC.instance(ScriptController) as ScriptController;
5155
const runtimeCtrl = IoC.instance(RuntimeController) as RuntimeController;
56+
const systemConfig = IoC.instance(SystemConfig) as SystemConfig;
57+
const [expandMenuIndex, setExpandMenuIndex] = useState<{
58+
[key: string]: boolean;
59+
}>({});
5260
const { t } = useTranslation();
5361

5462
let url: URL;
@@ -95,10 +103,13 @@ const ScriptMenuList: React.FC<{
95103
window.close();
96104
};
97105
// 监听菜单按键
106+
107+
// 菜单展开
108+
98109
return (
99110
<>
100111
{list.length === 0 && <Empty />}
101-
{list.map((item) => (
112+
{list.map((item, index) => (
102113
<Collapse bordered={false} expandIconPosition="right" key={item.id}>
103114
<CollapseItem
104115
header={
@@ -246,7 +257,13 @@ const ScriptMenuList: React.FC<{
246257
className="arco-collapse-item-content-box flex flex-col"
247258
style={{ padding: "0 0 0 40px" }}
248259
>
249-
{item.menus?.map((menu) => {
260+
{/* 判断菜单数量,再判断是否展开 */}
261+
{(item.menus && item.menus?.length > systemConfig.menuExpandNum
262+
? expandMenuIndex[index]
263+
? item.menus
264+
: item.menus?.slice(0, systemConfig.menuExpandNum)
265+
: item.menus
266+
)?.map((menu) => {
250267
if (menu.accessKey) {
251268
document.addEventListener("keypress", (e) => {
252269
if (e.key.toUpperCase() === menu.accessKey!.toUpperCase()) {
@@ -269,6 +286,24 @@ const ScriptMenuList: React.FC<{
269286
</Button>
270287
);
271288
})}
289+
{item.menus && item.menus?.length > systemConfig.menuExpandNum && (
290+
<Button
291+
className="text-left"
292+
key="expand"
293+
type="secondary"
294+
icon={
295+
expandMenuIndex[index] ? <IconCaretUp /> : <IconCaretDown />
296+
}
297+
onClick={() => {
298+
setExpandMenuIndex({
299+
...expandMenuIndex,
300+
[index]: !expandMenuIndex[index],
301+
});
302+
}}
303+
>
304+
{expandMenuIndex[index] ? t("collapse") : t("expand")}
305+
</Button>
306+
)}
272307
{item.hasUserConfig && (
273308
<Button
274309
className="text-left"

src/pages/options/routes/Setting.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ function Setting() {
9595
))}
9696
</Select>
9797
</Space>
98+
<Space>
99+
菜单项超过
100+
<Input
101+
style={{ width: "64px" }}
102+
type="number"
103+
defaultValue={systemConfig.menuExpandNum.toString()}
104+
onChange={(val) => {
105+
systemConfig.menuExpandNum = parseInt(val, 10);
106+
}}
107+
/>
108+
个时,自动隐藏
109+
</Space>
98110
</Space>
99111
</Card>
100112
<Card className="sync" title={t("script_sync")} bordered={false}>

src/pkg/config/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,13 @@ export class SystemConfig {
271271
set scriptListColumnWidth(val: { [key: string]: number }) {
272272
this.set("script_list_column_width", val);
273273
}
274+
275+
// 展开菜单数
276+
get menuExpandNum() {
277+
return <number>this.cache.get("menu_expand_num") || 5;
278+
}
279+
280+
set menuExpandNum(val: number) {
281+
this.set("menu_expand_num", val);
282+
}
274283
}

0 commit comments

Comments
 (0)