diff --git a/main/expressDocCurd.js b/main/expressDocCurd.js index 1220f6b9..18dd2b67 100644 --- a/main/expressDocCurd.js +++ b/main/expressDocCurd.js @@ -215,7 +215,7 @@ router.put('/:docId', async (req, res) => { const oldFilename = oldFilepath.pop(); const oldDir = oldFilepath.join('/'); const filename = req.body.name; - const suffix = oldFilename.split('.', 2)[1] + const suffix = oldFilename.split('.').slice(1).join('.') const tags = JSON.parse(req.body.tag); const dir = tags.shift() || ''; const actualFilename = `${docId}#${filename}${tags.map(tag => '[' + tag.replace('/', ':') + ']').join('')}.${suffix}` diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index 658eca5a..958b528a 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -59,7 +59,7 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager const forceUpdate = useForceUpdate(); const navigate = useNavigate(); const location = useLocation(); - const [curPage, setCurPage] = useState(location.pathname.split('/').shift() || 'note'); + const [curPage, setCurPage] = useState(location.pathname.split('/')[1] || 'note'); const [settingOpen, setSettingOpen] = useState(false); const [refreshing, setRefreshing] = useState(false); const [drawerWidth, setDrawerWidth] = useState(window.innerWidth / 2); @@ -374,8 +374,9 @@ function LayoutComponent(props: {session: Session, config: Config, pluginManager props.session.startKeyMonitor(); const docId = props.session.clientStore.getClientSetting('curDocId'); navigate(`/${e.key}/${docId}`); - } else if (e.key === 'test') { - navigate(`/${e.key}`); + } else if (e.key === 'produce') { + const pkbId = props.session.clientStore.getClientSetting('curPkbId'); + navigate(`/${e.key}/${pkbId}`); } else { // props.session.stopKeyMonitor('header'); const lastSearch = props.session.clientStore.getClientSetting('curSearch'); diff --git a/src/components/pkb-producer/index.tsx b/src/components/pkb-producer/index.tsx index 7b48d1f4..3d4a2c3e 100644 --- a/src/components/pkb-producer/index.tsx +++ b/src/components/pkb-producer/index.tsx @@ -83,8 +83,9 @@ export default function PkbProducer({ const {userDocs} = useLoaderData(); const appRef = useRef(null); const { t } = useI18n(); - const [selectId, setSelectId] = useState(''); + const [selectNodeId, setSelectNodeId] = useState(''); const [editingTextId, setEditingTextId] = useState(''); + const [editingDocId, setEditingDocId] = useState(-1); const [boardX, setBoardX] = useState(70); const [boardY, setBoardY] = useState(17); const [showFilter, setShowFilter] = useState(false); @@ -111,6 +112,7 @@ export default function PkbProducer({ }, [userDocs]); useEffect(() => { if (curDocId && Number(curDocId) > 0) { + session.clientStore.setClientSetting('curPkbId', Number(curDocId)); api_utils.getDocContent(Number(curDocId)).then((res) => { const elements = JSON.parse(res.content).elements as readonly ExcalidrawElement[]; // @ts-ignore @@ -347,27 +349,29 @@ export default function PkbProducer({ { excalidrawAPI?.updateScene({ - elements: filterWithSelectElementId('up_down', excalidrawAPI?.getSceneElements()!, selectId) + elements: filterWithSelectElementId('up_down', excalidrawAPI?.getSceneElements()!, selectNodeId) }); }}/> { excalidrawAPI?.updateScene({ - elements: filterWithSelectElementId('up', excalidrawAPI?.getSceneElements()!, selectId) + elements: filterWithSelectElementId('up', excalidrawAPI?.getSceneElements()!, selectNodeId) }); }} /> { excalidrawAPI?.updateScene({ - elements: filterWithSelectElementId('down', excalidrawAPI?.getSceneElements()!, selectId) + elements: filterWithSelectElementId('down', excalidrawAPI?.getSceneElements()!, selectNodeId) }); }}/> -
{ +
{ session.startKeyMonitor(); }} onMouseLeave={() => { session.stopKeyMonitor('sidebar-enter'); @@ -414,6 +418,12 @@ export default function PkbProducer({ }) }); setEditingTextId(''); + } else if (editingDocId > 0) { + console.log(`正在保存内容到文档 ${editingDocId}`); + session.reUploadFile(Path.root(), editingDocId).then(() => { + setEditingDocId(-1); + excalidrawAPI?.setToast({message: '节点保存成功', duration: 1000}); + }); } }; @@ -460,8 +470,9 @@ export default function PkbProducer({ const viewRoot = link.split('f=').pop()?.split('&').shift(); session.document.canonicalPath(Number(viewRoot)).then(path => { session.changeViewRoot(path || Path.root()).then(() => { + setEditingDocId(docID); setEditingTextId(''); - setSelectId(element.id); + setSelectNodeId(element.id); excalidrawAPI?.updateScene({appState: {openSidebar: {name: 'node-content'}}}); console.log('onLinkOpen', docID, viewRoot); }); @@ -494,7 +505,7 @@ export default function PkbProducer({ loadDoc({id: -1, content}).then(() => { setTimeout(() => { setEditingTextId(textElementId!.id); - setSelectId(pointerDownState.hit.element!.id); + setSelectNodeId(pointerDownState.hit.element!.id); excalidrawAPI?.updateScene({appState: {openSidebar: { name: 'node-content'}}}); }); }); @@ -507,28 +518,31 @@ export default function PkbProducer({ return ( - } onSelect={() => { - console.log('保存至EffectNote'); - if (!excalidrawAPI) { - return false; - } - exportToClipboard({ - elements: excalidrawAPI.getSceneElements(), - appState: excalidrawAPI.getAppState(), - files: excalidrawAPI.getFiles(), - type: 'json', - }).then(() => { - navigator.clipboard.readText().then(content => { - const docInfo = { ...userDocs.find((doc: any) => doc.id === Number(curDocId))!, - content: JSON.stringify(JSON.parse(content), undefined, 2)}; - api_utils.updateDoc(Number(curDocId), docInfo).then(() => { - excalidrawAPI.setToast({message: '保存成功', duration: 1000}); + { + Number(curDocId) > 0 && + } onSelect={() => { + console.log('保存至EffectNote'); + if (!excalidrawAPI) { + return false; + } + exportToClipboard({ + elements: excalidrawAPI.getSceneElements(), + appState: excalidrawAPI.getAppState(), + files: excalidrawAPI.getFiles(), + type: 'json', + }).then(() => { + navigator.clipboard.readText().then(content => { + const docInfo = { ...userDocs.find((doc: any) => doc.id === Number(curDocId))!, + content: JSON.stringify(JSON.parse(content), undefined, 2)}; + api_utils.updateDoc(Number(curDocId), docInfo).then(() => { + excalidrawAPI.setToast({message: '画板保存成功', duration: 1000}); + }); }); }); - }); - }}> - 保存至EffectNote - + }}> + 保存至EffectNote + + } diff --git a/src/share/ts/datastore.ts b/src/share/ts/datastore.ts index f939ce93..768b73bb 100644 --- a/src/share/ts/datastore.ts +++ b/src/share/ts/datastore.ts @@ -31,6 +31,7 @@ export type ClientSettings = Theme & { openFile: string; curView: string; curDocId: number; + curPkbId: number; curTheme: string; curSearch: string; curSearchResult: string; @@ -52,6 +53,7 @@ const default_client_settings: ClientSettings = openFile: '0', curView: 'note', curDocId: -1, + curPkbId: -2, curSearch: '', curSearchResult: '', recentDocId: [-1],