From 05d47be1c8a91165d0fbf3f8b8fbab95051bc32f Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 4 Jun 2022 01:26:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E9=80=89=E6=8B=A9=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .umirc.ts | 4 --- back/app.ts | 4 +-- back/config/util.ts | 3 -- back/loaders/db.ts | 4 +-- src/pages/script/editNameModal.tsx | 55 ++++++++++++++++++++++-------- src/pages/script/index.tsx | 18 +++++----- 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/.umirc.ts b/.umirc.ts index 023fcb6c..e8c58209 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -9,10 +9,6 @@ export default defineConfig({ type: 'none', }, fastRefresh: {}, - // antd: { - // dark: true, - // }, - mfsu: {}, esbuild: {}, webpack5: {}, dynamicImport: { diff --git a/back/app.ts b/back/app.ts index e689b541..067d7b19 100644 --- a/back/app.ts +++ b/back/app.ts @@ -9,12 +9,12 @@ import Logger from './loaders/logger'; async function startServer() { const app = express(); + await require('./loaders/db').default(); + await require('./loaders/initFile').default(); await require('./loaders/sentry').default({ expressApp: app }); - await require('./loaders/db').default(); - await require('./loaders/app').default({ expressApp: app }); const server = app diff --git a/back/config/util.ts b/back/config/util.ts index ef4d3798..e135b98a 100644 --- a/back/config/util.ts +++ b/back/config/util.ts @@ -293,7 +293,6 @@ export function readDirs( if (stats.isDirectory()) { return { title: file, - value: file, key, type: 'directory', disabled: true, @@ -303,7 +302,6 @@ export function readDirs( } return { title: file, - value: file, type: 'file', key, parent: relativePath, @@ -327,7 +325,6 @@ export function readDir( const key = path.join(relativePath, file); return { title: file, - value: file, type: stats.isDirectory() ? 'directory' : 'file', key, parent: relativePath, diff --git a/back/loaders/db.ts b/back/loaders/db.ts index 05583362..e100abcf 100644 --- a/back/loaders/db.ts +++ b/back/loaders/db.ts @@ -18,9 +18,7 @@ export default async () => { await AppModel.sync(); await AuthModel.sync(); await EnvModel.sync(); - await SubscriptionModel.sync({ alter: true }); - - await sequelize.sync(); + await SubscriptionModel.sync(); // try { // const queryInterface = sequelize.getQueryInterface(); diff --git a/src/pages/script/editNameModal.tsx b/src/pages/script/editNameModal.tsx index 58c8687e..3165e195 100644 --- a/src/pages/script/editNameModal.tsx +++ b/src/pages/script/editNameModal.tsx @@ -1,5 +1,14 @@ import React, { useEffect, useState } from 'react'; -import { Modal, message, Input, Form, Select, Upload, Radio } from 'antd'; +import { + Modal, + message, + Input, + Form, + Select, + Upload, + Radio, + TreeSelect, +} from 'antd'; import { request } from '@/utils/http'; import config from '@/utils/config'; import { UploadOutlined } from '@ant-design/icons'; @@ -40,7 +49,7 @@ const EditScriptNameModal = ({ .then(({ code, data }) => { if (code === 200) { message.success('保存文件成功'); - const key = values.path ? `${values.path}-` : ''; + const key = values.path ? `${values.path}/` : ''; const filename = file ? file.name : values.filename; handleCancel({ filename, @@ -64,15 +73,33 @@ const EditScriptNameModal = ({ setType(e.target.value); }; + const getDirs = (data) => { + for (const item of data) { + if (item.children && item.children.length > 0) { + item.children = item.children + .filter((x) => x.type === 'directory') + .map((x) => ({ ...x, disabled: false })); + getDirs(item.children); + } + } + return data; + }; + + useEffect(() => { + const originDirs = treeData + .filter((x) => x.type === 'directory') + .map((x) => ({ ...x, disabled: false })); + const dirs = getDirs(originDirs); + setDirs(dirs); + }, [treeData]); + useEffect(() => { form.resetFields(); - const originDirs = treeData.filter((x) => x.disabled); - setDirs([{ key: '' }, ...originDirs]); }, [visible]); return ( )} - 0 ? dirs[0].key : ''} - > - + + {type === 'upload' && ( diff --git a/src/pages/script/index.tsx b/src/pages/script/index.tsx index 8140216c..d36d9ae1 100644 --- a/src/pages/script/index.tsx +++ b/src/pages/script/index.tsx @@ -104,7 +104,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { const getDetail = (node: any) => { request - .get(`${config.apiPrefix}scripts/${node.value}?path=${node.parent || ''}`) + .get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`) .then((data) => { setValue(data.data); }); @@ -117,7 +117,6 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { const obj = { node: { title: s, - value: s, key: p ? vkey : s, parent: p, }, @@ -209,7 +208,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { <> 确认保存文件 - {currentNode.value} + {currentNode.title} {' '} ,保存后不可恢复 @@ -222,7 +221,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { request .put(`${config.apiPrefix}scripts`, { data: { - filename: currentNode.value, + filename: currentNode.title, path: currentNode.parent || '', content, }, @@ -262,7 +261,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { request .delete(`${config.apiPrefix}scripts`, { data: { - filename: currentNode.value, + filename: currentNode.title, path: currentNode.parent || '', }, }) @@ -315,8 +314,9 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { ) => { if (filename) { const newData = [...data]; - const _file = { title: filename, key, value: filename, parent: path }; + const _file = { title: filename, key, parent: path }; if (path) { + // TODO: 更新左侧树数据 const parentNodeIndex = newData.findIndex((x) => x.key === path); if (parentNodeIndex !== -1) { const parentNode = newData[parentNodeIndex]; @@ -331,7 +331,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { newData.unshift(_file); } setData(newData); - onSelect(_file.value, _file); + onSelect(_file.title, _file); setIsEditing(true); } setIsAddFileModalVisible(false); @@ -341,7 +341,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { request .post(`${config.apiPrefix}scripts/download`, { data: { - filename: currentNode.value, + filename: currentNode.title, }, }) .then((_data: any) => { @@ -349,7 +349,7 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => { const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = currentNode.value; + a.download = currentNode.title; document.documentElement.appendChild(a); a.click(); document.documentElement.removeChild(a);