暂存,修改navigate和添加图片

This commit is contained in:
2024-10-12 12:38:19 +08:00
parent 929aaebf20
commit 3eaa94eb46
29 changed files with 244 additions and 58 deletions

View File

@@ -10,6 +10,8 @@ type DeckPageStore = {
loading: boolean;
setLoading: (loading: boolean) => void;
pageData: any[];
cids: string[];
setCids: () => void;
setPageData: (data: any[]) => void;
getPageData: () => any[];
selected: any;
@@ -57,4 +59,12 @@ export const useDeckPageStore = create<DeckPageStore>((set, get) => ({
getCode: () => {
return get().code;
},
cids: [],
setCids: () => {
const pageData = get().pageData;
const cids = pageData.map((item) => item.codeId).filter((item) => item);
// cids 去重复
const newCids = Array.from(new Set(cids));
set({ cids: newCids });
},
}));

View File

@@ -22,12 +22,14 @@ export const clearBlank = (newStyle: any) => {
return change;
};
export const useListener = (id?: string, opts?: any) => {
const { refresh } = opts || {};
const { refresh, cids = [] } = opts || {};
const connected = useStore((state) => state.connected);
// 监听服务器的消息
useEffect(() => {
if (!id) return;
if (!connected) return;
if (cids.length === 0) return;
console.log('cids', cids);
ws.send(
JSON.stringify({
type: 'subscribe',
@@ -35,7 +37,7 @@ export const useListener = (id?: string, opts?: any) => {
type: 'pageEdit',
data: {
pid: id,
cids: ['170c0b55-8c13-4d6e-bf35-3f935d979a0d'],
cids: cids,
},
},
}),
@@ -46,7 +48,7 @@ export const useListener = (id?: string, opts?: any) => {
if (!connected) return;
ws.removeEventListener('message', listener);
};
}, [id, connected]);
}, [id, connected, cids]);
const listener = (event) => {
const parseIfJson = (data: string) => {
try {
@@ -66,17 +68,6 @@ export const useListener = (id?: string, opts?: any) => {
}
};
};
const getParent = (data: { children?: string[]; [key: string]: any }[], id: string, list: string[]) => {
for (let item of data) {
if (item.children?.includes(id)) {
// 找到了当前的父亲节点
list.unshift(item.id);
getParent(data, item.id, list);
return;
}
}
return;
};
export const Deck = () => {
const params = useParams<{ id: string }>();
@@ -86,6 +77,7 @@ export const Deck = () => {
const deckPageStore = useDeckPageStore();
const { code, setCode } = deckPageStore;
const { selected, setSelected } = deckPageStore;
const { cids } = deckPageStore;
const aiStore = useAiStore(
useShallow((state) => {
return {
@@ -129,6 +121,7 @@ export const Deck = () => {
const result = getContainerData({ page, containerList });
console.log('result', result);
deckPageStore.setPageData(result);
deckPageStore.setCids();
init(result);
}
};
@@ -149,12 +142,12 @@ export const Deck = () => {
});
// container.reRender();
containerList.forEach((item) => {
container.hotReload(item.id);
container.renderId(item.id);
});
// @ts-ignore
window.c = container;
};
useListener(id, { refresh });
useListener(id, { refresh, cids });
const onContainer = (e) => {
const { data } = e;
const types = ['position', 'resize'];

View File

@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { Form } from 'antd';
import copy from 'copy-to-clipboard';
import { useNavigate } from 'react-router';
import { useNewNavigate } from '@/modules';
import { useToCodeEditor } from '@/pages/code-editor';
import { CardBlank } from '@/components/card/CardBlank';
import {
@@ -103,7 +103,7 @@ const FormModal = () => {
);
};
export const List = () => {
const navicate = useNavigate();
const navicate = useNewNavigate();
const toCodeEditor = useToCodeEditor();
const editStore = useEditStore(
useShallow((state) => {