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={} /> , + +