Commit c8f11bba authored by Damon's avatar Damon

拍照图片缓存到本地

parent 321432ba
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
</template> </template>
<script> <script>
import qiniup from '@/components/upload/qiniup'; import qiniup from '@/components/upload/qiniup';
import cache from '../../common/cache.js'
const app = getApp() const app = getApp()
export default { export default {
mixins: [qiniup], mixins: [qiniup],
...@@ -82,9 +83,9 @@ ...@@ -82,9 +83,9 @@
}) })
} }
} }
if(photo.currentItem){ // if(photo.currentItem){
photo.currentItem.imageList.unshift(photo.tempPath.mixWater) // photo.currentItem.imageList.unshift(photo.tempPath.mixWater)
} // }
// if(photo.productList && photo.productList[photo.topIndex]){ // if(photo.productList && photo.productList[photo.topIndex]){
// const topArr = photo.productList[photo.topIndex] // const topArr = photo.productList[photo.topIndex]
// if(topArr[photo.itemIndex]){ // if(topArr[photo.itemIndex]){
...@@ -94,7 +95,8 @@ ...@@ -94,7 +95,8 @@
// photo. // photo.
if(photo.tempPath.mixWater){ if(photo.tempPath.mixWater){
// 保存水印处理图片到本地 // 保存水印处理图片到本地
path = photo.tempPath.mixWater path = photo.tempPath.mixWater
this.saveToStroage(path) // 保存到本地缓存
let result1 = await this.saveLocal(path) let result1 = await this.saveLocal(path)
if(result1){ if(result1){
uni.showToast({ uni.showToast({
...@@ -103,6 +105,26 @@ ...@@ -103,6 +105,26 @@
}) })
} }
} }
},
saveToStroage(path) {
const photo = getApp().globalData.photo
const currentItem = photo.currentItem
uni.saveFile({
tempFilePath: path,
success(e) {
const { savedFilePath } = e
currentItem.imageList.unshift(savedFilePath)
// 从缓存数据中找到修改对象并替换
const data = cache.getCache(currentItem.system_id)
data.result.forEach(v => {
const index = v.list.findIndex(item => item._id === currentItem._id)
if (index > -1) {
v.list[index] = currentItem
}
})
cache.setCache(currentItem.system_id, data)
}
})
}, },
saveLocal(path){ saveLocal(path){
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
...@@ -145,8 +167,26 @@ ...@@ -145,8 +167,26 @@
uni.showLoading({ uni.showLoading({
title:'图片保存中…' title:'图片保存中…'
}) })
self.saveTempToLocal() self.saveTempToLocal()
self.confirmUpload(true) self.handleResult()
//self.confirmUpload(true)
},
handleResult() {
const photo = getApp().globalData.photo
if (photo.currentItemLength < 10) photo.currentItemLength = photo.currentItemLength + 1
uni.hideLoading()
console.log(photo)
// 当前项的图片显示
// 拍照项张数目增加 等于10张
if(photo.currentItemLength<10){
uni.navigateBack({
delta:1
})
}else{
uni.navigateBack({
delta:2
})
}
}, },
submitFile() { submitFile() {
let self = this let self = this
......
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