123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import methods from "@/common/methodTool";
- export function download(url) {
- // #ifdef H5
- window.location.href = url;
- // #endif
- // #ifdef MP-WEIXIN
- const _s = saveImgToLoca;
- uni.getSetting({
- success: (res) => {
- if (!res.authSetting["scope.writePhotosAlbum"]) {
- uni.authorize({
- scope: "scope.writePhotosAlbum",
- success() {
- _s(url);
- },
- fail() {},
- });
- } else {
- _s(url);
- }
- },
- });
- // #endif
- }
- function saveImgToLoca(url) {
- uni.downloadFile({
- url: url, //图片地址
- success: ({ statusCode, tempFilePath }) => {
- if (statusCode === 200) {
- const type = tempFilePath.substr(tempFilePath.lastIndexOf(".") + 1);
- console.log("🚀 ~ file: util.js:32 ~ saveImgToLoca ~ type:", type);
- if (type === "pdf") {
- uni.getFileSystemManager().saveFile({
- tempFilePath,
- success: function (res) {
- console.log("🚀 ~ file: util.js:37 ~ uni.getFileSystemManager ~ res:", res)
- uni.showToast({
- title: "保存成功",
- icon: "none",
- });
- },
- fail: function () {
- uni.showToast({
- title: "保存失败",
- icon: "none",
- });
- },
- });
- return;
- }
- uni.showModal({
- title: "提示",
- content: "确定保存到相册吗",
- success: (res) => {
- if (res.confirm) {
- uni.saveImageToPhotosAlbum({
- filePath: tempFilePath,
- success: function () {
- uni.showToast({
- title: "保存成功",
- icon: "none",
- });
- },
- fail: function () {
- uni.showToast({
- title: "保存失败",
- icon: "none",
- });
- },
- });
- }
- },
- });
- }
- },
- });
- }
|