IOS 拍照完成后,点击使用,会立即刷新页面。上个版本是没有问题的,新版本更新才出现这个问题
完整demo:
var fetch = require('../../comm/script/fetch');
var config = require('../../comm/script/config');
var message = require('../../component/message/message');
const BORROW_CONTAINER = 'BORROW_CONTAINER'
const ORDER_CABINETREARDOOR = 'ORDER_CABINETREARDOOR'
const ORDER_SEALS = 'ORDER_SEALS'
Page({
data:{
orderId: '',
status: '',
loading: false,
disabled: true, // 确认按钮是否可点击
info: null,
attchList: []
},
onLoad: function(params) {
// 请求接口加载数据
// 转换数据
this.setData({
orderId: params.id,
status: params.status,
loaded: false
})
let data = {
orderId: params.id,
sectionName: BORROW_CONTAINER
}
this.fetchList(data)
},
onShow: function() {
// 请求接口加载数据
// 转换数据
let data = {
orderId: this.data.orderId,
sectionName: BORROW_CONTAINER
}
this.fetchList(data)
},
fetchList: function(params,cb) {
wx.showNavigationBarLoading();
fetch.orderContainer.call(this, config.apiList.orderContainer, 'GET', params, json => {
wx.hideNavigationBarLoading();
this.setData({
loaded: true
})
// 如果成功
if (json.result) {
let info = Object.assign({}, json.data, {
ghm: !!json.data.Attachs[0] ? [json.data.Attachs[0]] : [],
ft: !!json.data.Attachs[1] ? [json.data.Attachs[1]] : []
})
this.setData({
info: info
})
this._disabled()
cb && cb(json.data);
}
})
},
showModal: function(e) {
let that = this
let data = e.currentTarget.dataset;
wx.showModal({
title: '提示',
content: '是否删除该图片?',
success: function(res) {
if (res.confirm) {
that.data.info[data.field] = []
that.setData({
info: Object.assign({},that.data.info)
})
that._disabled()
} else if (res.cancel) {
}
}
})
},
showActionSheet(e) {
let that = this
let data = e.currentTarget.dataset
wx.showActionSheet({
itemList: ['拍照'],
success: function(res) {
if (res.tapIndex == 1) {
that.chooseImage(['album'],data.field);
} else if(res.tapIndex == 0){
that.chooseImage(['camera'],data.field);
}
},
fail: function(res) {
console.log(res.errMsg)
}
})
},
chooseImage(sourceType, field) {
let that = this;
wx.chooseImage({
count: 1, // 最多选9张
sizeType: ['origin', 'compressed'],
sourceType,
success: (res) => {
//
let tempFilePaths = res.tempFilePaths
// 成功后,需将本地文件存储起来。
/* wx.saveFile({
tempFilePath: tempFilePaths[0],
success: function(res) {
var savedFilePath = res.savedFilePath
}
})*/
//let data = that.data.info[field].concat(tempFilePaths)
that.data.info[field] = tempFilePaths
that.setData({
info: Object.assign({},that.data.info)
})
that._disabled()
}
})
},
closePage: function() {
wx.navigateBack()
},
preViewImage: function(e) {
let src = e.currentTarget.dataset.src
wx.previewImage({
current: src, // 当前显示图片的http链接
urls: [src] // 需要预览的图片http链接列表
})
},
changeInput: function(e) {
let value = e.detail.value
let field = e.currentTarget.dataset.field
this.data.info[field] = value
this.setData({
info: this.data.info
})
this._disabled()
},
_disabled: function() {
let { SerialNumOfBookingNum, TankNo, SealNumber, ArkHeavy, ghm, ft, BookingNum } = this.data.info
let disabled = !!TankNo && !!SealNumber && !!ArkHeavy
&& !!BookingNum && ghm.length > 0 && ft.length > 0
this.setData({
disabled: !disabled
})
},
submitInfo: function() {
this.setData({
loading: true,
disabled: true,
attchList: []
})
// 2张图片
fetch.upaloadImage.call(this, config.apiList.orderContainerImage, 'ORDER_CABINETREARDOOR', this.data.info.ghm[0], {
orderId: this.data.orderId,
businessKey: ORDER_CABINETREARDOOR
}, json => {
wx.hideToast();
console.log(json)
// 如果成功
if (json.result) {
console.log(json.data)
this.saveInfo(json.data)
} else {
this.setData({
loading: false,
disabled: false
})
}
})
// 第二张图片
fetch.upaloadImage.call(this, config.apiList.orderContainerImage, 'ORDER_SEALS', this.data.info.ft[0], {
orderId: this.data.orderId,
businessKey: ORDER_SEALS
}, json => {
console.log(json)
// 如果成功
if (json.result) {
console.log(json.data)
this.saveInfo(json.data)
} else {
this.setData({
loading: false,
disabled: false
})
}
})
},
saveInfo: function(data) {
let _data = !!data ? JSON.parse(data) : []
let attchList = []
let that = this
if (_data.length > 0) {
this.data.attchList.push({
FileStoreId: _data[0],
AttachmentId: _data[1]
})
}
// 2张图片上传成功后
if (this.data.attchList.length == 2) {
let params = {
OrderId: this.data.orderId,
SerialNumOfBookingNum: this.data.info.SerialNumOfBookingNum,
TankNo: this.data.info.TankNo,
SealNumber: this.data.info.SealNumber,
ArkHeavy: this.data.info.ArkHeavy,
Attachments: this.data.attchList
}
fetch.saveProcess.call(this, config.apiList.orderContainer, 'POST', params, json => {
// 如果成功
if (json.result) {
message.show.call(that,{
content: '保存成功',
icon: 'success',
duration: 2000
})
setTimeout(() => {
// 失败则直接重定向
/*let pages = getCurrentPages().length
if (pages > 4) {
wx.navigateTo({
url: `/pages/recievedDetail/recievedDetail?id=${this.data.orderId}`,
})
} else {
wx.redirectTo({
url: `/pages/recievedDetail/recievedDetail?id=${this.data.orderId}`
})
}*/
wx.switchTab({
url: `/pages/recievedOrder/recievedOrder`
})
}, 2000)
} else {
this.setData({
loading: false,
disabled: false
})
}
})
}
}
})
你说的立即刷新页面是指什么?
请提供可复现问题的完整demo。
避免使用onshow尽量使用onload可以解决这个问题
ios拍照上传闪退 很久了
嗯。
怎么这个bug还没修复?
页面再次调用 生命周期函数 onHide。再接着 调用 onShow
ios 微信最新版本,官方的例子都是这样的。