diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 522ae8ae..52ada7fa 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -186,7 +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", + "当前文件不支持预览": "Current file type is not supported for preview", "清空日志": "Clear Logs", "设置": "Settings", "退出": "Exit", @@ -501,5 +501,9 @@ "常规定时": "Normal Timing", "手动运行": "Manual Run", "开机运行": "Boot Run", - "时区": "Timezone" + "时区": "Timezone", + "强制打开": "Force Open", + "强制打开可能会导致编辑器显示异常": "Force opening may cause display issues in the editor", + "确认离开": "Confirm Leave", + "当前文件未保存,确认离开吗": "Current file is not saved, are you sure to leave?" } diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json index d6059568..e56e8cad 100644 --- a/src/locales/zh-CN.json +++ b/src/locales/zh-CN.json @@ -501,6 +501,10 @@ "常规定时": "常规定时", "手动运行": "手动运行", "开机运行": "开机运行", - "时区": "时区" + "时区": "时区", + "强制打开": "强制打开", + "强制打开可能会导致编辑器显示异常": "强制打开可能会导致编辑器显示异常", + "确认离开": "确认离开", + "当前文件未保存,确认离开吗": "当前文件未保存,确认离开吗" } \ No newline at end of file diff --git a/src/pages/crontab/detail.tsx b/src/pages/crontab/detail.tsx index 3e25ee76..82d7e24f 100644 --- a/src/pages/crontab/detail.tsx +++ b/src/pages/crontab/detail.tsx @@ -202,9 +202,6 @@ const CronDetailModal = ({ .catch((e) => reject(e)); }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -232,9 +229,6 @@ const CronDetailModal = ({ } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -259,9 +253,6 @@ const CronDetailModal = ({ } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -298,9 +289,6 @@ const CronDetailModal = ({ } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -337,9 +325,6 @@ const CronDetailModal = ({ } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 5f81c517..7ef02f72 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -20,7 +20,7 @@ import { PushpinOutlined, SettingOutlined, StopOutlined, - UnorderedListOutlined + UnorderedListOutlined, } from '@ant-design/icons'; import { PageContainer } from '@ant-design/pro-layout'; import { history, useOutletContext } from '@umijs/max'; @@ -36,7 +36,7 @@ import { TablePaginationConfig, Tabs, Tag, - Typography + Typography, } from 'antd'; import { ColumnProps } from 'antd/lib/table'; import { FilterValue, SorterResult } from 'antd/lib/table/interface'; @@ -453,9 +453,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -488,9 +485,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -524,9 +518,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -569,9 +560,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -614,9 +602,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -738,9 +723,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -766,9 +748,6 @@ const Crontab = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/crontab/viewManageModal.tsx b/src/pages/crontab/viewManageModal.tsx index 4c405de1..99325bd6 100644 --- a/src/pages/crontab/viewManageModal.tsx +++ b/src/pages/crontab/viewManageModal.tsx @@ -85,7 +85,7 @@ const ViewManageModal = ({ title: intl.get('名称'), dataIndex: 'name', key: 'name', - render: (v) => (v === '全部任务' ? intl.get('全部任务') : v) + render: (v) => (v === '全部任务' ? intl.get('全部任务') : v), }, { title: intl.get('类型'), @@ -162,9 +162,6 @@ const ViewManageModal = ({ } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/dependence/index.tsx b/src/pages/dependence/index.tsx index 2c6cdfcf..b48d90c0 100644 --- a/src/pages/dependence/index.tsx +++ b/src/pages/dependence/index.tsx @@ -315,9 +315,6 @@ const Dependence = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -342,9 +339,6 @@ const Dependence = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -367,9 +361,6 @@ const Dependence = () => { getDependencies(); }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -419,9 +410,6 @@ const Dependence = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -439,9 +427,6 @@ const Dependence = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/env/index.tsx b/src/pages/env/index.tsx index 30f2b821..750315a7 100644 --- a/src/pages/env/index.tsx +++ b/src/pages/env/index.tsx @@ -292,9 +292,6 @@ const Env = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -337,9 +334,6 @@ const Env = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -456,9 +450,6 @@ const Env = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -484,9 +475,6 @@ const Env = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/log/index.tsx b/src/pages/log/index.tsx index 549b0ea3..6cdf6f43 100644 --- a/src/pages/log/index.tsx +++ b/src/pages/log/index.tsx @@ -175,9 +175,6 @@ const Log = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; diff --git a/src/pages/script/components/UnsupportedFilePreview/index.module.less b/src/pages/script/components/UnsupportedFilePreview/index.module.less new file mode 100644 index 00000000..8f28ebce --- /dev/null +++ b/src/pages/script/components/UnsupportedFilePreview/index.module.less @@ -0,0 +1,67 @@ +.container { + height: 100%; + display: flex; + align-items: center; + justify-content: center; + background: var(--background-color); + padding: 16px; +} + +.content { + text-align: center; + background: var(--card-background); + padding: 24px; + border-radius: 12px; + max-width: 360px; + width: 100%; + transition: all 0.3s ease; +} + +.iconWrapper { + display: inline-flex; + align-items: center; + justify-content: center; + width: 64px; + height: 64px; + border-radius: 50%; + background: var(--background-color); + margin-bottom: 16px; +} + +.icon { + font-size: 32px; + color: var(--text-color-secondary); +} + +.message { + font-size: 16px; + color: var(--text-color); + margin-bottom: 16px; + font-weight: 500; + line-height: 1.5; +} + +.actionArea { + width: 100%; +} + +.button { + min-width: 140px; + height: 36px; + font-size: 14px; +} + +.warning { + font-size: 13px; + color: var(--text-color-secondary); + line-height: 1.5; + display: flex; + align-items: center; + justify-content: center; + gap: 6px; +} + +.warningIcon { + font-size: 14px; + color: #faad14; +} \ No newline at end of file diff --git a/src/pages/script/components/UnsupportedFilePreview/index.tsx b/src/pages/script/components/UnsupportedFilePreview/index.tsx new file mode 100644 index 00000000..4cac37ff --- /dev/null +++ b/src/pages/script/components/UnsupportedFilePreview/index.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import { Button, Space } from 'antd'; +import { FileUnknownOutlined, WarningOutlined } from '@ant-design/icons'; +import intl from 'react-intl-universal'; +import styles from './index.module.less'; + +interface UnsupportedFilePreviewProps { + onForceOpen: () => void; +} + +const UnsupportedFilePreview: React.FC = ({ + onForceOpen, +}) => { + return ( +
+
+
+ +
+
+ {intl.get('当前文件不支持预览')} +
+ + +
+ + {intl.get('强制打开可能会导致编辑器显示异常')} +
+
+
+
+ ); +}; + +export default UnsupportedFilePreview; \ No newline at end of file diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index 8bc2a34e..af76b006 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -43,6 +43,7 @@ import EditModal from './editModal'; import EditScriptNameModal from './editNameModal'; import styles from './index.module.less'; import RenameModal from './renameModal'; +import UnsupportedFilePreview from './components/UnsupportedFilePreview'; const { Text } = Typography; const Script = () => { @@ -63,6 +64,7 @@ const Script = () => { useState(false); const [currentNode, setCurrentNode] = useState(); const [expandedKeys, setExpandedKeys] = useState([]); + const [showMonaco, setShowMonaco] = useState(true); const handleIsEditing = (filename: string, value: boolean) => { setIsEditing(value && canPreviewInMonaco(filename)); @@ -82,7 +84,7 @@ const Script = () => { .finally(() => needLoading && setLoading(false)); }; - const getDetail = (node: any) => { + const getDetail = (node: any, options: any = {}) => { request .get( `${config.apiPrefix}scripts/detail?file=${encodeURIComponent( @@ -92,6 +94,9 @@ const Script = () => { .then(({ code, data }) => { if (code === 200) { setValue(data); + if (options.callback) { + options.callback(); + } } }); }; @@ -126,7 +131,7 @@ const Script = () => { if (item) { obj.node = item; setExpandedKeys([p as string]); - onTreeSelect([vkey], obj); + onSelect([vkey], obj); } } }; @@ -141,18 +146,27 @@ const Script = () => { if (node.type === 'directory') { setValue(intl.get('请选择脚本文件')); + setShowMonaco(true); return; } if (!canPreviewInMonaco(node.title)) { - setValue(intl.get('当前文件不支持预览')); + setShowMonaco(false); return; } + setShowMonaco(true); const newMode = getEditorMode(value); setMode(isPhone && newMode === 'typescript' ? 'javascript' : newMode); setValue(intl.get('加载中...')); - getDetail(node); + + getDetail(node, { + callback: () => { + if (isEditing) { + setIsEditing(true); + } + }, + }); }; const onTreeSelect = useCallback( @@ -161,20 +175,20 @@ const Script = () => { if (node.key === select && isEditing) { return; } - const content = editorRef.current + + const currentContent = editorRef.current ? editorRef.current.getValue().replace(/\r\n/g, '\n') : value; - if (content !== value) { + const originalContent = value.replace(/\r\n/g, '\n'); + + if (currentContent !== originalContent && isEditing) { Modal.confirm({ - title: `确认离开`, - content: <>{intl.get('当前修改未保存,确定离开吗')}, + title: intl.get('确认离开'), + content: <>{intl.get('当前文件未保存,确认离开吗')}, onOk() { onSelect(keys[0], e.node); handleIsEditing(e.node.title, false); }, - onCancel() { - console.log('Cancel'); - }, }); } else { handleIsEditing(e.node.title, false); @@ -268,9 +282,6 @@ const Script = () => { .catch((e) => reject(e)); }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -320,9 +331,6 @@ const Script = () => { } }); }, - onCancel() { - console.log('Cancel'); - }, }); }; @@ -493,7 +501,7 @@ const Script = () => { label: intl.get('编辑'), key: 'edit', icon: , - disabled: !currentNode || !canPreviewInMonaco(currentNode?.title), + disabled: !currentNode, }, { label: intl.get('重命名'), @@ -514,6 +522,20 @@ const Script = () => { }, }; + const handleForceOpen = () => { + if (!currentNode) return; + + setMode('plaintext'); + setValue(intl.get('加载中...')); + setShowMonaco(true); + + getDetail(currentNode, { + callback: () => { + setIsEditing(true); + }, + }); + }; + return ( { ,