feat: download 模块到本地

This commit is contained in:
xion 2024-10-08 17:11:13 +08:00
parent 1c39c74350
commit 7747dcbea6
5 changed files with 52 additions and 12 deletions

View File

@ -113,8 +113,8 @@ export const List = () => {
}, []);
return (
<div className='flex w-full h-full bg-slate-200'>
<div className='h-full bg-white flex-shrink-0 flex justify-center'>
<Button className='m-4' onClick={() => chatPromptStore.setShowEdit(true)} icon={<PlusOutlined />}></Button>
<div className='h-full p-2 bg-white flex-shrink-0 flex justify-center'>
<Button className='' onClick={() => chatPromptStore.setShowEdit(true)} icon={<PlusOutlined />}></Button>
</div>
<div className='p-4'>
<div className='flex flex-wrap gap-4'>

View File

@ -7,7 +7,16 @@ import copy from 'copy-to-clipboard';
import { useNavigate } from 'react-router';
import { useToCodeEditor } from '@/pages/code-editor';
import { CardBlank } from '@/components/card/CardBlank';
import { CloudUploadOutlined, DeleteOutlined, EditOutlined, ForkOutlined, GoldOutlined, PlusOutlined, ToolOutlined } from '@ant-design/icons';
import {
CloudDownloadOutlined,
CloudUploadOutlined,
DeleteOutlined,
EditOutlined,
ForkOutlined,
GoldOutlined,
PlusOutlined,
ToolOutlined,
} from '@ant-design/icons';
import { isObjectNull } from '@/utils/is-null';
import { PublishFormModal } from './modal/PublishFormModal';
@ -100,6 +109,7 @@ export const List = () => {
getList: state.getList,
loading: state.loading,
setShowPublishModal: state.setShowPublishModal,
downloadData: state.downloadData,
};
}),
);
@ -108,11 +118,10 @@ export const List = () => {
}, []);
return (
<div className='w-full h-full flex'>
<div className='w-full h-full flex bg-gray-200'>
<div className='p-2 bg-white rounded-r-lg'>
<Button
className='w-10 '
type='primary'
icon={<PlusOutlined />}
onClick={() => {
editStore.setFormData({});
@ -172,6 +181,14 @@ export const List = () => {
icon={<CloudUploadOutlined />}
/>
</Tooltip>
<Tooltip title='Download'>
<Button
onClick={() => {
editStore.downloadData(item.id);
}}
icon={<CloudDownloadOutlined />}
/>
</Tooltip>
<Tooltip title='delete'>
<Button
onClick={(e) => {

View File

@ -16,6 +16,7 @@ type EditStore = {
showPublishModal: boolean;
setShowPublishModal: (showPublishModal: boolean) => void;
publishData: (data: any) => Promise<void>;
downloadData: (data: any) => Promise<void>;
};
export const useEditStore = create<EditStore>((set, get) => {
return {
@ -73,6 +74,20 @@ export const useEditStore = create<EditStore>((set, get) => {
message.error(res.message || 'Request failed');
}
},
downloadData: async (id) => {
const res = await query.post({
path: 'page',
key: 'download',
id: id,
});
if (res.code === 200) {
message.success('Success');
const url = new URL('resources/' + res.data, window.location.origin);
window.open(url.href, '_blank');
} else {
message.error(res.message || 'Request failed');
}
},
deleteData: async (id) => {
const { getList } = get();
const res = await query.post({

View File

@ -13,6 +13,7 @@ import { marked } from 'marked';
import { extractKeysFromBraces } from '@/utils/extra';
import { useAiStore } from '@/pages/ai-chat';
import { CardBlank } from '@/components/card/CardBlank';
import { isObjectNull } from '@/utils/is-null';
const FormModal = () => {
const [form] = Form.useForm();
@ -30,14 +31,13 @@ const FormModal = () => {
useEffect(() => {
const open = promptStore.showEdit;
if (open) {
const isNull = JSON.stringify(promptStore.formData) === '{}';
if (isNull) {
form.resetFields();
if (isObjectNull(promptStore.formData)) {
form.setFieldsValue({});
} else {
form.setFieldsValue(promptStore.formData || {});
}
}
}, [promptStore.showEdit]);
}, [promptStore.showEdit, promptStore.formData]);
const onFinish = async (values: any) => {
let other = {};
if (!values.id) {
@ -172,7 +172,9 @@ export const List = () => {
return (
<div className='w-full h-full flex flex-col'>
<div className='flex flex-grow overflow-hidden h-full'>
<Button onClick={onAdd} type='primary' className='m-4 w-64 flex-shrink-0' icon={<PlusOutlined />}></Button>
<div className='p-2 bg-white'>
<Button onClick={onAdd} icon={<PlusOutlined />}></Button>
</div>
<div className='flex-grow overflow-auto scrollbar bg-gray-100'>
<div className='flex flex-wrap gap-x-10 gap-y-4 rounded pt-10 justify-center'>
{promptStore.list.length > 0 &&
@ -249,8 +251,9 @@ export const List = () => {
<Button
icon={<CaretRightOutlined />}
onClick={() => {
aiStore.setKey(location.pathname);
aiStore.setOpen(true);
// aiStore.setKey(location.pathname);
// aiStore.setOpen(true);
message.error('Not implemented');
}}
/>
</Button.Group>

View File

@ -42,6 +42,11 @@ export default defineConfig({
rewriteWsOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api'),
},
'/resources': {
target: 'https://envision.xiongxiao.me',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/resources/, '/resources'),
},
},
},
});