async imageOrLocation (index, cameraOnly) {
let item = this.picture[index]
if (item.restrictiveConditionDto.requireGeographyInfo) {
this.getLocationRequired(index, cameraOnly)
} else {
this.chooseImage(index, cameraOnly)
}
},
chooseImage (index, cameraOnly) {
let vue = this
// let sourceType = cameraOnly ? ['camera'] : ['album', 'camera']
wechatlib.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: async function (res) {
vue.$set(vue.picture[index], 'src', res.localIds[0])
vue.uploadImage(res.localIds[0], index)
},
fail: function () {
vue.toast('选择图片失败')
}
})
},
getLocalImageDate (localID, index) {
let vue = this
wechatlib.getLocalImgData({
localId: localID,
success: function (res) {
vue.picture[index].src = res.localData
},
fail: function () {
vue.toast('获取本地图片失败')
}
})
},
async getLocationRequired (index, cameraOnly) {
this.indicator('地理位置获取中')
let vue = this
let indicator = true
setTimeout(() => {
if (indicator) {
Indicator.close()
vue.messageBoxB()
}
}, 5000)
await wechatlib.getLocation({
type: 'wgs84',
success: function (res) {
vue.picture[index].location = res.latitude.toString() + ',' + res.longitude.toString()
Indicator.close()
indicator = false
vue.chooseImage(index, cameraOnly)
},
fail: function (res) {
alert(JSON.stringify(res))
vue.messageBoxB()
Indicator.close()
indicator = false
},
cancel: function () {
vue.messageBoxA()
Indicator.close()
indicator = false
}
})
},
async uploadImage (localId, index) {
let vue = this
vue.indicator('上传中')
await wechatlib.uploadImage({
localId: localId,
isShowProgressTips: 0,
success: async function (res) {
vue.picture[index].value = await api.postImage(vue.$route.params.id, res.serverId)
let u = navigator.userAgent
let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
if (isIOS) {
vue.getLocalImageDate(localId, index)
}
Indicator.close()
},
fail: function () {
vue.toast('图片上传失败,请重试')
Indicator.close()
}
})
},