import { computed, defineComponent, TransitionGroup } from 'vue' import useLayoutStore from '../useLayoutStore' import { OhVueIcon, addIcons } from 'oh-vue-icons' import { MdAdd } from 'oh-vue-icons/icons' import useRouterStore from '@/useRouterStore' import { globalToast } from '@/main' import LinkBlock from './LinkBlock' import useSortable, { dragging } from './useSortable' addIcons(MdAdd) export default defineComponent(() => { const layout = useLayoutStore() const router = useRouterStore() const container = useSortable( computed(() => layout.currentPage.list), 'page' ) return () => (
{ const h = (e.target as any).scrollTop if (h > 60) { // 需要移动搜索框和时间 layout.isCompact = true } else { layout.isCompact = false } }} onDragover={(e) => e.preventDefault()} onDrop={() => { // 处理移入(当前有内容不可移入) if (!dragging.id) return if (dragging.type === 'dock') { const oldIdx = layout.state.dock.findIndex((el) => el?.id === dragging.id) if (oldIdx < 0) return const block = layout.state.dock[oldIdx] if (!block) return layout.currentPage.list.push(block) layout.state.dock[oldIdx] = null return } if (dragging.type && dragging.type !== 'dock') { // TODO: 文件夹 return } }} >
{layout.currentPage.list.map((block, idx) => (
e.preventDefault()} onDrop={() => { // 处理移入(当前有内容不可移入) if (!dragging.id) return if (dragging.type === 'dock') { const oldIdx = layout.state.dock.findIndex((el) => el?.id === dragging.id) if (oldIdx < 0) return const block = layout.state.dock[oldIdx] if (!block) return layout.currentPage.list.splice(idx, 0, block) layout.state.dock[oldIdx] = null return } if (dragging.type && dragging.type !== 'dock') { // TODO: 文件夹 return } }} >
{block.link ? ( block.link.startsWith('id:') ? ( // 文件夹
) : ( // 链接 ) ) : ( // 小组件
)}
{block.label}
))}
{ if (layout.state.content[layout.state.current].pages[layout.state.currentPage]) { router.path = 'global-adder' } else { globalToast.warning('请先添加页面') } }} >
) })