顶吸设置(sticky)
.stickyCont{
position: sticky;
top: 0;
background-color: #fff;
padding-bottom: 10rpx;
}
图片上传
wx.chooseMedia({
count:1,
mediaType:['image'],
sourceType:['album','camera'],
success(res){
// console.log(res.tempFiles[0].tempFilePath);
}
})
wx.getImageInfo({
src: tempFilePath,
success: res => {
wx.getFileSystemManager().readFile({
filePath: tempFilePath, // 图片路径
encoding: 'base64', // 转换为base64
success: res => {
// console.log(res.data); // 转换后的base64
that.imgORC(res.data);
},
fail: err => {
console.log(err);
}
})
}
})
// ORC文字识别
imgORC:function(imgUrl){
wx.showLoading({
title: '正在识别...',
});
var client_id = '5H8vomnbKXU1gDG4EihG825I';
var client_secret = 'GaKZZImjetAaCxdMt3UPLMGmA0wYZyRo';
wx.request({
url: "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret,
data: {},
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
//console.log(res);
var access_token = res.data.access_token;
var postData = {
image: imgUrl,
}
wx.request({
// url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=' + that.data.access_token,
url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/driving_license?access_token=' + access_token,
// url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=' + that.data.access_token,
// url: "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license?access_token=" + that.data.access_token,
data: postData,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
wx.showToast({
title: '识别成功',
icon: 'none',
duration:1500
})
setTimeout(function(){
wx.hideLoading();
console.log(res);
// console.log(Number(res.data.words_result[0].words));
wx.navigateTo({
url: '../user_detail/user_detail?item=' + encodeURIComponent(JSON.stringify(res.data.words_result)),
})
},1500);
},
})
}
})
},
- files 文件流上传(后端提供接口存储服务器)
wx.uploadFile/uni.uploadFile 官网提供,formData上传其他参数
uni.uploadFile({
url: 'https://upload.yutunyoupu.com/UploadFiles', //仅为示例,非真实的接口地址
// url:'https://jyglapi.jzxnm.com/api/common/uploads',
filePath: url,
name: 'files',
formData: {
bucket_name: 'minch',
folder_name: 'goods'
},
success(res2) {
console.log(res2);
// var res = JSON.parse(res2.data);
// if (res.code == 1) {
// that.setData({
// images: that.data.images.concat(res.data)
// });
// //调百度orc识别
// // that.imgORC(that.data.comImg+that.data.images[0]);
// } else {
// uni.showToast({
// title: '上传失败',
// icon: 'none', //当icon:'none'时,没有图标 只有文字
// image: '/images/icon/warn.png',
// duration: 1000
// });
// }
},
complete() {
uni.hideLoading();
}
})