This commit is contained in:
abearxiong 2025-03-26 14:06:13 +08:00
parent cc070a81a1
commit 8ee288e06a
5 changed files with 33 additions and 14 deletions

View File

@ -27,6 +27,7 @@
"@kevisual/query": "0.0.15", "@kevisual/query": "0.0.15",
"@kevisual/router": "0.0.9", "@kevisual/router": "0.0.9",
"@kevisual/store": "workspace:*", "@kevisual/store": "workspace:*",
"@kevisual/query-mark": "workspace:*",
"@mui/material": "^6.4.8", "@mui/material": "^6.4.8",
"antd": "^5.24.5", "antd": "^5.24.5",
"clsx": "^2.1.1", "clsx": "^2.1.1",

3
pnpm-lock.yaml generated
View File

@ -23,6 +23,9 @@ importers:
'@kevisual/query': '@kevisual/query':
specifier: 0.0.15 specifier: 0.0.15
version: 0.0.15(ws@8.18.0) version: 0.0.15(ws@8.18.0)
'@kevisual/query-mark':
specifier: workspace:*
version: link:submodules/query-mark
'@kevisual/router': '@kevisual/router':
specifier: 0.0.9 specifier: 0.0.9
version: 0.0.9 version: 0.0.9

9
src/modules/query.ts Normal file
View File

@ -0,0 +1,9 @@
import { QueryClient } from '@kevisual/query';
import { QueryMark } from '@kevisual/query-mark';
export const queryClient = new QueryClient();
export const queryMark = new QueryMark({
query: queryClient as any,
markType: 'mark',
});

View File

@ -1,7 +1,7 @@
import { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { useEffect, useLayoutEffect, useRef, useState } from 'react';
import { createMarkStore, store } from '../store'; import { createMarkStore, store, useMarkStore } from '../store';
console.log('store', store); console.log('store', store);
import { StoreContextProvider, useStore } from '@kevisual/store/react'; import { StoreContextProvider } from '@kevisual/store/react';
import { LineChart } from 'lucide-react'; import { LineChart } from 'lucide-react';
import { useShallow } from 'zustand/shallow'; import { useShallow } from 'zustand/shallow';
import { Core } from './core/Excalidraw'; import { Core } from './core/Excalidraw';
@ -27,26 +27,20 @@ export const Draw = () => {
); );
}; };
export const DrawHeader = () => { export const DrawHeader = () => {
const store = useStore( const store = useMarkStore(
useShallow((value: any) => { useShallow((value) => {
return { return {
mark: value.mark, mark: value.mark,
setMark: value.setMark, setMark: value.setMark,
setInfo: value.setInfo, setInfo: value.setInfo,
getList: value.getList,
}; };
}), }),
); );
console.log('store show', store); console.log('store show', store);
const init = useRef(false);
useEffect(() => { useEffect(() => {
if (!init.current && store.mark) { store.getList();
init.current = true; }, []);
store.setMark('1234');
setTimeout(() => {
store.setMark('info4');
}, 1000);
}
}, [store.mark]);
return ( return (
<div className='fixed left-0 top-0 z-10 h-10 w-10 bg-red-500'> <div className='fixed left-0 top-0 z-10 h-10 w-10 bg-red-500'>
<button> <button>

View File

@ -1,6 +1,8 @@
import { StoreManager } from '@kevisual/store'; import { StoreManager } from '@kevisual/store';
import { useContextKey } from '@kevisual/store/context'; import { useContextKey } from '@kevisual/store/context';
import { StateCreator, StoreApi } from 'zustand'; import { StateCreator, StoreApi, UseBoundStore } from 'zustand';
import { queryMark } from '../modules/query';
import { useStore, BoundStore } from '@kevisual/store/react';
export const store = useContextKey('store', () => { export const store = useContextKey('store', () => {
return new StoreManager(); return new StoreManager();
}); });
@ -10,6 +12,9 @@ type MarkStore = {
setMark: (mark: string) => void; setMark: (mark: string) => void;
info: string; info: string;
setInfo: (info: string) => void; setInfo: (info: string) => void;
getList: () => Promise<void>;
list: any[];
setList: (list: any[]) => void;
}; };
export const createMarkStore = (get: any, set: any, store: any): MarkStore => { export const createMarkStore = (get: any, set: any, store: any): MarkStore => {
return { return {
@ -17,5 +22,12 @@ export const createMarkStore = (get: any, set: any, store: any): MarkStore => {
setMark: (mark: string) => set(() => ({ mark })), setMark: (mark: string) => set(() => ({ mark })),
info: 'test info', info: 'test info',
setInfo: (info: string) => set(() => ({ info })), setInfo: (info: string) => set(() => ({ info })),
getList: async () => {
const res = await queryMark.getMarkList({ page: 1, pageSize: 10 });
console.log(res);
},
list: [],
setList: (list: any[]) => set(() => ({ list })),
}; };
}; };
export const useMarkStore = useStore as BoundStore<MarkStore>;