feat: download 模块到本地

This commit is contained in:
熊潇 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 ( return (
<div className='flex w-full h-full bg-slate-200'> <div className='flex w-full h-full bg-slate-200'>
<div className='h-full bg-white flex-shrink-0 flex justify-center'> <div className='h-full p-2 bg-white flex-shrink-0 flex justify-center'>
<Button className='m-4' onClick={() => chatPromptStore.setShowEdit(true)} icon={<PlusOutlined />}></Button> <Button className='' onClick={() => chatPromptStore.setShowEdit(true)} icon={<PlusOutlined />}></Button>
</div> </div>
<div className='p-4'> <div className='p-4'>
<div className='flex flex-wrap gap-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 { useNavigate } from 'react-router';
import { useToCodeEditor } from '@/pages/code-editor'; import { useToCodeEditor } from '@/pages/code-editor';
import { CardBlank } from '@/components/card/CardBlank'; 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 { isObjectNull } from '@/utils/is-null';
import { PublishFormModal } from './modal/PublishFormModal'; import { PublishFormModal } from './modal/PublishFormModal';
@ -100,6 +109,7 @@ export const List = () => {
getList: state.getList, getList: state.getList,
loading: state.loading, loading: state.loading,
setShowPublishModal: state.setShowPublishModal, setShowPublishModal: state.setShowPublishModal,
downloadData: state.downloadData,
}; };
}), }),
); );
@ -108,11 +118,10 @@ export const List = () => {
}, []); }, []);
return ( 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'> <div className='p-2 bg-white rounded-r-lg'>
<Button <Button
className='w-10 ' className='w-10 '
type='primary'
icon={<PlusOutlined />} icon={<PlusOutlined />}
onClick={() => { onClick={() => {
editStore.setFormData({}); editStore.setFormData({});
@ -172,6 +181,14 @@ export const List = () => {
icon={<CloudUploadOutlined />} icon={<CloudUploadOutlined />}
/> />
</Tooltip> </Tooltip>
<Tooltip title='Download'>
<Button
onClick={() => {
editStore.downloadData(item.id);
}}
icon={<CloudDownloadOutlined />}
/>
</Tooltip>
<Tooltip title='delete'> <Tooltip title='delete'>
<Button <Button
onClick={(e) => { onClick={(e) => {

View File

@ -16,6 +16,7 @@ type EditStore = {
showPublishModal: boolean; showPublishModal: boolean;
setShowPublishModal: (showPublishModal: boolean) => void; setShowPublishModal: (showPublishModal: boolean) => void;
publishData: (data: any) => Promise<void>; publishData: (data: any) => Promise<void>;
downloadData: (data: any) => Promise<void>;
}; };
export const useEditStore = create<EditStore>((set, get) => { export const useEditStore = create<EditStore>((set, get) => {
return { return {
@ -73,6 +74,20 @@ export const useEditStore = create<EditStore>((set, get) => {
message.error(res.message || 'Request failed'); 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) => { deleteData: async (id) => {
const { getList } = get(); const { getList } = get();
const res = await query.post({ const res = await query.post({

View File

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

View File

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