From a2d9f1a5dbf740ea6e6289f191ae47e3ed0edad8 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 27 Dec 2022 16:02:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=AE=A1=E7=90=86=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=87=8D=E5=91=BD=E5=90=8D=E6=96=87=E4=BB=B6/?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/script.ts | 27 +++++++++++ src/components/iconfont.tsx | 2 +- src/pages/script/index.tsx | 41 +++++++++++++++-- src/pages/script/renameModal.tsx | 79 ++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 src/pages/script/renameModal.tsx diff --git a/back/api/script.ts b/back/api/script.ts index d13e4245..9dec7f93 100644 --- a/back/api/script.ts +++ b/back/api/script.ts @@ -274,4 +274,31 @@ export default (app: Router) => { } }, ); + + route.put( + '/rename', + celebrate({ + body: Joi.object({ + filename: Joi.string().required(), + path: Joi.string().allow(''), + newFilename: Joi.string().required(), + }), + }), + async (req: Request, res: Response, next: NextFunction) => { + try { + let { filename, path, type, newFilename } = req.body as { + filename: string; + path: string; + type: string; + newFilename: string; + }; + const filePath = join(config.scriptPath, path, filename); + const newPath = join(config.scriptPath, path, newFilename); + fs.renameSync(filePath, newPath); + res.send({ code: 200 }); + } catch (e) { + return next(e); + } + }, + ); }; diff --git a/src/components/iconfont.tsx b/src/components/iconfont.tsx index 1bab8044..03f9afb1 100644 --- a/src/components/iconfont.tsx +++ b/src/components/iconfont.tsx @@ -1,7 +1,7 @@ import { createFromIconfontCN } from '@ant-design/icons'; const IconFont = createFromIconfontCN({ - scriptUrl: ['//at.alicdn.com/t/c/font_3354854_z0d9rbri1ci.js'], + scriptUrl: ['//at.alicdn.com/t/c/font_3354854_ob5y15ewlyq.js'], }); export default IconFont; diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index 4c054714..5331d4ff 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -39,6 +39,8 @@ import { depthFirstSearch } from '@/utils'; import { SharedContext } from '@/layouts'; import useFilterTreeData from '@/hooks/useFilterTreeData'; import uniq from 'lodash/uniq'; +import IconFont from '@/components/iconfont'; +import RenameModal from './renameModal'; const { Text } = Typography; @@ -64,20 +66,22 @@ const Script = () => { const [isEditing, setIsEditing] = useState(false); const editorRef = useRef(null); const [isAddFileModalVisible, setIsAddFileModalVisible] = useState(false); + const [isRenameFileModalVisible, setIsRenameFileModalVisible] = useState(false); const [currentNode, setCurrentNode] = useState(); const [expandedKeys, setExpandedKeys] = useState([]); - const getScripts = () => { - setLoading(true); + const getScripts = (needLoading: boolean = true) => { + needLoading && setLoading(true); request .get(`${config.apiPrefix}scripts`) .then(({ code, data }) => { if (code === 200) { setData(data); + initState(); initGetScript(); } }) - .finally(() => setLoading(false)); + .finally(() => needLoading && setLoading(false)); }; const getDetail = (node: any) => { @@ -287,6 +291,15 @@ const Script = () => { }); }; + const renameFile = () => { + setIsRenameFileModalVisible(true); + } + + const handleRenameFileCancel = () => { + setIsRenameFileModalVisible(false); + getScripts(false); + } + const addFile = () => { setIsAddFileModalVisible(true); }; @@ -381,6 +394,9 @@ const Script = () => { case 'delete': deleteFile(); break; + case 'rename': + renameFile(); + break; default: break; } @@ -407,6 +423,12 @@ const Script = () => { icon: , disabled: !select, }, + { + label: '重命名', + key: 'rename', + icon: , + disabled: !select, + }, { label: '删除', key: 'delete', @@ -471,6 +493,14 @@ const Script = () => { icon={} /> , + +