pluginLoginAuth.ts 906 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { getScriptOptions } from '@/utils/common'
  2. const scriptOptions = getScriptOptions()
  3. class pluginLoginAuth {
  4. name: string
  5. options: any
  6. hooks: Record<string, Function>
  7. constructor(options = {}) {
  8. this.name = 'login'
  9. this.hooks = {}
  10. this.options = Object.assign(
  11. {
  12. auto: false,
  13. type: 'login-code'
  14. },
  15. scriptOptions,
  16. options
  17. )
  18. if (this.options.auto) {
  19. this.init()
  20. }
  21. }
  22. init() {
  23. // console.log('init', getScriptOptions())
  24. }
  25. use(context) {
  26. context.$emit('register-plugin-login-auth', this, {
  27. replay: true
  28. })
  29. }
  30. getInstance() {
  31. const hooks = this.hooks
  32. return hooks
  33. }
  34. register(hook, fn) {
  35. if (!this.hooks[hook]) {
  36. this.hooks[hook] = fn
  37. } else {
  38. console.warn('not register hook:', hook)
  39. }
  40. }
  41. }
  42. const LoginAuth = new pluginLoginAuth()
  43. export default LoginAuth