'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {
  getRealPath
} from '../util'
 
import {
  publish
} from '../../bridge'
 
import {
  t
} from 'uni-core/helpers/i18n'
 
export function previewImagePlus ({
  current = 0,
  background = '#000000',
  indicator = 'number',
  loop = false,
  urls,
  longPressActions
} = {}) {
  urls = urls.map(url => getRealPath(url))
 
  const index = Number(current)
  if (isNaN(index)) {
    current = urls.indexOf(getRealPath(current))
    current = current < 0 ? 0 : current
  } else {
    current = index
  }
 
  plus.nativeUI.previewImage(urls, {
    current,
    background,
    indicator,
    loop,
    onLongPress: function (res) {
      let itemList = []
      let itemColor = ''
      let title = ''
      const hasLongPressActions = longPressActions && longPressActions.callbackId
      if (!hasLongPressActions) {
        itemList = [t('uni.previewImage.button.save')]
        itemColor = '#000000'
        title = ''
      } else {
        itemList = longPressActions.itemList ? longPressActions.itemList : []
        itemColor = longPressActions.itemColor ? longPressActions.itemColor : '#000000'
        title = longPressActions.title ? longPressActions.title : ''
      }
 
      const options = {
        buttons: itemList.map(item => ({
          title: item,
          color: itemColor
        })),
        cancel: t('uni.previewImage.cancel')
      }
      if (title) {
        options.title = title
      }
      plus.nativeUI.actionSheet(options, (e) => {
        if (e.index > 0) {
          if (hasLongPressActions) {
            publish(longPressActions.callbackId, {
              errMsg: 'showActionSheet:ok',
              tapIndex: e.index - 1,
              index: res.index
            })
            return
          }
          plus.gallery.save(res.url, function (GallerySaveEvent) {
            plus.nativeUI.toast(t('uni.previewImage.save.success'))
          }, function () {
            plus.nativeUI.toast(t('uni.previewImage.save.fail'))
          })
        } else if (hasLongPressActions) {
          publish(longPressActions.callbackId, {
            errMsg: 'showActionSheet:fail cancel'
          })
        }
      })
    }
  })
  return {
    errMsg: 'previewImage:ok'
  }
}
 
export function closePreviewImagePlus () {
  try {
    plus.nativeUI.closePreviewImage()
    return {
      errMsg: 'closePreviewImagePlus:ok'
    }
  } catch (error) {
    return {
      errMsg: 'closePreviewImagePlus:fail'
    }
  }
}