uni-item-manage/tm-vuetify/tool/function/preview.js
2023-10-18 15:52:41 +08:00

53 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 上传文件。
* 作者tmzdy
* 时间20217289:14:53
* 联系zhongjihan@sina.com
* 预览图片。
* @param {Object} url 必填 当前预览的图片链接。
* @param {Object} list 可以是url数组也可以是对象数据比如["http:url"] or [{url:"https:url",...}]
* @param {Object} rangKey 如果list是对象数组需要提供url字段。
*/
function previewImg(url,list,rangKey){
if(!url){
uni.$tm.toast("参数有误");
return;
}
if(arguments.length==1){
uni.previewImage({
current:url,
urls:list?list:[url]
})
}else if(arguments.length===3){
if(typeof list[0] === 'object' && typeof list[0] !== 'undefined'){
let urls = [];
list.forEach(item=>{
urls.push(item[rangKey]);
})
uni.previewImage({
current:url,
urls:urls,
fail: (er) => {
console.warn(er)
}
})
}else if(typeof list[0] === 'string'){
uni.previewImage({
current:url,
urls:list
})
}
}else{
uni.$tm.toast("参数有误");
}
}
export default previewImg