Skip to content

Tour 漫游组件

用于分步骤引导用户了解页面功能,可高亮目标元素并在其附近展示说明面板。

提示

Tour 组件演示 demo 在 iframe 中表现异常,可以点击 demo 左上角箭头单独查看。

组件类型

基本用法

通过 steps 定义引导步骤,通过 v-model 控制显隐,通过 v-model:current 同步当前步骤索引。

html
<wd-tour v-model="showBasicTour" :steps="basicSteps" v-model:current="current" :padding="10" @finish="handleFinish" @change="handleChange" />
ts
import type { TourChangeDetail, TourStep } from '@/uni_modules/wot-ui/components/wd-tour/types'
import { ref } from 'vue'

const showBasicTour = ref(false)
const current = ref(0)

const basicSteps: TourStep[] = [
  {
    element: '#step1',
    content: '欢迎使用引导组件,这是第一步的说明'
  },
  {
    element: '#step2',
    content: '这是第二步,展示了另一个功能点'
  }
]

function handleChange({ current }: TourChangeDetail) {
  console.log('当前步骤:', current)
}

function handleFinish() {
  showBasicTour.value = false
}

组件状态

点击蒙版继续

设置 click-mask-next 后,点击遮罩层会自动进入下一步。

html
<wd-tour v-model="showClickMaskTour" :steps="basicSteps" :click-mask-next="true" />

关闭蒙版

设置 maskfalse 后,仅保留高亮区域与说明面板,不再显示整页遮罩。

html
<wd-tour v-model="showNoMaskTour" :steps="noMaskSteps" :mask="false" />

组件样式

自定义蒙版

可以通过 mask-coloroffsetborder-radiuspadding 等属性调整高亮区域和遮罩表现。

html
<wd-tour
  v-model="showCustomMaskTour"
  :steps="customMaskSteps"
  mask-color="red"
  :offset="40"
  :border-radius="15"
  :padding="10"
  next-text="下一步"
  prev-text="上一步"
  skip-text="跳过"
  finish-text="完成"
/>

自定义高亮区域

通过 highlight 插槽可以完全接管高亮区域渲染。

html
<wd-tour v-model="showCustomHighlightTour" :steps="customHighlightSteps" :padding="10">
  <template #highlight="{ elementInfo }">
    <view class="custom-highlight" :style="`${objToStyle(elementInfo)};${objToStyle(customHighlightStyle)}`"></view>
  </template>
</wd-tour>
ts
import { objToStyle } from '@/uni_modules/wot-ui/common/util'

const customHighlightStyle = {
  border: '2px dashed #ff0000',
  borderRadius: '8px',
  background: 'rgba(255, 0, 0, 0.1)',
  boxSizing: 'border-box'
}

自定义内容和按钮

支持通过 contentprevnextskipfinish 插槽自定义引导内容和操作按钮。

html
<wd-tour v-model="showCustomContentTour" :steps="customContentSteps" next-text="继续" prev-text="返回" skip-text="跳过" finish-text="知道了">
  <template #content>
    <view class="custom-content">
      <wd-icon name="help-circle-filled" size="22px"></wd-icon>
      <text class="custom-text">自定义引导内容区域</text>
    </view>
  </template>

  <template #next>
    <view class="custom-button custom-next">下一步</view>
  </template>

  <template #finish>
    <view class="custom-button custom-finish">完成</view>
  </template>
</wd-tour>

特殊样式

控制当前步骤

通过 v-model:current 可在外部直接跳转到指定步骤。

ts
const controlCurrent = ref(0)

function startControlTour() {
  controlCurrent.value = 2
  showControlTour.value = true
}

Tour Attributes

参数说明类型默认值
model-value是否显示引导组件,支持 v-modelbooleanfalse
steps引导步骤列表TourStep[][]
current当前步骤索引,支持 v-model:currentnumber0
mask是否显示蒙版booleantrue
mask-color蒙版颜色string-
offset引导面板与高亮区域的间距number20
duration动画时长,单位毫秒number300
border-radius高亮区域圆角number4
padding高亮区域内边距number8
prev-text上一步按钮文案string上一步
next-text下一步按钮文案string下一步
skip-text跳过按钮文案string跳过
finish-text完成按钮文案string完成
bottom-safety-offset底部安全偏移量,用于滚动计算number100
top-safety-offset顶部安全偏移量,用于滚动计算number0
custom-nav是否启用自定义导航栏模式booleanfalse
click-mask-next点击遮罩层是否进入下一步booleanfalse
highlight-style默认高亮区域样式CSSProperties{}
z-index层级number-
show-tour-buttons是否显示引导按钮booleantrue
scope查询作用域,限定选择器查找范围unknown-
missing-strategy目标元素缺失时的处理策略,可选值为 skipstophideMissingStrategystop
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

TourStep Attributes

参数说明类型默认值
element需要高亮的元素选择器string-
content步骤说明,支持 rich-text 渲染string-
padding覆盖当前步骤的高亮内边距number-
offset覆盖当前步骤的面板间距number-
placement强制指定提示位置,可选值为 autotopbottomleftrightTourPlacementauto

Tour Events

事件名称说明参数
change当前步骤变化时触发{ current: number }
prev点击上一步时触发{ prevCurrent, current, total, isElementInTop }
next点击下一步时触发{ prevCurrent, current, total, isElementInTop }
finish点击完成时触发{ current, total }
skip点击跳过时触发{ current, total }
error目标元素查询失败时触发{ message, element }
update:modelValue显隐状态变化时触发boolean
update:current当前步骤变化时触发number

Tour Methods

方法名说明参数返回值
handlePrev切换到上一步--
handleNext切换到下一步--
handleFinish完成引导并关闭组件--
handleSkip跳过引导并关闭组件--

Tour Slots

名称说明参数
highlight自定义高亮区域{ elementInfo }
content自定义引导内容-
prev自定义上一步按钮-
next自定义下一步按钮-
skip自定义跳过按钮-
finish自定义完成按钮-

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-tour-z-index999层级
--wot-tour-animation-duration0.3s动画时长
--wot-tour-highlight-animation-timingease-in-out高亮动画时间函数
--wot-tour-highlight-shadow-color$opac-7_55高亮区域阴影颜色
--wot-tour-popover-z-index1000弹层层级
--wot-tour-popover-max-widthcalc($n-1 * 340)弹层最大宽度
--wot-tour-popover-min-widthcalc($n-1 * 200)弹层最小宽度
--wot-tour-popover-bg$filled-oppo弹层背景色
--wot-tour-popover-padding$padding-loose弹层内边距
--wot-tour-popover-radius$radius-main弹层圆角
--wot-tour-info-font-size$typography-body-size-main信息框字号
--wot-tour-info-line-height$typography-body-line--height-size-main信息框行高
--wot-tour-info-color$text-main信息框文字颜色
--wot-tour-buttons-margin-top$spacing-tight操作区域上边距

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.