update
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
export const showToast = (options) => {
|
||||
if (typeof options === 'string') {
|
||||
uni.showToast({
|
||||
title: options,
|
||||
icon: 'none',
|
||||
title: options, icon: 'none',
|
||||
}).then();
|
||||
} else {
|
||||
uni.showToast(options).then();
|
||||
@@ -31,6 +30,7 @@ export const backPage = () => {
|
||||
}
|
||||
|
||||
export const copy = (context) => {
|
||||
// #ifndef APP-PLUS || MP-WEIXIN
|
||||
try {
|
||||
navigator.clipboard.writeText(context)
|
||||
.then(() => {
|
||||
@@ -42,10 +42,20 @@ export const copy = (context) => {
|
||||
} catch (e) {
|
||||
showToast('复制失败');
|
||||
}
|
||||
// #endif
|
||||
// #ifdef APP-PLUS || MP-WEIXIN
|
||||
uni.setClipboardData({
|
||||
data: context, success: () => {
|
||||
showToast('已复制');
|
||||
}, fail: () => {
|
||||
showToast('复制失败');
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
export const download = (urls) => {
|
||||
// #ifndef APP-PLUS
|
||||
// #ifndef APP-PLUS || MP-WEIXIN
|
||||
const promises1 = urls.map(url => new Promise((resolve, reject) => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.src = url;
|
||||
@@ -62,16 +72,14 @@ export const download = (urls) => {
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
const promises2 = urls.map(v => new Promise((resolve, reject) => {
|
||||
urls.forEach(v => {
|
||||
uni.downloadFile({
|
||||
url: v,
|
||||
success: () => {
|
||||
resolve(true);
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
}
|
||||
})
|
||||
uni.downloadFile({
|
||||
url: v,
|
||||
success: () => {
|
||||
resolve(true);
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
}
|
||||
})
|
||||
}));
|
||||
Promise.all(promises2).then(() => {
|
||||
@@ -80,4 +88,32 @@ export const download = (urls) => {
|
||||
showToast('保存失败');
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const promises3 = urls.map(v => new Promise((resolve, reject) => {
|
||||
uni.downloadFile({
|
||||
url: v,
|
||||
success: ({tempFilePath}) => {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: tempFilePath,
|
||||
success: () => {
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log(err);
|
||||
reject(false);
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
}
|
||||
})
|
||||
}));
|
||||
Promise.all(promises3).then(() => {
|
||||
showToast('保存成功');
|
||||
}).catch(() => {
|
||||
showToast('保存失败');
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user