useIntro.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import introJs from 'intro.js'
  2. import { IntroJs, Step, Options } from 'intro.js'
  3. import 'intro.js/introjs.css'
  4. import { useDesign } from '@/hooks/web/useDesign'
  5. export const useIntro = (setps?: Step[], options?: Options) => {
  6. const { t } = useI18n()
  7. const { variables } = useDesign()
  8. const defaultSetps: Step[] = setps || [
  9. {
  10. element: `#${variables.namespace}-menu`,
  11. title: t('common.menu'),
  12. intro: t('common.menuDes'),
  13. position: 'right'
  14. },
  15. {
  16. element: `#${variables.namespace}-tool-header`,
  17. title: t('common.tool'),
  18. intro: t('common.toolDes'),
  19. position: 'left'
  20. },
  21. {
  22. element: `#${variables.namespace}-tags-view`,
  23. title: t('common.tagsView'),
  24. intro: t('common.tagsViewDes'),
  25. position: 'bottom'
  26. }
  27. ]
  28. const defaultOptions: Options = options || {
  29. prevLabel: t('common.prevLabel'),
  30. nextLabel: t('common.nextLabel'),
  31. skipLabel: t('common.skipLabel'),
  32. doneLabel: t('common.doneLabel')
  33. }
  34. const introRef: IntroJs = introJs()
  35. introRef.addSteps(defaultSetps).setOptions(defaultOptions)
  36. return {
  37. introRef
  38. }
  39. }