Commit e51186ea authored by qipeng's avatar qipeng

图片保存

parent d3e48898
......@@ -18,12 +18,19 @@
</view>
<!--主体循环-->
<view class="album-subject">
<view class="subject-List" v-for="(item,index) in previewData" :key="index" >
<image class="list-image" :src="item.faceSourceUrl" @click="stopPhoto(index)"></image>
<u-checkbox v-model="item.checkType" v-if="checkTypeFun==true" @click.stop.native="()=>{}" @change="stopPhoto(index)" shape="circle" class="list-uCheck"></u-checkbox>
<template v-for="(item,index) in previewData">
<view class="suject-lable" :key="index">
<image src="../static/album/icon01.png"></image>
<view>{{item.merchantName}}</view>
</view>
</view>
<view class="album-subject" :key="index">
<view class="subject-List" v-for="(item2,index2) in item.list" :key="index2">
<image class="list-image" :src="item2.faceSourceUrl||item2.faceAiUrl" @click="stopPhoto(index,index2)"></image>
<u-checkbox v-model="item2.checkType" v-if="checkTypeFun==true" @click.stop.native="()=>{}" @change="stopPhoto(index,index2)" shape="circle" class="list-uCheck"></u-checkbox>
</view>
</view>
</template>
<!--脚部-->
<view class="album-bottom">
<view class="bottom-left" v-if="maskDetail==false">
......@@ -95,6 +102,8 @@ export default {
favorablePrice:0,//优惠
priceNum:0,//选购了多少照片
options:{},//参数
imgList:[],//下载图片列表
downImgNumber:0,//下载图片的数量
}
},
onLoad(option) {
......@@ -145,9 +154,9 @@ export default {
if(res.code=='00'){
this.previewData = res.data
this.previewData.forEach((item,index)=>{
item['checkType'] = false
this.originalPrice = item.originalPrice//原价.
this.sellingPrice = item.sellingPrice//售价
item.list.forEach((item2,index2)=>{
item2['checkType'] = false
})
})
}else{
this.$refs.uToast.show({
......@@ -173,14 +182,14 @@ export default {
cancel2() { //单列 点击取消
this.merchantShow = false
},
stopPhoto(index){//刷新显示
stopPhoto(index,index2){//刷新显示
if(this.checkProjectAll==true){
this.checkProjectAll=false
}
if(this.previewData[index].checkType==false){
this.previewData[index].checkType = true
this.previewData[index].list[index2].checkType = true
}else{
this.previewData[index].checkType = false
this.previewData[index].list[index2].checkType = false
}
this.checkTypeFun = false
this.checkTypeFun = true
......@@ -189,17 +198,101 @@ export default {
if(this.checkProjectAll==true){
this.checkProjectAll = false
this.previewData.forEach((item,index)=>{
item.checkType = false
item.list.forEach((item2,index2)=>{
item2.checkType = false
})
})
}else{
this.checkProjectAll = true
this.previewData.forEach((item,index)=>{
item.checkType = true
item.list.forEach((item2,index2)=>{
item2.checkType = true
})
})
}
},
upLoad(){//下单
this.previewData.forEach((item,index)=>{
item.list.forEach((item2,index2)=>{
var imgUrl = item2.faceSourceUrl||item2.faceAiUrl
this.imgList.push(imgUrl)
})
})
this.download()
},
//---点击下载
download(){
this.downImgNumber=0
this.imgList.forEach(item=>{
this.downloadFun(item)
})
},
//---下载方法
downloadFun(imgUrl) {
uni.showLoading({
title: '下载中',
mask: true
})
let fileName = new Date().getTime()
uni.downloadFile({ //下载文件资源到本地
url:imgUrl,
filePath: wx.env.USER_DATA_PATH + '/' + fileName + '.jpg', //filePath指定文件下载后存储的路径,wx.env.USER_DATA_PATH,时间戳为文件名
success: res => { //下载到本地成功
if(res.statusCode==200){
let filePath = res.filePath
uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
filePath,
success: file => { //保存成功
this.downImgNumber+=1
if(this.downImgNumber==this.imgList.length){
uni.showToast({
title: '下载成功',
icon: 'success',
mask: true
})
}
},
fail: err => {
uni.hideLoading()
this.getPermissions(err)
}
})
}
},
fail: err => { //下载失败
uni.hideLoading()
uni.showToast({
title: '下载失败',
icon: 'none',
mask: true
})
}
})
},
//---获取授权
getPermissions(err){
//拒绝授权时显示
if (err.errMsg.includes('fail auth deny')) {
uni.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,
success: data => {
//打开权限设置
uni.openSetting({
success: setting => {
if (!setting.authSetting['scope.writePhotosAlbum']) {
uni.showModal({
title: '提示',
content: '获取权限失败无法保存到相册',
showCancel: false,
})
}
},
})
}
})
}
},
}
}
......@@ -217,7 +310,7 @@ export default {
height: 100%;
background-color: #F7F7F7;
padding-bottom: 98rpx;
padding-top: 174rpx;
padding-top: 144rpx;
overflow: auto;
}
......@@ -262,7 +355,23 @@ export default {
display: none;
}
.suject-lable{
display: flex;
height: 44rpx;
margin-bottom: 24rpx;
padding: 0 24rpx 0 24rpx;
image{
display: block;
width: 32rpx;
height: 32rpx;
margin: 6rpx 6rpx 0 0;
}
view{
font-size: 32rpx;
color: #333333;
line-height: 44rpx;
}
}
.album-subject {
display: flex;
flex-wrap: wrap;
......@@ -270,7 +379,7 @@ export default {
flex: 1;
padding: 0 24rpx 0 24rpx;
overflow: auto;
.subject-List {
width: 344rpx;
height: 344rpx;
......@@ -323,6 +432,7 @@ export default {
display: flex;
line-height: 98rpx;
.album-checkAll {
display: flex;
width: 100%;
height: 98rpx;
padding: 0rpx 24rpx 0 0rpx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment