保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
 * @file vue-awesome-swiper
 * @module exporter
 * @author Surmon <https://github.com/surmon-china>
 */
 
import Swiper, { SwiperOptions } from 'swiper'
import _Vue, { PluginFunction } from 'vue'
import { CoreNames } from './constants'
import getDirective from './directive'
import getSwiperComponent from './swiper'
import SwiperSlideComponent from './slide'
 
export interface InstallFunction extends PluginFunction<SwiperOptions> {
  installed?: boolean
}
 
const getInstaller = (SwiperClass: typeof Swiper) => {
  const install: InstallFunction = (Vue: typeof _Vue, globalOptions?: SwiperOptions) => {
    if (install.installed) return
 
    const SwiperComponent = getSwiperComponent(SwiperClass)
    if (globalOptions) {
      (SwiperComponent as any).options.props.defaultOptions.default = () => globalOptions
    }
  
    Vue.component(CoreNames.SwiperComponent, SwiperComponent)
    Vue.component(CoreNames.SwiperSlideComponent, SwiperSlideComponent)
    Vue.directive(CoreNames.SwiperDirective, getDirective(SwiperClass, globalOptions))
    install.installed = true
  }
  return install
}
 
export default function exporter(SwiperClass: typeof Swiper) {
  return {
    version: 'PACKAGE_VERSION',
    install: getInstaller(SwiperClass),
    directive: getDirective(SwiperClass),
    [CoreNames.SwiperComponent as const]: getSwiperComponent(SwiperClass),
    [CoreNames.SwiperSlideComponent as const]: SwiperSlideComponent
  }
}