feat: 暂存, 添加ui2

This commit is contained in:
xion 2024-09-21 22:58:46 +08:00
parent 052dd919cd
commit 4d308921a3
14 changed files with 609 additions and 236 deletions

7
insight/readme.md Normal file
View File

@ -0,0 +1,7 @@
insight
探索研究
```
npx tsc --declaration --allowJs --emitDeclarationOnly your-file.js
```

6
insight/test.js Normal file
View File

@ -0,0 +1,6 @@
let a = 1
export const main = ({b,c}) => {
console.log('current a', a);
return a++
}

View File

@ -12,12 +12,14 @@
"deploy": "rsync -avz --delete ./dist/ light:/root/apps/envision/web" "deploy": "rsync -avz --delete ./dist/ light:/root/apps/envision/web"
}, },
"dependencies": { "dependencies": {
"@abearxiong/container": "0.0.1-alpha.0", "@abearxiong/container": "0.0.1-alpha.4",
"@abearxiong/flows": "0.0.1-alpha.8", "@abearxiong/flows": "0.0.1-alpha.9",
"@abearxiong/ui": "0.0.1-alpha.0", "@abearxiong/ui": "0.0.1-alpha.0",
"@ant-design/icons": "^5.4.0", "@ant-design/icons": "^5.5.1",
"@icon-park/react": "^1.4.2", "@icon-park/react": "^1.4.2",
"@kevisual/codemirror": "^0.0.1",
"@kevisual/query": "^0.0.2", "@kevisual/query": "^0.0.2",
"@kevisual/ui": "^0.0.2",
"@uiw/react-textarea-code-editor": "^3.0.2", "@uiw/react-textarea-code-editor": "^3.0.2",
"@xyflow/react": "^12.3.0", "@xyflow/react": "^12.3.0",
"antd": "^5.20.6", "antd": "^5.20.6",
@ -36,15 +38,15 @@
"zustand": "^4.5.5" "zustand": "^4.5.5"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.10.0", "@eslint/js": "^9.11.0",
"@tailwindcss/aspect-ratio": "^0.4.2", "@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/typography": "^0.5.15", "@tailwindcss/typography": "^0.5.15",
"@types/node": "^22.5.5", "@types/node": "^22.5.5",
"@types/react": "^18.3.7", "@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1", "@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"eslint": "^9.10.0", "eslint": "^9.11.0",
"eslint-plugin-react-hooks": "^5.1.0-rc.0", "eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.12", "eslint-plugin-react-refresh": "^0.4.12",
"globals": "^15.9.0", "globals": "^15.9.0",
@ -54,6 +56,6 @@
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"typescript": "^5.6.2", "typescript": "^5.6.2",
"typescript-eslint": "^8.6.0", "typescript-eslint": "^8.6.0",
"vite": "^5.4.6" "vite": "^5.4.7"
} }
} }

