From 64fcbff71546ee1a2143839de100b459626a1657 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 26 Feb 2025 01:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=AF=E9=A2=84=E8=A7=88=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/notify.ts | 2 +- src/locales/en-US.json | 1 + src/locales/zh-CN.json | 1 + src/pages/script/index.tsx | 33 ++++++++++++++++++++++++--------- src/utils/monaco/index.ts | 7 +++++++ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/utils/monaco/index.ts diff --git a/back/services/notify.ts b/back/services/notify.ts index 5386fce71dd..feb5c482ab6 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -801,7 +801,7 @@ export default class NotificationService { webhookContentType, } = this.params; - if (!webhookUrl.includes('$title') && !webhookBody.includes('$title')) { + if (!webhookUrl?.includes('$title') && !webhookBody?.includes('$title')) { throw new Error('Url 或者 Body 中必须包含 $title'); } diff --git a/src/locales/en-US.json b/src/locales/en-US.json index cdbe2fb36ba..84f4fc02826 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -186,6 +186,7 @@ "秒后重试": "Retry after seconds", "在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "Open the two-factor authentication application on your device to view your authentication code and verify your identity.", "请选择脚本文件": "Please select a script file", + "当前文件不支持预览": "The current file does not support preview", "清空日志": "Clear Logs", "设置": "Settings", "退出": "Exit", diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index f947eee340c..1acd1cb1b65 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -186,6 +186,7 @@ "秒后重试": "秒后重试", "在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。": "在您的设备上打开两步验证应用程序以查看您的身份验证代码并验证您的身份。", "请选择脚本文件": "请选择脚本文件", + "当前文件不支持预览": "当前文件不支持预览", "清空日志": "清空日志", "设置": "设置", "退出": "退出", diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index c420b69c85c..0559d28f78b 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -46,6 +46,7 @@ import RenameModal from './renameModal'; import { langs } from '@uiw/codemirror-extensions-langs'; import { useHotkeys } from 'react-hotkeys-hook'; import prettyBytes from 'pretty-bytes'; +import { canPreviewInMonaco } from '@/utils/monaco'; const { Text } = Typography; const Script = () => { @@ -67,6 +68,10 @@ const Script = () => { const [currentNode, setCurrentNode] = useState(); const [expandedKeys, setExpandedKeys] = useState([]); + const handleIsEditing = (filename: string, value: boolean) => { + setIsEditing(value && canPreviewInMonaco(filename)); + }; + const getScripts = (needLoading: boolean = true) => { needLoading && setLoading(true); request @@ -128,6 +133,11 @@ const Script = () => { return; } + if (!canPreviewInMonaco(node.title)) { + setValue(intl.get('当前文件不支持预览')); + return; + } + const newMode = getEditorMode(value); setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode); setValue(intl.get('加载中...')); @@ -149,14 +159,14 @@ const Script = () => { content: <>{intl.get('当前修改未保存,确定离开吗')}, onOk() { onSelect(keys[0], e.node); - setIsEditing(false); + handleIsEditing(e.node.title, false); }, onCancel() { console.log('Cancel'); }, }); } else { - setIsEditing(false); + handleIsEditing(e.node.title, false); onSelect(keys[0], e.node); } }, @@ -196,18 +206,18 @@ const Script = () => { if (node.type === 'file') { setSelect(node.key); setCurrentNode(node); - setIsEditing(true); + handleIsEditing(node.title, true); } }; const editFile = () => { setTimeout(() => { - setIsEditing(true); + handleIsEditing(currentNode.title, true); }, 300); }; const cancelEdit = () => { - setIsEditing(false); + handleIsEditing(currentNode.title, false); setValue(intl.get('加载中...')); getDetail(currentNode); }; @@ -240,7 +250,7 @@ const Script = () => { if (code === 200) { message.success(`保存成功`); setValue(content); - setIsEditing(false); + handleIsEditing(currentNode.title, false); } resolve(null); }) @@ -342,7 +352,7 @@ const Script = () => { } setData(newData); onSelect(_file.title, _file); - setIsEditing(true); + handleIsEditing(_file.title, true); } setIsAddFileModalVisible(false); }; @@ -472,7 +482,9 @@ const Script = () => { label: intl.get('编辑'), key: 'edit', icon: , - disabled: !select, + disabled: + !select || + (currentNode && !canPreviewInMonaco(currentNode?.title)), }, { label: intl.get('重命名'), @@ -554,7 +566,10 @@ const Script = () => { ,