add 预览图片,并且长按保存 工具类

This commit is contained in:
heyi
2023-07-26 19:31:53 +08:00
parent 9fc69a0fb0
commit e7b00d50ac

View File

@@ -1,32 +1,79 @@
/**
* 预览图片,并且长按保存
*
*/
export function previewImageAndSave(images, index) {
uni.previewImage({ // 预览图片 图片路径必须是一个数组 => ["http://192.168.100.251:8970/6_1597822634094.png"]
current: index,
urls: images,
longPressActions: { //长按保存图片到相册
itemList: ['保存图片'],
success: (data) => {
uni.downloadFile({
url:images[data.index],
success(res){
console.log(res)
let url = res.tempFilePath
uni.saveImageToPhotosAlbum({
filePath:url,
success() {
uni.showToast({
title:'保存成功',
icon:"none"
})
},
fail(err) {
uni.showToast({
title:'保存失败',
icon:"none"
})
}
})
}
})
},
fail: (err) => {
console.log(err.errMsg);
}
}
});
}
/**
* 显示消息提示框
* @param content 提示的标题
*/
export function toast(content) {
uni.showToast({
icon: 'none',
title: content
})
}
*/
export function toast(content) {
uni.showToast({
icon: 'none',
title: content
})
}
/**
* 显示模态弹窗
* @param content 提示的标题
*/
export function showConfirm(content) {
return new Promise((resolve, reject) => {
uni.showModal({
title: '提示',
content: content,
cancelText: '取消',
confirmText: '确定',
success: function(res) {
resolve(res)
}
})
})
}
*/
export function showConfirm(content) {
return new Promise((resolve, reject) => {
uni.showModal({
title: '提示',
content: content,
cancelText: '取消',
confirmText: '确定',
success: function(res) {
resolve(res)
}
})
})
}
/**
* 参数处理
* @param params 参数