Blogger Information
Blog 87
fans 1
comment 0
visits 58338
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
余囤、二维小程序杂记
阿杰
Original
161 people have browsed it

顶吸设置(sticky)

  • css部分
  1. .stickyCont{
  2. position: sticky;
  3. top: 0;
  4. background-color: #fff;
  5. padding-bottom: 10rpx;
  6. }

图片上传

  • 官方上传图片接口调用
  1. wx.chooseMedia({
  2. count:1,
  3. mediaType:['image'],
  4. sourceType:['album','camera'],
  5. success(res){
  6. // console.log(res.tempFiles[0].tempFilePath);
  7. }
  8. })
  • base64格式(ORC驾驶证识别用到)
  1. wx.getImageInfo({
  2. src: tempFilePath,
  3. success: res => {
  4. wx.getFileSystemManager().readFile({
  5. filePath: tempFilePath, // 图片路径
  6. encoding: 'base64', // 转换为base64
  7. success: res => {
  8. // console.log(res.data); // 转换后的base64
  9. that.imgORC(res.data);
  10. },
  11. fail: err => {
  12. console.log(err);
  13. }
  14. })
  15. }
  16. })
  17. // ORC文字识别
  18. imgORC:function(imgUrl){
  19. wx.showLoading({
  20. title: '正在识别...',
  21. });
  22. var client_id = '5H8vomnbKXU1gDG4EihG825I';
  23. var client_secret = 'GaKZZImjetAaCxdMt3UPLMGmA0wYZyRo';
  24. wx.request({
  25. url: "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret,
  26. data: {},
  27. method: 'POST',
  28. header: {
  29. 'content-type': 'application/x-www-form-urlencoded'
  30. },
  31. success: function (res) {
  32. //console.log(res);
  33. var access_token = res.data.access_token;
  34. var postData = {
  35. image: imgUrl,
  36. }
  37. wx.request({
  38. // url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic?access_token=' + that.data.access_token,
  39. url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/driving_license?access_token=' + access_token,
  40. // url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=' + that.data.access_token,
  41. // url: "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license?access_token=" + that.data.access_token,
  42. data: postData,
  43. method: 'POST',
  44. header: {
  45. 'content-type': 'application/x-www-form-urlencoded'
  46. },
  47. success: function (res) {
  48. wx.showToast({
  49. title: '识别成功',
  50. icon: 'none',
  51. duration:1500
  52. })
  53. setTimeout(function(){
  54. wx.hideLoading();
  55. console.log(res);
  56. // console.log(Number(res.data.words_result[0].words));
  57. wx.navigateTo({
  58. url: '../user_detail/user_detail?item=' + encodeURIComponent(JSON.stringify(res.data.words_result)),
  59. })
  60. },1500);
  61. },
  62. })
  63. }
  64. })
  65. },
  • files 文件流上传(后端提供接口存储服务器)
    wx.uploadFile/uni.uploadFile 官网提供,formData上传其他参数
  1. uni.uploadFile({
  2. url: 'https://upload.yutunyoupu.com/UploadFiles', //仅为示例,非真实的接口地址
  3. // url:'https://jyglapi.jzxnm.com/api/common/uploads',
  4. filePath: url,
  5. name: 'files',
  6. formData: {
  7. bucket_name: 'minch',
  8. folder_name: 'goods'
  9. },
  10. success(res2) {
  11. console.log(res2);
  12. // var res = JSON.parse(res2.data);
  13. // if (res.code == 1) {
  14. // that.setData({
  15. // images: that.data.images.concat(res.data)
  16. // });
  17. // //调百度orc识别
  18. // // that.imgORC(that.data.comImg+that.data.images[0]);
  19. // } else {
  20. // uni.showToast({
  21. // title: '上传失败',
  22. // icon: 'none', //当icon:'none'时,没有图标 只有文字
  23. // image: '/images/icon/warn.png',
  24. // duration: 1000
  25. // });
  26. // }
  27. },
  28. complete() {
  29. uni.hideLoading();
  30. }
  31. })
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post