修复创建脚本选择目录

This commit is contained in:
whyour 2022-06-04 01:26:01 +08:00
parent 106b34e33a
commit 05d47be1c8
6 changed files with 52 additions and 36 deletions

View File

@ -9,10 +9,6 @@ export default defineConfig({
type: 'none',
},
fastRefresh: {},
// antd: {
// dark: true,
// },
mfsu: {},
esbuild: {},
webpack5: {},
dynamicImport: {

View File

@ -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

View File

@ -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,

View File

@ -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();

View File

@ -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 (
<Modal
title="新建文件"
title="新建脚本"
visible={visible}
forceRender
centered
@ -111,16 +138,14 @@ const EditScriptNameModal = ({
<Input placeholder="请输入文件名" />
</Form.Item>
)}
<Form.Item
label="父目录"
name="path"
initialValue={dirs && dirs.length > 0 ? dirs[0].key : ''}
>
<Select placeholder="请选择父目录">
{dirs.map((x) => (
<Option value={x.key}>{x.key || '根'}</Option>
))}
</Select>
<Form.Item label="父目录" name="path">
<TreeSelect
allowClear
treeData={dirs}
fieldNames={{ value: 'key', label: 'title' }}
placeholder="请选择父目录"
treeDefaultExpandAll
/>
</Form.Item>
{type === 'upload' && (
<Form.Item label="文件" name="file">

View File

@ -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) => {
<>
<Text style={{ wordBreak: 'break-all' }} type="warning">
{currentNode.value}
{currentNode.title}
</Text>{' '}
</>
@ -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);