123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <template>
- <view>
-
- <view>
- <image show-menu-by-longpress="true" :src=url ></image>
-
- </view>
- <button class="downBtn" @tap="savePoster()">图像下载</button>
-
- <view class="progress-container" v-if="isShowProgress">
- <view class="progress-box">
- <view class="text">文件下载中,请稍后...</view>
- <progress :percent="progress" show-info stroke-width="3" />
- </view>
- </view>
-
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- url: 'http://125.71.216.35:9001/dcm/27/image-00001.png',
-
- isShowProgress: false,
- progress: 0,
- }
- },
- methods: {
- savePoster() {
- uni.getSetting({
- success: (res) => {
- if (res.authSetting['scope.writePhotosAlbum']) {
-
- this.downloadFile()
- } else {
- uni.authorize({
- scope: 'scope.writePhotosAlbum',
- success: () => {
-
- this.downloadFile()
- },
- fail: () => {
- uni.showToast({
- title: "请打开保存相册权限,再点击图像下载",
- icon: "none",
- duration: 3000
- });
- setTimeout(() => {
- uni.openSetting({
- success: (res2) => {
-
- }
- });
- }, 3000);
- }
- })
- }
- }
- })
- },
-
- downloadFile() {
- const downloadTask = uni.downloadFile({
- url: this.url,
- success: res => {
- if (res.statusCode === 200) {
- this.isShowProgress = false;
-
- }
- let that = this;
-
-
-
-
- uni.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function(red) {
-
- that.isShowProgress = false;
- uni.showToast({
- title: '图像已存入相册',
-
- icon: 'success',
-
- duration: 3000
- })
- }
- });
- }
- })
-
- downloadTask.onProgressUpdate((res) => {
- if(res.progress > 0) {
- this.isShowProgress = true;
- }
- this.progress = res.progress;
-
-
-
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- page{
- height: 100%;
- background-color: #000;
- }
- .downBtn{
- margin-top: 50%;
- width: 30%;
- height: 70rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
- background: #05c86d;
- font-size: 32rpx;
- border-radius: 50rpx;
- }
- .progress-container{
- position: fixed;
- top: 0;
- left: 0;
- z-index: 99;
- background: rgba(0, 0, 0, .2);
- width: 750rpx;
- height: 100vh;
- display: flex;
- align-items: center;
- justify-content: center;
- .progress-box{
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 30rpx;
- .text{
- margin-bottom: 20rpx;
- }
- }
- }
- </style>
|