1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| // components/w-swiper/w-swiper.js Component({ /** * 组件的属性列表 */ properties: { images: { type: Array, value: [] } },
/** * 组件的初始数据 */ data: { //所有图片的高度 imgheights: [], //图片宽度 imgwidth: 750, //默认 current: 0 },
/** * 组件的方法列表 */ methods: { savePic(e) { const $this = this const imgUrl = e.currentTarget.dataset['url']; wx.showActionSheet({ itemList: ['保存到手机'], success(res) { console.log(res.tapIndex) if (res.tapIndex === 0) { $this.saveImage(imgUrl) } }, fail(res) { console.log(res.errMsg) } }) }, saveImage(imgUrl) { wx.showLoading({ title: '保存中...', mask: true, }); wx.downloadFile({ url: imgUrl, success: function (res) { if (res.statusCode === 200) { let img = res.tempFilePath; wx.saveImageToPhotosAlbum({ filePath: img, success(res) { wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 }); }, fail(res) { wx.showToast({ title: '保存失败', icon: 'success', duration: 2000 }); } }); } wx.hideLoading() } }); }, imageLoad: function (e) { //获取图片真实宽度 var imgwidth = e.detail.width, imgheight = e.detail.height, //宽高比 ratio = imgwidth / imgheight; console.log(imgwidth, imgheight) //计算的高度值 var viewHeight = 750 / ratio; var imgheight = viewHeight; var imgheights = this.data.imgheights; //把每一张图片的对应的高度记录到数组里 imgheights[e.target.dataset.id] = imgheight; this.setData({ imgheights: imgheights }) }, bindchange: function (e) { // console.log(e.detail.current) this.setData({ current: e.detail.current }) }, } })
|