introjs 用法 新手引导

效果图:
在这里插入图片描述

一、安装

npm install intro.js --save

二、引入

如果全局引入的话使用下面代码,在main.ts引入

import IntroJs from 'intro.js'
import 'intro.js/introjs.css';

Vue.use(IntroJs);

vue.config.js加入以下代码

module.exports = {
	……
	configureWebpack: {
	  plugins: [
	    new webpack.ProvidePlugin({
	      introJs: ['intro.js', 'introJs']
	    })
	  ]
	},
	……
}

三、封装

我这边是封装在src/utils/intro.ts,代码如下

import introJs from "intro.js";
import "intro.js/introjs.css";
import "@/styles/intro.scss";
export const intro = introJs;

interface Step {
  element?: string;
  intro: string;
  position?: string;
}

interface Options {
  steps: Step[]; // 引导步骤
  prevLabel?: string; // 返回上一步的按钮的字符串
  nextLabel?: string; // 返回下一步的按钮的字符串
  skipLabel?: string; // 跳过引导的按钮的字符串
  doneLabel?: string; // 结束按钮的字符串
  showBullets?: boolean;  // 未知
  highlightClass?: string;  // 高亮所使用的class名
  hidePrev?: boolean;  // 是否在第一步隐藏上一步
  hideNext?: boolean;  // 是否在最后一步隐藏下一步
  showStepNumbers?: boolean;  // 是否显示当前步骤的索引数字
  scrollToElement?: boolean;  // 未知
  showButtons?: boolean;  // 是否显示所有按钮
  disableInteraction?: boolean;  // 引导框内视图是否可交互
  tooltipClass?: string;  // 提示框所使用的class名
  showProgress?: boolean; // 是否显示进度条
  overlayOpacity?: number;  // 蒙版的透明度
  exitOnEsc?: boolean; // 是否使用键盘Esc退出
  exitOnOverlayClick?: boolean; // 是否允许点击空白处退出
  helperElementPadding?: number;  // 提示边框的padding
}

const baseOptions: Options = {
  steps: [],
  prevLabel: "上一步",
  nextLabel: "下一步",
  skipLabel: "跳过",
  doneLabel: "结束",
  showBullets: false,
  highlightClass: "introjs",
  hidePrev: true,
  hideNext: true,
  showStepNumbers: false,
  scrollToElement: true,
  disableInteraction: false,
  tooltipClass: "intro-no-pre",
  showProgress: false,
  overlayOpacity: 0.5,
  exitOnEsc: false,
  exitOnOverlayClick: false,
  helperElementPadding: 1
};

const getIntro = (options: Options) => {
  return new introJs().setOptions(
    Object.assign(JSON.parse(JSON.stringify(baseOptions)), options)
  );
};

export const homeIntro = getIntro({
  disableInteraction: true,
  tooltipClass: "intro-no-skip",
  steps: [
    {
      element: "#companySelect",
      intro: "切换公司",
      position: "right",
    },
    {
      element: "#sideMenu",
      intro: "功能模块导航栏",
      position: "right",
    },
    {
      element: "#headerSearch",
      intro: "搜索栏",
      position: "bottom"
    },
    {
      element: "#userAction",
      intro: "消息提醒与个人中心",
      position: "bottom"
    },
    {
      element: "#archive",
      intro: "文件列表区",
      position: "right"
    },
  ]
});

export const adminsiteIntro = getIntro({
  showButtons: false,
  steps: [
    {
      element: "#adminsiteStep",
      intro: "这是我的企业",
      position: "right",
    },
  ]
});

export const companyIntro = getIntro({
  tooltipClass: "intro-no-skip-and-end",
  steps: [
    {
      element: "#companyCheck",
      intro: "点击“申请认证”,可进行企业认证",
      position: "right",
    },
    {
      element: "#adminsiteUser",
      intro: "点击“用户管理”,管理公司成员",
      position: "right",
    },
  ],
});
export const userControlIntro = getIntro({
  tooltipClass: "intro-no-skip-and-end-and-next",
  steps: [
    {
      element: "#addUser",
      intro: "点击“新增”,邀请成员",
      position: "bottom",
    },
  ],
});

export const userAddIntro = getIntro({
  tooltipClass: "intro-useradd",
  steps: [
    {
      element: ".el-dialog__wrapper",
      intro: "通过邮箱或手机号邀请成员,并设置成员权限",
      position: "right",
    },
  ],
});

四、CSS

这里使用的是scss

.introjs {
  background-color: transparent !important;
  box-shadow: 0 0 8px 0 red !important;
}

.intro-base {
  width: 300px;
  font-size: 17px;
  border-radius: 8px;
  background-color: #fff;
  border: 1px solid #ebeef5;
  padding: 14px 26px 14px 13px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.4);
  &::before {
    content: "引导";
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    display: inline-block;
  }
  .introjs-button {
    font-size: 15px;
    color: #8ebcff;
    background: #fff;
    border: 1px solid #8ebcff;
  }
  .introjs-tooltiptext {
    text-indent: 2em;
  }
}

.intro-no-pre {
  @extend .intro-base;
  .introjs-prevbutton {
    display: none;
  }
}

.intro-no-skip {
  @extend .intro-no-pre;
  .introjs-skipbutton {
    display: none;
  }
  .introjs-donebutton {
    display: inline-block;
  }
}

.intro-no-skip-and-end {
  @extend .intro-no-skip;
  .introjs-skipbutton {
    display: none;
  }
}

.intro-no-skip-and-end-and-next {
  @extend .intro-no-skip-and-end;
  .introjs-nextbutton {
    display: none;
  }
}

.intro-useradd {
  @extend .intro-no-skip-and-end-and-next;
  left: calc(50% + 300px) !important;
  top: calc(15vh + 141px) !important;
  margin: 0 !important;
}

五、使用示例

import { homeIntro, adminsiteIntro } from "@/utils/intro";
adminsiteIntro.exit()  // 结束某个引导
homeIntro.start().oncomplete(async ()=>{
        await this.$store.commit('setIntro', {home:false})
      })  // 开始某个引导,引导完成后触发 vuex
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

泡泡码客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值