Skip to content

漫游式引导

HiIntro 漫游式引导组件,用于生成界面操作指引

安装方式

bash
pnpm add pangea-component

基本使用

js
import createInto from "pangea-component/hi-intro";
import "pangea-component/dist/style.css";

const steps = [
  {
    element: ".test1",
    title: "引导一",
    intro: "xxxxxxxxx",
  },
  {
    element: ".test2",
    title: "引导二",
    intro: "xxxxxxxxx",
  },
];

const options = {
  theme: "dark",
};

createInto(steps, options);

注意

调用createInto生成引导组件时要确保element对应的元素已渲染

API

名称描述参数
createInto创建引导式组件steps: Step[], options: Options
  • steps: 引导步骤配置
  • Options: 引导组件基础信息配置

配置参数

Step

参数名描述类型默认值
title标题string-
intro介绍内容string-
element当前步骤高亮元素Element / string-
width气泡弹窗宽度string-
buttons自定义按钮Button[]-

Options

参数名描述类型默认值
theme主题色"light" | "dark""light"
animate动画booleantrue
showProgress显示进度booleantrue
nextBtnText下一步按钮文案string下一步
prevBtnText上一步按钮文案string上一步
doneBtnText完成按钮文案string完成
smoothScroll是否滚动到高亮元素booleantrue
allowClose允许关闭booleantrue
overlayClickBehavior点击背景时的行为"close" | "nextStep""nextStep"
showSkip是否显示跳过按钮booleanfalse
skipText跳过按钮文案string跳过
onChange步骤切换时(step: number) => void-
onBeforeDestroy引导组件销毁前(params: {destroy: () => void;step: number }) => void-
onDestroy组件销毁后触发() => void-

Button

参数名描述类型默认值
text按钮名称string-
type按钮类型"primary" | "secondary""secondary"
action点击按钮触发动作(params: { destroy:() => void; stepNext: () => void; stepPrev: () => void; stepTo: (index: number) => void ; step: number; }) => void-

低代码页面内使用方式

将createInto方法通过ctxInjected注册到 ctx.injected对象中

常见场景配置

一、控制引导组件只显示一次

js
import createInto from "pangea-component/hi-intro";
import "pangea-component/dist/style.css";

const steps = [
  {
    element: ".test1",
    title: "引导一",
    intro: "xxxxxxxxx",
  },
  {
    element: ".test2",
    title: "引导二",
    intro: "xxxxxxxxx",
  },
];

const options = {
  onDestroy() {
    localStorage.setItem("showIntro", "true")
  }
};

if (localStorage.getItem("showIntro") !== "true") {
  createInto(steps, options);
}

二、引导组件销毁前添加确认弹窗

js
import createInto from "pangea-component/hi-intro";
import "pangea-component/dist/style.css";

const steps = [
  {
    element: ".test1",
    title: "引导一",
    intro: "xxxxxxxxx",
  },
  {
    element: ".test2",
    title: "引导二",
    intro: "xxxxxxxxx",
  },
];

const options = {
  onBeforeDestroy({destroy}) {
    if (window.confirm("确认关闭吗?")) {
      destroy()
    }
};
createInto(steps, options);