开发预览 更新于 2026-05-10

DetachedPanel 浮动面板

可拖拽的浮动面板,Teleport 到 body。配合 TearOffTab / DockLayout 的 detach 动作使用。

基础用法

按住头部即可拖动;resizable 启用浏览器原生 resize。Tauri / Electron 场景里把它转成独立 window 时只需在 tear-off 事件里 spawn 一个新 BrowserWindow / WebView。

背景
<script setup lang="ts">
import { ref } from 'vue';
import { CfDetachedPanel, CfButton } from '@chufix-design/vue';
const open = ref(false);
</script>

<template>
  <div class="demo-row">
    <CfButton @click="open = true">弹出浮动面板</CfButton>
    <CfDetachedPanel v-model:open="open" title="Inspector" :width="320" :height="220">
      <div style="font-size: 13px; color: var(--fg-2); line-height: 1.6;">
        拖动顶部把手可以移动面板。<br>
        外部 Tauri/Electron 应用可在 tear-off 事件里把它转换成独立窗口。
      </div>
    </CfDetachedPanel>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { CfDetachedPanel, CfButton } from '@chufix-design/vue';
const open = ref(false);
</script>

<template>
  <div class="demo-row">
    <CfButton @click="open = true">弹出浮动面板</CfButton>
    <CfDetachedPanel v-model:open="open" title="Inspector" :width="320" :height="220">
      <div style="font-size: 13px; color: var(--fg-2); line-height: 1.6;">
        拖动顶部把手可以移动面板。<br>
        外部 Tauri/Electron 应用可在 tear-off 事件里把它转换成独立窗口。
      </div>
    </CfDetachedPanel>
  </div>
</template>
<CfDetachedPanel open={open} onOpenChange={setOpen} title="Inspector" width={320}>
<div>面板内容…</div>
</CfDetachedPanel>
<CfDetachedPanel open={open} onOpenChange={setOpen} title="Inspector" width={320}>
<div>面板内容…</div>
</CfDetachedPanel>

多面板共存

可同时打开多个 DetachedPanel;通过 zIndex 显式分层。resizable=true 启用浏览器原生 resize 句柄。

背景
<script setup lang="ts">
import { ref } from 'vue';
import { CfDetachedPanel, CfButton } from '@chufix-design/vue';
const a = ref(false);
const b = ref(false);
</script>

<template>
  <div class="demo-row">
    <CfButton @click="a = true">面板 A</CfButton>
    <CfButton variant="secondary" @click="b = true">面板 B(resizable)</CfButton>
    <CfDetachedPanel
      v-model:open="a"
      title="Inspector A"
      :width="280"
      :height="180"
      :z-index="1500"
    >
      <div style="font-size: 12px; color: var(--fg-2);">头部拖动可移动整个面板。</div>
    </CfDetachedPanel>
    <CfDetachedPanel
      v-model:open="b"
      title="Inspector B"
      :width="320"
      :height="220"
      resizable
      :z-index="1501"
    >
      <div style="font-size: 12px; color: var(--fg-2);">右下角可拖拽改变大小(resizable)。</div>
    </CfDetachedPanel>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { CfDetachedPanel, CfButton } from '@chufix-design/vue';
const a = ref(false);
const b = ref(false);
</script>

<template>
  <div class="demo-row">
    <CfButton @click="a = true">面板 A</CfButton>
    <CfButton variant="secondary" @click="b = true">面板 B(resizable)</CfButton>
    <CfDetachedPanel
      v-model:open="a"
      title="Inspector A"
      :width="280"
      :height="180"
      :z-index="1500"
    >
      <div style="font-size: 12px; color: var(--fg-2);">头部拖动可移动整个面板。</div>
    </CfDetachedPanel>
    <CfDetachedPanel
      v-model:open="b"
      title="Inspector B"
      :width="320"
      :height="220"
      resizable
      :z-index="1501"
    >
      <div style="font-size: 12px; color: var(--fg-2);">右下角可拖拽改变大小(resizable)。</div>
    </CfDetachedPanel>
  </div>
</template>
<CfDetachedPanel open={a} onOpenChange={setA} width={280} />
<CfDetachedPanel open={b} onOpenChange={setB} resizable />
<CfDetachedPanel open={a} onOpenChange={setA} width={280} />
<CfDetachedPanel open={b} onOpenChange={setB} resizable />

API

属性类型默认值说明
open / v-model:openbooleanfalse
titlestring头部标题
x / ynumber自动初始位置
width / heightnumber | string360 / 240
resizablebooleanfalse启用原生 resize 句柄
closablebooleantrue
tostring'body'Teleport 目标
zIndexnumber

事件:update:open / move(x, y)

反馈与讨论

DetachedPanel 浮动面板 的讨论

0
0 / 600
一键发送
正在加载评论...