previewImage.ts 908 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
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
import { isArray } from '@vue/shared'
import { MPProtocol } from './types'

export const previewImage: MPProtocol = {
  args(
    fromArgs: UniApp.PreviewImageOptions,
    toArgs: WechatMiniprogram.PreviewImageOption
  ) {
    let currentIndex = parseInt(fromArgs.current as string)
    if (isNaN(currentIndex)) {
      return
    }
    const urls = fromArgs.urls
    if (!isArray(urls)) {
      return
    }
    const len = urls.length
    if (!len) {
      return
    }
    if (currentIndex < 0) {
      currentIndex = 0
    } else if (currentIndex >= len) {
      currentIndex = len - 1
    }
    if (currentIndex > 0) {
      toArgs.current = urls[currentIndex]
      toArgs.urls = urls.filter((item, index) =>
        index < currentIndex ? item !== urls[currentIndex] : true
      )
    } else {
      toArgs.current = urls[0]
    }
    return {
      indicator: false,
      loop: false,
    }
  },
}