// pages/checkImg/checkImg.ts Page({ /** * 页面的初始数据 */ data: { currentIndex: 0, swiperList: [ { id: "1", src: "https://suimang.oss-accelerate.aliyuncs.com/capi/2023-09-21/4f3cf1dea65142a2945d5412bee85ca2.jpg?x-oss-process=image/resize,w_10000/quality,q_60" }, { id: "2", src: "https://suimang.oss-accelerate.aliyuncs.com/capi/2023-09-21/4f3cf1dea65142a2945d5412bee85ca2.jpg?x-oss-process=image/resize,w_10000/quality,q_60" }, { id: "3", src: "https://suimang.oss-accelerate.aliyuncs.com/capi/2023-09-21/4f3cf1dea65142a2945d5412bee85ca2.jpg?x-oss-process=image/resize,w_10000/quality,q_60" }, { id: "4", src: "https://suimang.oss-accelerate.aliyuncs.com/capi/2023-09-21/4f3cf1dea65142a2945d5412bee85ca2.jpg?x-oss-process=image/resize,w_10000/quality,q_60" } ] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(options); }, /** * 生命周期函数--监听页面显示 */ onShow() { }, switchImg(e) { const currentIndex = e.currentTarget.dataset.index this.setData({ currentIndex }) }, previewImage() { const array = [] this.data.swiperList.forEach(item => { array.push(item.src) }) wx.previewImage({ urls: array, showmenu: true, }) }, swiperChanged(e) { const currentIndex = e.detail.current this.setData({ currentIndex }) }, downloadImage() { const index = this.data.currentIndex const list = this.data.swiperList const filePath = "zhixiangImg.png" const url = list[index].src wx.downloadFile({ url, success: res => { console.log(res, 'res'); if (res.statusCode === 200) { wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: () => { wx.showToast({ title: '保存成功!', icon: "success" }) } }) } } }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })