- bug: IOS / wx.chooseImage
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 }) } }) } } })
2017-07-11 - wx:chooseImage怎样阻止调用onHide和onShow?
公司项目在手机上测试时,评论上传图片时,选择完图片就会刷新页面
2017-08-03 - wx:chooseImage怎样阻止刷新页面?
公司项目在手机上测试时,评论上传图片时,选择完图片就会刷新页面
2017-08-03 - 上传图片会刷新页面,数据会重新加载
[图片] 如果我执行上传图片,上传一次就会重新加载数据,以前用户填写的数据就都没了, 开发工具是这样,手机也是这样
2017-12-28 - wx.uploadfile 上传成功后页面会刷新
[代码]wx.uploadFile({[代码][代码] [代码][代码]url: api + [代码][代码]'files/upload'[代码][代码],[代码][代码] [代码][代码]filePath: res.tempFilePaths[i],[代码][代码] [代码][代码]name: [代码][代码]'file'[代码][代码],[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]"content-type"[代码][代码]: [代码][代码]"multipart/form-data"[代码][代码],[代码][代码] [代码][代码]"x-auth-token"[代码][代码]: that.data.token[代码][代码] [代码][代码]},[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]let data = JSON.parse(res.data);[代码][代码] [代码][代码]that.data.uploadFileList.push(data.path)[代码][代码] [代码][代码]wx.hideLoading();[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]wx.hideLoading();[代码][代码] [代码][代码]wx.showToast({[代码][代码] [代码][代码]title: [代码][代码]'上传失败!'[代码][代码],[代码][代码] [代码][代码]icon: [代码][代码]'none'[代码][代码],[代码][代码] [代码][代码]duration: 1000[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码]因为这个图片上传之后会刷新页面,导致我页面上面的数据都被初始化了,这个问题请问下大家该如何解决?
2018-08-04