You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

  1. // components/share/share.js
  2. //TODO: 上传到社区函数未实现,生成的图片需要从服务器端传来
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. list:[{
  14. path:"/asset/img/icon-download.png",
  15. text:"下载图片"
  16. },{
  17. path:"/asset/img/subicon-share.png",
  18. text:"分享"
  19. },{
  20. path:"/asset/img/subicon-up.png",
  21. text:"上传到社区"
  22. }],
  23. picPath: ""
  24. },
  25. /**
  26. * 组件的方法列表
  27. */
  28. methods: {
  29. onRet: function () {
  30. wx.reLaunch({
  31. url: "/Pages/travel/home/home",
  32. });
  33. },
  34. genPic:function () {
  35. var query = this.createSelectorQuery()
  36. query.select('#pic').context(function(res) {
  37. this.editorCtx = res.context,
  38. this.editorCtx.insertImage({
  39. src: picPath//后端传数据进来,保存为data中的变量picPath
  40. })
  41. })
  42. },
  43. switchFun:function(e) {
  44. console.log(e)
  45. if(e.currentTarget.id==0){
  46. this.download()
  47. }else if(e.currentTarget.id==1){
  48. this.share()
  49. }else{
  50. this.upload()
  51. }
  52. },
  53. download:function() {
  54. wx.downloadFile({
  55. url: this.data.picPath,
  56. })
  57. },
  58. share:function(){
  59. wx.showShareImageMenu({
  60. path: this.data.picPath,
  61. })
  62. },
  63. upload:function () {
  64. wx.uploadFile({
  65. filePath: this.data.picPath,
  66. name: 'name',//key值
  67. url: 'url',//服务器地址
  68. })
  69. }
  70. }
  71. })