111 lines
1.9 KiB
JavaScript
111 lines
1.9 KiB
JavaScript
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,
|
|
}
|