Files
car_client_app/utils/common.js
2024-03-22 17:55:26 +08:00

99 lines
2.1 KiB
JavaScript

/**
* 预览图片,并且长按保存
*
*/
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){
let url = res.tempFilePath
uni.saveImageToPhotosAlbum({
filePath:url,
success() {
uni.showToast({
title:'保存成功',
icon:"none"
})
},
fail(err) {
uni.showToast({
title:'保存失败',
icon:"none"
})
}
})
}
})
},
fail: (err) => {
}
}
});
}
/**
* 显示消息提示框
* @param 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)
}
})
})
}
/**
* 参数处理
* @param params 参数
*/
export function tansParams(params) {
let result = ''
for (const propName of Object.keys(params)) {
const value = params[propName]
var part = encodeURIComponent(propName) + "="
if (value !== null && value !== "" && typeof (value) !== "undefined") {
if (typeof value === 'object') {
for (const key of Object.keys(value)) {
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
let params = propName + '[' + key + ']'
var subPart = encodeURIComponent(params) + "="
result += subPart + encodeURIComponent(value[key]) + "&"
}
}
} else {
result += part + encodeURIComponent(value) + "&"
}
}
}
return result
}