js

// pages/downloadFile/downloadFile.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    a:'0'
  },
  onClicksource:function(e){
    console.log("复制来源信息",e.currentTarget.dataset);
    let source = e.currentTarget.dataset.source
    wx.setClipboardData({
      data: source
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that=this
    let id = options.id
    console.log(options);
    wx.request({
      url: 'https://api.uom.cn/?mod=seek&act=downloadfile',
      method:"POST",
      data:{
        id:id
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success(res){
        console.log(res);
        let fileInfo=res.data[0]
        let k = fileInfo.id+fileInfo.code
        let nowtime = Math.round(new Date() / 1000)
        let fileSize = fileInfo.fileSize/1024/1024
        let source =''
        var Y,M,D;
        var Shijianchuo=Number(fileInfo.newstime);
        Shijianchuo=Shijianchuo*1000;
        var time = new Date(Shijianchuo);
          Y = time.getFullYear() + '-';
          M = time.getMonth()+1 +"-";
          D = time.getDate();   
        console.log("时间",Y+M+D);        
        fileInfo.newstime=Y+M+D;
        if(fileInfo.laiyuan!=''){
          source = "https://mp.weixin.qq.com/s/"+fileInfo.laiyuan
        };
        fileSize = fileSize.toFixed(2)
        console.log(k);
        if( fileInfo.ewmtime == 0 || nowtime > fileInfo.ewmtime){
            wx.request({
                url: 'https://api.uom.cn/?mod=gzh&act=sendticket', 
                data: {
                  k: k,
                },
                header: {
                  'content-type': 'application/json' // 默认值
                },
                success (e) {
                  //console.log("获取ticket的返回结果",e.data)
                  fileInfo.fwhticket = e.data.ticket
                  fileInfo.ewmtime = e.data.ewmtime
                  console.log("获取ticket的返回结果",e)
                  that.setData({
                    fileInfo:fileInfo,
                  })
                }
              })
        };
        that.setData({
          fileInfo:fileInfo,
          fileSize:fileSize,
          source:source,
          a:'1'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})

wxml

<!--pages/downloadFile/downloadFile.wxml-->
<view class="box">
  <view class="title">
    文 件 名 :
    <text style="color: #2E5A81;">{{fileInfo.title}}</text>
  </view>
  <view class="fileTime">
    {{"上传时间:"+fileInfo.newstime}}
  </view>
  <view class="FileOnClicks">
    {{"点 击 量 :"+fileInfo.onclick}}
  </view>
  <view class="fileSize">
    {{"文件大小:"+fileSize+" MB"}}
  </view>
  <view class="source">
    文件来源地址<text style="color: #aaa; font-size: 25rpx;">(点击链接复制)</text><text class="source1" bindtap="onClicksource" data-source="{{source}}">{{source}}</text>
  </view>
  <view class="fileQR">
    <!-- {{fileInfo.}} -->
    <image wx:if="{{a==0}}" show-menu-by-longpress  src="/images/meteorite.gif" style="width: 70rpx;height:70rpx; border-radius: 20%;" mode='scaleToFill'></image>
    <image wx:if="{{a!=0}}" show-menu-by-longpress  src="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket={{fileInfo.fwhticket}}" style="width: 300rpx;height:300rpx;" mode='scaleToFill'></image>
  </view>
  <view class="hint">
    长按上方二维码下载文件
  </view>
  <view class="hint1">
    (有时加载较慢,请稍等)
  </view>
</view>
<view class="base">
  <image src="/images/dt.png" style="width: 100%; height: 100%;"></image>
</view>

wxss

/* pages/downloadFile/downloadFile.wxss */
.box{
  padding: 10rpx;
  height: 100%;
}
.title{
  background-color: #fff;
  padding: 25rpx 10rpx;
}
.fileTime{
  background-color: #eee;
  padding: 25rpx 10rpx;
}
.FileOnClicks{
  background-color: #fff;
  padding: 25rpx 10rpx;
}
.fileSize{
  background-color: #eee;
  padding: 25rpx 10rpx;
}
.source{
  background-color: #fff;
  padding: 25rpx 10rpx;
}
.source1{
  color: #366dbe;
  display: flex;
  flex-wrap: wrap;
  font-size: 28rpx;
}
.fileQR{
  display: flex;
  justify-content: center;
  text-align: center;
  padding: 100rpx 10rpx;
}
.hint{
  display: flex;
  justify-content: center;
  text-align: center;
  font-size: 50rpx;
  font-weight: bolder;
  color: #71a3b3;
}
.hint1{
  display: flex;
  justify-content: center;
  text-align: center;
  font-size: 30rpx;
  font-weight: bolder;
  color: #97a2a5;
}
.base{
  height: 200rpx;
  width: 100%;
  position: fixed;
  bottom: 0rpx;
  /* background-image: linear-gradient(to bottom,#eee,#2e5a81); */
}

 

原文地址:http://www.cnblogs.com/meetlilanglang/p/16838675.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性