import { computed, defineComponent, ref, toRaw } 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 useSortable, { dragging, resetDragging } from './useSortable'
import BlockWrapper from './BlockWrapper'
addIcons(MdAdd)
export default defineComponent(() => {
const layout = useLayoutStore()
const router = useRouterStore()
const container = useSortable(
computed(() => layout.currentPage.list),
ref('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(toRaw(block))
layout.state.dock[oldIdx] = null
resetDragging()
} else if (dragging.type && dragging.type !== 'dock') {
const list = layout.state.dir[dragging.type]?.list
if (!list) return
const idx = list.findIndex((el) => el.id === dragging.id)
if (idx < 0) return
const block = list[idx]
layout.currentPage.list.push(toRaw(block))
list.splice(idx, 1)
layout.checkDir(dragging.type)
resetDragging()
}
}}
>
{layout.currentPage.list.map((block, idx) => (
))}
)
})