update at 2026-02-08 18:28:39
This commit is contained in:
110
miniprogram/utils/mp/wx-promisify.js
Normal file
110
miniprogram/utils/mp/wx-promisify.js
Normal file
@@ -0,0 +1,110 @@
|
||||
function request(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.request({
|
||||
...options,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function downloadFile(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.downloadFile({
|
||||
...options,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function saveImageToPhotosAlbum(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function canvasToTempFilePath(options, component) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.canvasToTempFilePath(
|
||||
{
|
||||
...options,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
},
|
||||
component
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function readFile(filePath, encoding) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.readFile({
|
||||
filePath,
|
||||
encoding,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function writeFile(filePath, data, encoding) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.writeFile({
|
||||
filePath,
|
||||
data,
|
||||
encoding,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function saveFile(tempFilePath, filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fs = wx.getFileSystemManager()
|
||||
fs.saveFile({
|
||||
tempFilePath,
|
||||
filePath,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function openSetting() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.openSetting({
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function showModal(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.showModal({
|
||||
...options,
|
||||
success: resolve,
|
||||
fail: reject,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
request,
|
||||
downloadFile,
|
||||
saveImageToPhotosAlbum,
|
||||
canvasToTempFilePath,
|
||||
readFile,
|
||||
writeFile,
|
||||
saveFile,
|
||||
openSetting,
|
||||
showModal,
|
||||
}
|
||||
Reference in New Issue
Block a user