赞
踩
<downReport :dataImage="dataImage"></downReport>
- <view class="down-report">
- <view class="down-btn" @click="downReport">下载报告</view>
- </view>
- <script>
- export default {
- props: ["dataImage"],
- methods: {
- // 用户下载图片并授权相册权限
- downLoadFile() {
- uni.downloadFile({
- url: this.dataImage, //图片地址
- success: function(res) {
- console.log('resvvv', res);
- //wx.saveImageToPhotosAlbum方法:保存图片到系统相册
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath, //图片文件路径
- success: function(data) {
- uni.hideLoading(); //隐藏 loading 提示框
- uni.showModal({
- title: '提示',
- content: '保存成功',
- modalType: false,
- })
- },
- // 接口调用失败的回调函数
- fail: function(err) {
- if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err
- .errMsg === "saveImageToPhotosAlbum:fail auth deny" || err
- .errMsg === "saveImageToPhotosAlbum:fail authorize no response"
- ) {
- wx.showModal({
- title: '提示',
- content: '需要您授权保存相册',
- modalType: false,
- success: modalSuccess => {
- wx.openSetting({
- success(settingdata) {
- console.log("settingdata",
- settingdata)
- if (settingdata
- .authSetting[
- 'scope.writePhotosAlbum'
- ]) {
- wx.showModal({
- title: '提示',
- content: '获取权限成功,再次点击图片即可保存',
- modalType: false,
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '获取权限失败,将无法保存到相册哦~',
- modalType: false,
- })
- }
- },
- fail(failData) {
- console.log("failData",
- failData)
- },
- complete(finishData) {
- console.log("finishData",
- finishData)
- }
- })
- }
- })
- }
- },
- complete(res) {
- wx.hideLoading(); //隐藏 loading 提示框
- }
- })
- }
- })
- },
- downReport() {
- console.log('下载报告');
- uni.showLoading({
- title: '加载中...'
- });
- this.downLoadFile()
- }
- }
- }
- </script>
- <style lang="scss">
- .down-report {
- height: 182rpx;
- margin-top: 29rpx;
- // border: 1px solid green;
- position: relative;
- background-color: #fff;
-
- .down-btn {
- width: 690rpx;
- height: 90rpx;
- line-height: 90rpx;
- background: #C41335;
- border-radius: 45rpx;
- position: absolute;
- left: 50%;
- top: 20rpx;
- transform: translateX(-50%);
- text-align: center;
- font-size: 30rpx;
- color: #fff;
- }
- }
- </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。