Skip to content

xtf-popover

组件说明

xtf-popover 是气泡浮层组件,适用于字段说明、轻量提示和就近操作内容;与弹窗不同,它锚定触发元素展示。 核心能力以当前 xtf-popover.vue 源码为准。


基础用法

1. 基础用法

最小配置下即可完成常见业务交互:

vue
<template>
  <xtf-popover title="字段说明" content="GMV 默认不含退款订单。">
    <xtf-button label="查看说明"
  /></xtf-popover>
</template>

<script>
export default {
  data() {
    return { value: false }
  },
  methods: {
    onEvent(payload) {
      console.log('组件事件', payload)
    }
  }
}
</script>

2. 核心交互

监听组件事件并维护页面状态:

vue
<template>
  <xtf-popover
    :show="value"
    trigger="manual"
    title="手动控制"
    content="由外部状态控制"
    @update:show="value = $event"
    ><xtf-button label="切换" @click="value = !value"
  /></xtf-popover>
</template>

<script>
export default {
  data() {
    return { value: false }
  },
  methods: {
    onEvent(payload) {
      console.log('组件事件', payload)
    }
  }
}
</script>

3. 进阶配置

组合布局、样式或插槽能力:

vue
<template>
  <xtf-popover placement="bottom">
    <xtf-button label="插槽内容" /><template #content
      ><xtf-cell title="待发货" desc="仓库正在处理"
    /></template>
  </xtf-popover>
</template>

<script>
export default {
  data() {
    return { value: false }
  },
  methods: {
    onEvent(payload) {
      console.log('组件事件', payload)
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
showBooleanfalse控制组件的 show 行为。按业务需要设置。
triggerString'click'控制组件的 trigger 行为。按业务需要设置。
placementString'bottom'弹出位置:top/top-start/top-endbottom/bottom-start/bottom-endleft/left-start/left-endright/right-start/right-end需要控制面板相对触发器的方向和对齐方式。
titleString''控制组件的 title 行为。按业务需要设置。
contentString''控制组件的 content 行为。按业务需要设置。
arrowBooleantrue控制组件的 arrow 行为。按业务需要设置。
disabledBooleanfalse控制组件的 disabled 行为。按业务需要设置。
closeOnClickOutsideBooleantrue可见时是否渲染全屏透明遮罩;点击触发器周围空白区域会触发 update:show(false)close。设为 false 时不渲染遮罩,空白点击不会关闭。说明提示保持默认;面板内有连续操作或必须明确关闭时设为 false
overlayBooleanfalse是否为全屏背景遮罩着色;与 closeOnClickOutside 独立。true + false 可实现有遮罩但点击空白不关闭。需要突出当前浮层或弱化页面背景时。
overlayColorString'rgba(15, 23, 42, 0.42)'遮罩背景色;仅 overlaytrue 时使用。调整遮罩明暗与品牌色调。
autoAdjustBooleantrue控制组件的 autoAdjust 行为。按业务需要设置。
variantString'popover'控制组件的 variant 行为。按业务需要设置。
animationString'scale'面板进入和退出动画:none / fade / scale / zoom / slide-up / slide-down / slide-left / slide-right需要匹配浮层方向、降低动效或突出反馈时。
offsetString | Number12触发器与面板在主方向上的基础间距;数字和纯数字字符串按 rpx 处理,也可传入如 '16px' 的单位值。常规间距控制;保留以兼容已有用法。
offsetXString | Number0面板相对默认定位的水平偏移;正值向右,负值向左。数字按 rpx 处理。需要微调左右对齐、避开邻近内容时。
offsetYString | Number0面板相对默认定位的垂直偏移;正值向下,负值向上。数字按 rpx 处理。需要微调上下对齐、避开邻近内容时。
width[String, Number]''控制组件的 width 行为。按业务需要设置。
maxWidth[String, Number]320控制组件的 maxWidth 行为。按业务需要设置。
zIndex[String, Number]40控制组件的 zIndex 行为。按业务需要设置。
customClassString''控制组件的 customClass 行为。按业务需要设置。
customStyle[String, Object]''控制组件的 customStyle 行为。按业务需要设置。
panelClassString''控制组件的 panelClass 行为。按业务需要设置。
panelStyle[String, Object]''自定义浮层面板背景、边框、阴影、圆角等内联样式。单个实例需要独立视觉时。
titleClassString''控制组件的 titleClass 行为。按业务需要设置。
titleStyle[String, Object]''自定义标题容器内联样式。使用 title 插槽时常用于重置内边距。
contentClassString''控制组件的 contentClass 行为。按业务需要设置。
contentStyle[String, Object]''自定义正文容器内联样式。使用 content 插槽组合业务组件时。
arrowClassString''控制组件的 arrowClass 行为。按业务需要设置。
arrowStyle[String, Object]''自定义箭头背景与边框样式。面板使用非默认背景色时。

事件

事件名称触发时机回调参数参数说明
update:show对应交互或状态变化时触发。payload参数形状以源码 $emit('update:show', ...) 为准。
open对应交互或状态变化时触发。payload参数形状以源码 $emit('open', ...) 为准。
close对应交互或状态变化时触发。payload参数形状以源码 $emit('close', ...) 为准。

事件使用示例

vue
<template>
  <xtf-popover @update:show="onEvent" />
</template>
<script>
export default {
  methods: {
    onEvent(payload) {
      console.log('收到事件', payload)
    }
  }
}
</script>

插槽

插槽名说明作用域参数
default触发气泡浮层的内容。
title替换标题内容。
content替换浮层正文内容。

方法

setVisible(value):切换可见状态;refreshPlacement():重新计算自动避让位置。

使用示例:

js
this.$refs.popover.setVisible(true)
this.$refs.popover.refreshPlacement()

主题说明

  • var(--xtf-popover-z-index) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-popover-offset) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-popover-shift-x) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-popover-shift-y) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-color-surface) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-color-border) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-shadow-popover) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-color-text) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-color-text-secondary) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-popover-arrow-shift-x) 参与组件的颜色、背景、边框或动效呈现。
  • var(--xtf-popover-arrow-shift-y) 参与组件的颜色、背景、边框或动效呈现。
  • 视觉变体的可选值以 variantthemelayout 等属性在源码中的分支为准。

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖上述 CSS 变量。

MIT Licensed