Skip to content

Commit

Permalink
fix(type): update params type of previewImage, add mapkey type for sh… (
Browse files Browse the repository at this point in the history
#14067)

* fix(type): update params type of previewImage, add mapkey type for share-element

#14053

* fix: previewImage current prop compatible due to type change
  • Loading branch information
TheKonka authored Jun 26, 2023
1 parent 10b66fc commit b715e83
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions packages/taro-components/types/ShareElement.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { StandardProps, CommonEventFunction } from './common'
interface ShareElementProps extends StandardProps {
/** 映射标记
* @supported weapp
* @deprecated 使用mapkey替换key
*/
key?: string
/** 映射标记
* @supported weapp
*/
mapkey?: string
/** 映射标记
* @supported alipay
*/
Expand Down
18 changes: 10 additions & 8 deletions packages/taro-h5/src/api/media/image/previewImage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Taro from '@tarojs/api'
import { SwiperProps } from '@tarojs/components'
import { defineCustomElementTaroSwiperCore, defineCustomElementTaroSwiperItemCore } from '@tarojs/components/dist/components'
import {
defineCustomElementTaroSwiperCore,
defineCustomElementTaroSwiperItemCore,
} from '@tarojs/components/dist/components'
import { isFunction } from '@tarojs/shared'

import { shouldBeObject } from '../../../utils'
Expand Down Expand Up @@ -52,7 +55,8 @@ export const previewImage: typeof Taro.previewImage = async (options) => {
const handle = new MethodHandler({ name: 'previewImage', success, fail, complete })
const container = document.createElement('div')
container.classList.add('preview-image')
container.style.cssText = 'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;'
container.style.cssText =
'position:fixed;top:0;left:0;z-index:1050;width:100%;height:100%;overflow:hidden;outline:0;background-color:#111;'
container.addEventListener('click', () => {
container.remove()
})
Expand All @@ -65,12 +69,10 @@ export const previewImage: typeof Taro.previewImage = async (options) => {

let children: Node[] = []
try {
children = await Promise.all(
urls.map(e => loadImage(e, fail))
)
children = await Promise.all(urls.map((e) => loadImage(e, fail)))
} catch (error) {
return handle.fail({
errMsg: error
errMsg: error,
})
}

Expand All @@ -79,8 +81,8 @@ export const previewImage: typeof Taro.previewImage = async (options) => {
swiper.appendChild(child)
}

const currentIndex = urls.indexOf(current)
// @ts-ignore
const currentIndex = typeof current === 'number' ? current : urls.indexOf(current)

swiper.current = currentIndex

container.appendChild(swiper)
Expand Down
22 changes: 17 additions & 5 deletions packages/taro/types/api/media/image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ declare module '../../index' {
interface Option {
/** 需要预览的图片链接列表。 */
urls: string[]
/** 当前显示图片的链接 */
current?: string
/** @support weapp 最低版本:2.13.0。是否显示长按菜单,默认值:true */
/**
* 微信端为当前显示图片的链接,支付宝端为当前显示图片的索引值
*/
current?: string | number
/**
* 是否支持长按下载图片
* @supported alipay 基础库: 1.13.0
*/
enablesavephoto?: boolean
/**
* 是否在右下角显示下载入口
* @supported alipay 基础库: 1.13.0
*/
enableShowPhotoDownload?: boolean
/** @supported weapp 最低版本:2.13.0。是否显示长按菜单,默认值:true */
showmenu?: boolean
/** @support weapp 最低版本:2.13.0。origin: 发送完整的referrer; no-referrer: 不发送。格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本;默认值:no-referrer */
/** @supported weapp 最低版本:2.13.0。origin: 发送完整的referrer; no-referrer: 不发送。格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本;默认值:no-referrer */
referrerPolicy?: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: (res: TaroGeneral.CallbackResult) => void
Expand All @@ -46,7 +58,7 @@ declare module '../../index' {
/** 需要预览的资源列表 */
sources: Sources[]
/** 当前显示的资源序号,默认值:0 */
current?: number
current?: number
/** 是否显示长按菜单 2.13.0,默认值:true */
showmenu?: boolean
/** origin: 发送完整的referrer; no-referrer: 不发送。格式固定为 https://servicewechat.com/{appid}/{version}/page-frame.html,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本;默认值:no-referrer */
Expand Down

0 comments on commit b715e83

Please sign in to comment.