479
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ import { BrowserRouter as Router, Route, Routes, Navigate } from 'react-router-d
import { ConfigProvider } from 'antd'; import { ConfigProvider } from 'antd';
import { App as ContainerApp } from './pages/container'; import { App as ContainerApp } from './pages/container';
import { App as PanelApp } from './pages/panel'; import { App as PanelApp } from './pages/panel';
import { App as PublishApp } from './pages/publish';
export const App = () => { export const App = () => {
return ( return (
@ -15,6 +16,7 @@ export const App = () => {
<Route path='/' element={<Navigate to='/container/' />} /> <Route path='/' element={<Navigate to='/container/' />} />
<Route path='/container/*' element={<ContainerApp />} /> <Route path='/container/*' element={<ContainerApp />} />
<Route path='/panel/*' element={<PanelApp />} /> <Route path='/panel/*' element={<PanelApp />} />
<Route path='/publish/*' element={<PublishApp />} />
<Route path='/404' element={<div>404</div>} /> <Route path='/404' element={<div>404</div>} />
<Route path='*' element={<div>404</div>} /> <Route path='*' element={<div>404</div>} />
</Routes> </Routes>

View File

@ -84,6 +84,7 @@ export const ContainerList = () => {
deleteData: state.deleteData, deleteData: state.deleteData,
getList: state.getList, getList: state.getList,
loading: state.loading, loading: state.loading,
publishData: state.publishData,
}; };
}), }),
); );
@ -145,6 +146,12 @@ export const ContainerList = () => {
}}> }}>
Preview Preview
</Button> </Button>
<Button
onClick={() => {
containerStore.publishData(record);
}}>
Publish
</Button>
<Button <Button
danger danger
onClick={() => { onClick={() => {

View File

@ -12,6 +12,7 @@ type ContainerStore = {
getList: () => Promise<void>; getList: () => Promise<void>;
updateData: (data: any) => Promise<void>; updateData: (data: any) => Promise<void>;
deleteData: (id: string) => Promise<void>; deleteData: (id: string) => Promise<void>;
publishData: (data: any) => Promise<void>;
}; };
export const useContainerStore = create<ContainerStore>((set, get) => { export const useContainerStore = create<ContainerStore>((set, get) => {
return { return {
@ -65,5 +66,29 @@ export const useContainerStore = create<ContainerStore>((set, get) => {
message.error(res.msg || 'Request failed'); message.error(res.msg || 'Request failed');
} }
}, },
publishData: async (data) => {
const hasPublish = !!data.publish?.name;
const publish = {
name: 'test-import',
};
if (!hasPublish) {
console.error('need publish.name');
return;
}
const res = await query.post({
path: 'container',
key: 'publish',
data: {
id: data.id,
publish: publish,
type: 'patch',
},
});
if (res.code === 200) {
message.success('Success');
} else {
message.error(res.msg || 'Request failed');
}
},
}; };
}); });

View File

@ -1,8 +1,9 @@
import { Container } from '@abearxiong/container'; import { Container, ContainerEdit } from '@abearxiong/container';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { useParams } from 'react-router'; import { useParams } from 'react-router';
import { query } from '@/modules'; import { query } from '@/modules';
import { message } from 'antd'; import { message } from 'antd';
import '@abearxiong/container/dist/container.css';
export const Deck = () => { export const Deck = () => {
const params = useParams<{ id: string }>(); const params = useParams<{ id: string }>();
@ -78,10 +79,11 @@ export const Deck = () => {
}; };
const init = async (data: any[]) => { const init = async (data: any[]) => {
// console.log('data', data, ref.current); // console.log('data', data, ref.current);
const container = new Container({ const container = new ContainerEdit({
root: ref.current!, root: ref.current!,
data: data as any, data: data as any,
showChild: true, showChild: true,
// edit: false,
}); });
container.render(id!); container.render(id!);
containerRef.current = container; containerRef.current = container;

View File

@ -124,9 +124,15 @@ export const List = () => {
</Button> </Button>
<Button <Button
onClick={() => { onClick={() => {
navicate('/container/preview/' + record.id); navicate('/panel/flow/' + record.id);
}}> }}>
Preview Flow
</Button>
<Button
onClick={() => {
navicate('/panel/deck/' + record.id);
}}>
Deck
</Button> </Button>
<Button <Button
danger danger

View File

@ -2,12 +2,12 @@ import { useParams } from 'react-router';
import Flow from './Flow'; import Flow from './Flow';
import { usePanelStore } from '../store'; import { usePanelStore } from '../store';
import { useShallow } from 'zustand/react/shallow'; import { useShallow } from 'zustand/react/shallow';
import { useEffect } from 'react'; import { useEffect, useRef } from 'react';
import { DialogModal } from '@kevisual/ui';
import '@kevisual/ui';
export const App = () => { export const App = () => {
const param = useParams(); const param = useParams();
const id = param.id; const id = param.id;
const panel = usePanelStore( const panel = usePanelStore(
useShallow((state) => { useShallow((state) => {
return { return {

View File

@ -0,0 +1,178 @@
import { Button, Input, message, Modal, Table } from 'antd';
import { useEffect, useState } from 'react';
import { usePublishStore } from '../store';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
import { useNavigate } from 'react-router';
const FormModal = () => {
const [form] = Form.useForm();
const containerStore = usePublishStore(
useShallow((state) => {
return {
showEdit: state.showEdit,
setShowEdit: state.setShowEdit,
formData: state.formData,
updateData: state.updateData,
};
}),
);
useEffect(() => {
const open = containerStore.showEdit;
if (open) {
form.setFieldsValue(containerStore.formData || {});
} else {
form.resetFields();
}
}, [containerStore.showEdit]);
const onFinish = async (values: any) => {
containerStore.updateData(values);
};
const onClose = () => {
containerStore.setShowEdit(false);
form.resetFields();
};
const isEdit = containerStore.formData.id;
return (
<Modal
title={isEdit ? 'Edit' : 'Add'}
open={containerStore.showEdit}
onClose={() => containerStore.setShowEdit(false)}
destroyOnClose
footer={false}
width={800}
onCancel={onClose}>
<Form
form={form}
onFinish={onFinish}
labelCol={{
span: 4,
}}
wrapperCol={{
span: 20,
}}>
<Form.Item name='id' hidden>
<Input />
</Form.Item>
<Form.Item name='title' label='title'>
<Input />
</Form.Item>
<Form.Item label=' ' colon={false}>
<Button type='primary' htmlType='submit'>
Submit
</Button>
<Button className='ml-2' htmlType='reset' onClick={onClose}>
Cancel
</Button>
</Form.Item>
</Form>
</Modal>
);
};
export const List = () => {
const navicate = useNavigate();
const containerStore = usePublishStore(
useShallow((state) => {
return {
setFormData: state.setFormData,
setShowEdit: state.setShowEdit,
list: state.list,
deleteData: state.deleteData,
getList: state.getList,
loading: state.loading,
};
}),
);
useEffect(() => {
containerStore.getList();
}, []);
const columns = [
{
title: 'ID',
dataIndex: 'id',
render: (text: string) => {
return (
<div
className='w-40 truncate cursor-pointer'
title={text}
onClick={() => {
copy(text);
message.success('copy success');
}}>
{text}
</div>
);
},
},
{
title: 'Title',
dataIndex: 'title',
},
{
title: 'Source',
dataIndex: 'source',
},
{
title: 'Operation',
dataIndex: 'operation',
render: (text: string, record: any) => {
return (
<div className='flex gap-2'>
<Button
type='primary'
onClick={() => {
containerStore.setFormData(record);
containerStore.setShowEdit(true);
}}>
Edit
</Button>
<Button
onClick={() => {
navicate('/container/preview/' + record.id);
}}>
Preview
</Button>
<Button
danger
onClick={() => {
containerStore.deleteData(record.id);
}}>
Delete
</Button>
</div>
);
},
},
];
return (
<div className='w-full h-full flex flex-col'>
<div className='mb-2 w-full p-2 bg-white rounded-lg'>
<Button
className='w-20 '
type='primary'
onClick={() => {
containerStore.setFormData({});
containerStore.setShowEdit(true);
}}>
Add
</Button>
</div>
<div className='flex-grow overflow-scroll'>
<Table
pagination={false}
scroll={{
y: 600,
}}
loading={containerStore.loading}
dataSource={containerStore.list}
rowKey='id'
columns={columns}
/>
</div>
<div className='h-2'></div>
<FormModal />
</div>
);
};

View File

@ -0,0 +1,14 @@
import { Navigate, Route, Routes } from 'react-router-dom';
import { List } from './edit/List';
import { Main } from './layouts';
export const App = () => {
return (
<Routes>
<Route element={<Main />}>
<Route path='/' element={<Navigate to='/panel/edit/list' />}></Route>
<Route path='edit/list' element={<List />} />
<Route path='*' element={'Not Found'}></Route>
</Route>
</Routes>
);
};

View File

@ -0,0 +1,20 @@
import { Outlet } from 'react-router';
export const Main = () => {
return (
<div className='flex w-full h-full flex-col bg-gray-200'>
<div className='h-12 bg-white p-2 mb-2'>Deck And Flow</div>
<div
className='flex'
style={{
height: 'calc(100vh - 4rem)',
}}>
<div className='flex-grow overflow-hidden mx-2'>
<div className='w-full h-full rounded-lg'>
<Outlet />
</div>
</div>
</div>
</div>
);
};

View File

@ -0,0 +1,69 @@
import { create } from 'zustand';
import { query } from '@/modules';
import { message } from 'antd';
type Store = {
showEdit: boolean;
setShowEdit: (showEdit: boolean) => void;
formData: any;
setFormData: (formData: any) => void;
loading: boolean;
setLoading: (loading: boolean) => void;
list: any[];
getList: () => Promise<void>;
updateData: (data: any) => Promise<void>;
deleteData: (id: string) => Promise<void>;
};
export const usePublishStore = create<Store>((set, get) => {
return {
showEdit: false,
setShowEdit: (showEdit) => set({ showEdit }),
formData: {},
setFormData: (formData) => set({ formData }),
loading: false,
setLoading: (loading) => set({ loading }),
list: [],
getList: async () => {
set({ loading: true });
const res = await query.post({
path: 'resource',
key: 'list',
});
set({ loading: false });
if (res.code === 200) {
set({ list: res.data });
} else {
message.error(res.msg || 'Request failed');
}
},
updateData: async (data) => {
const { getList } = get();
const res = await query.post({
path: 'resource',
key: 'update',
data,
});
if (res.code === 200) {
message.success('Success');
set({ showEdit: false, formData: [] });
getList();
} else {
message.error(res.msg || 'Request failed');
}
},
deleteData: async (id) => {
const { getList } = get();
const res = await query.post({
path: 'resource',
key: 'delete',
id,
});
if (res.code === 200) {
getList();
message.success('Success');
} else {
message.error(res.msg || 'Request failed');
}
},
};
});