image-upload.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // components/image-upload/image-upload.js
  2. import util from '../../utils/util.js';
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. options: {
  8. addGlobalClass: true,
  9. },
  10. properties: {
  11. label: {
  12. type: String,
  13. value: '',
  14. },
  15. formid: {
  16. type: String,
  17. value: '',
  18. },
  19. forminfo: {
  20. type: Object,
  21. value: {}
  22. }
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. wx_back_image:'',
  29. inputType:'upload',
  30. input_text:'', //获取到上传成功以后的输入地址
  31. },
  32. behaviors: ['wx://component-export'],
  33. export() {
  34. return {
  35. input_text: this.data.input_text,
  36. force: this.properties.forminfo.force,
  37. role:this.properties.forminfo.role
  38. }
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. uploadImage:function(){
  45. wx.chooseImage({
  46. count: 1,
  47. sizeType: ['original','compressed'],
  48. sourceType: ['album', 'camera'],
  49. success: (res)=>{
  50. console.log(res);
  51. const { tempFilePaths} =res;
  52. console.log('wx image path::::',tempFilePaths[0]);
  53. this.setData({
  54. wx_back_image: tempFilePaths[0]
  55. });
  56. util.wx_upload_image(tempFilePaths[0]).then((resp)=>{
  57. console.log(resp);
  58. this.setData({
  59. inputType: 'uploaded',
  60. input_text: resp,
  61. });
  62. });
  63. },
  64. })
  65. },
  66. }
  67. })