useIntro.ts 1.2 KB

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