From f1a51638a570d9519acf1dff7b805d3896c4d999 Mon Sep 17 00:00:00 2001 From: whyour Date: Mon, 16 May 2022 01:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9antd=20Menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/index.tsx | 10 ++-- src/pages/crontab/index.tsx | 48 +++++++---------- src/pages/script/index.tsx | 89 +++++++++++++++++++++----------- src/pages/setting/security.tsx | 1 + src/pages/subscription/index.tsx | 35 ++++++------- 5 files changed, 101 insertions(+), 82 deletions(-) diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 7cf3108c..726b987a 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -213,11 +213,11 @@ export default function (props: any) { const isQQBrowser = navigator.userAgent.includes('QQBrowser'); const menu = ( - - } onClick={logout}> - 退出登录 - - + }]} + onClick={logout} + /> ); return loading ? ( diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 1015e5cf..23b2dde0 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -627,6 +627,24 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => { }); }; + const getMenuItems = (record: any) => { + return [ + { label: '编辑', key: 'edit', icon: }, + { + label: record.isDisabled === 1 ? '启用' : '禁用', + key: 'enableOrDisable', + icon: + record.isDisabled === 1 ? : , + }, + { label: '删除', key: 'delete', icon: }, + { + label: record.isPinned === 1 ? '取消置顶' : '置顶', + key: 'pinOrUnPin', + icon: record.isPinned === 1 ? : , + }, + ]; + }; + const MoreBtn: React.FC<{ record: any; index: number; @@ -637,38 +655,12 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => { trigger={['click']} overlay={ { domEvent.stopPropagation(); action(key, record, index); }} - > - }> - 编辑 - - - ) : ( - - ) - } - > - {record.isDisabled === 1 ? '启用' : '禁用'} - - }> - 删除 - - : - } - > - {record.isPinned === 1 ? '取消置顶' : '置顶'} - - + /> } > e.stopPropagation()}> diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index 8e71939e..4b96b970 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -367,37 +367,68 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { } }, []); + const action = (key: string | number) => { + switch (key) { + case 'save': + saveFile(); + break; + case 'exit': + cancelEdit(); + break; + default: + break; + } + }; + + const menuAction = (key: string | number) => { + switch (key) { + case 'save': + addFile(); + break; + case 'edit': + editFile(); + break; + case 'delete': + deleteFile(); + break; + default: + break; + } + }; + const menu = isEditing ? ( - - } onClick={saveFile}> - 保存 - - } onClick={cancelEdit}> - 退出编辑 - - + }, + { label: '退出编辑', key: 'exit', icon: }, + ]} + onClick={({ key, domEvent }) => { + domEvent.stopPropagation(); + action(key); + }} + /> ) : ( - - } onClick={addFile}> - 新建 - - } - onClick={editFile} - disabled={!select} - > - 编辑 - - } - onClick={deleteFile} - disabled={!select} - > - 删除 - - + }, + { + label: '编辑', + key: 'edit', + icon: , + disabled: !select, + }, + { + label: '删除', + key: 'delete', + icon: , + disabled: !select, + }, + ]} + onClick={({ key, domEvent }) => { + domEvent.stopPropagation(); + menuAction(key); + }} + /> ); return ( diff --git a/src/pages/setting/security.tsx b/src/pages/setting/security.tsx index 25a45226..8e3ab7e2 100644 --- a/src/pages/setting/security.tsx +++ b/src/pages/setting/security.tsx @@ -93,6 +93,7 @@ const SecuritySettings = ({ user, userChange }: any) => { const onChange = (e) => { if (e.file && e.file.response) { setAvatar(`/api/static/${e.file.response.data}`); + userChange(); } }; diff --git a/src/pages/subscription/index.tsx b/src/pages/subscription/index.tsx index b0f86d60..261524d9 100644 --- a/src/pages/subscription/index.tsx +++ b/src/pages/subscription/index.tsx @@ -393,30 +393,25 @@ const Subscription = ({ headerStyle, isPhone, theme }: any) => { trigger={['click']} overlay={ }, + { + label: record.is_disabled === 1 ? '启用' : '禁用', + key: 'enableOrDisable', + icon: + record.is_disabled === 1 ? ( + + ) : ( + + ), + }, + { label: '删除', key: 'delete', icon: }, + ]} onClick={({ key, domEvent }) => { domEvent.stopPropagation(); action(key, record, index); }} - > - }> - 编辑 - - - ) : ( - - ) - } - > - {record.is_disabled === 1 ? '启用' : '禁用'} - - }> - 删除 - - + /> } > e.stopPropagation()}>