Skip to content

Tour 引导

引导用户按步骤使用界面或完成任务的组件,由 ea-tourea-tour-step 组成。

引入

html
<script type="module">
  import "./node_modules/easy-component-ui/dist/components/ea-tour.js";
</script>
js
import "easy-component-ui/ea-tour";

基础用法

简单示例:点击按钮开启引导。

Begin Tour

UploadSave

tour.png
Put you files here.
查看代码
html
<div class="demo">
  <ea-button id="basicTourBtn" variant="primary">Begin Tour</ea-button>
  <hr />
  <ea-button id="basicEl1">Upload</ea-button>
  <ea-button id="basicEl2" variant="primary">Save</ea-button>
  <ea-button id="basicEl3" icon="share-nodes"></ea-button>

  <ea-tour id="basicTour">
    <ea-tour-step target="#basicEl1" heading="Upload File">
      <img
        style="width: 240px"
        src="https://raw.githubusercontent.com/LuminaQAQ/ea-ui-component/refs/heads/dev_3.0/docs/favicon.ico"
        alt="tour.png"
      />
      <div>Put you files here.</div>
    </ea-tour-step>
    <ea-tour-step
      target="#basicEl2"
      heading="Save"
      description="Save your changes"
    ></ea-tour-step>
    <ea-tour-step
      target="#basicEl3"
      heading="Other Actions"
      description="Click to see other"
    ></ea-tour-step>
  </ea-tour>
</div>

<script type="module">
  const basicExample = {
    el: document.querySelector("#basicTour"),
    btn: document.querySelector("#basicTourBtn"),

    init() {
      this.btn.addEventListener("click", () => {
        this.el.visible = true;
      });
    },
  };
  basicExample.init();
</script>

非模态

设置 mask="false" 可让引导非模态显示(不遮罩页面),配合 variant="primary" 可使用主题色样式。

Begin Tour

UploadSave

Put you files here.
查看代码
html
<div class="demo">
  <ea-button id="noMaskTourBtn" variant="primary">Begin Tour</ea-button>
  <hr />
  <ea-button id="noMaskEl1">Upload</ea-button>
  <ea-button id="noMaskEl2" variant="primary">Save</ea-button>
  <ea-button id="noMaskEl3" icon="share-nodes"></ea-button>

  <ea-tour id="noMaskTour" variant="primary" mask="false">
    <ea-tour-step target="#noMaskEl1" heading="Upload File">
      <div>Put you files here.</div>
    </ea-tour-step>
    <ea-tour-step
      target="#noMaskEl2"
      heading="Save"
      description="Save your changes"
    ></ea-tour-step>
    <ea-tour-step
      target="#noMaskEl3"
      heading="Other Actions"
      description="Click to see other"
    ></ea-tour-step>
  </ea-tour>
</div>

<script type="module">
  const noMaskExample = {
    el: document.querySelector("#noMaskTour"),
    btn: document.querySelector("#noMaskTourBtn"),

    init() {
      this.btn.addEventListener("click", () => {
        this.el.visible = true;
      });
    },
  };
  noMaskExample.init();
</script>

位置

通过 placement 属性可设置 ea-tour-step 的出现位置;若不设置 target,可在屏幕中心显示。

Begin Tour
查看代码
html
<div class="demo" style="text-align: center">
  <ea-button id="placementTourBtn" variant="primary">Begin Tour</ea-button>

  <ea-tour id="placementTour">
    <ea-tour-step
      heading="Center"
      description="Displayed in the center of screen."
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Top"
      description="On the top of target."
      placement="top"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Top-Start"
      description="On the top-start of target."
      placement="top-start"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Top-End"
      description="On the top-end of target."
      placement="top-end"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Right"
      description="On the right of target."
      placement="right"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Right-Start"
      description="On the right-start of target."
      placement="right-start"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Right-End"
      description="On the right-end of target."
      placement="right-end"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Bottom"
      description="On the bottom of target."
      placement="bottom"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Bottom-Start"
      description="On the bottom-start of target."
      placement="bottom-start"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Bottom-End"
      description="On the bottom-end of target."
      placement="bottom-end"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Left"
      description="On the Left of target."
      placement="left"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Left-Start"
      description="On the left-start of target."
      placement="left-start"
    ></ea-tour-step>
    <ea-tour-step
      target="#placementTourBtn"
      heading="Left-End"
      description="On the left-end of target."
      placement="left-end"
    ></ea-tour-step>
  </ea-tour>
</div>

<script type="module">
  const placementExample = {
    el: document.querySelector("#placementTour"),
    btn: document.querySelector("#placementTourBtn"),

    init() {
      this.btn.addEventListener("click", () => {
        this.el.visible = true;
      });
    },
  };
  placementExample.init();
</script>

Tour API

Tour Attributes

参数说明类型可选值默认值
append-to挂载容器选择器stringbody
visible控制引导是否显示booleanfalse
current当前步骤索引number0
gap遮罩与目标元素间距(像素)number6
mask是否显示遮罩booleantrue
variant按钮等样式类型,会传递给子 stepstringdefault | primarydefault
placement默认步骤弹出位置(当 step 未设置 placement 时生效)stringtop | top-start | top-end | bottom | bottom-start | bottom-end | left | left-start | left-end | right | right-start | right-endbottom

Tour Slots

名称说明
defaultstep 子元素插槽

Tour Events

事件名说明回调参数(event.detail)
ea-close引导关闭时触发{ current: number }
ea-tour-change步骤切换时触发{ current: number }
ea-tour-finish完成引导时触发

Tour CSS Custom Properties

属性名说明默认值
--ea-tour-transition过渡动画时长var(--transition-normal)
--ea-tour-mask-color遮罩颜色rgba(0, 0, 0, 0.5)

TourStep API

TourStep Attributes

参数说明类型可选值默认值
heading步骤标题string""
target目标元素选择器(缺省则居中显示)string""
placement步骤弹出位置stringtop | top-start | top-end | bottom | bottom-start | bottom-end | left | left-start | left-end | right | right-start | right-endbottom
variant样式类型,会影响按钮类型stringdefault | primarydefault

TourStep CSS Part

名称说明
containerstep 根元素
header头部(heading / close)
close-icon关闭图标
content内容区域
footer底部区域
indicator-group指示器容器
indicator单个指示器(circle)
switch-group按钮容器
previous上一步按钮 part
next下一步按钮 part
finish完成按钮 part

TourStep Slots

名称说明
default默认插槽,用于步骤内容
header头部插槽,可自定义标题或关闭按钮
indicator自定义指示器(覆盖默认圆点)
footer自定义底部按钮区域

TourStep Methods

方法名说明参数
updateIndicators更新步骤指示器allSteps: HTMLElement[]

TourStep CSS Custom Properties

属性名说明默认值
--ea-tour-step-visible步骤可见性none
--ea-tour-step-width步骤宽度400px
--ea-tour-step-padding步骤内边距var(--spacing-lg)
--ea-tour-step-bg-color步骤背景颜色var(--white)
--ea-tour-step-indicator-size指示器尺寸6px
--ea-tour-step-indicator-color指示器颜色var(--grey-200)
--ea-tour-step-indicator-active-color激活指示器颜色var(--blue-500)
--ea-tour-step-close-color关闭图标颜色var(--grey-500)
--ea-tour-step-primary-color主题色var(--blue-500)