The method of WeChat applet to judge whether a file is a picture, and return different content according to different fields, and time to convert

1. Display different content according to different fields returned from the background:

formatSX(item){
    
     
    let title="";
    switch(item){
    
    
        case 1 : title ="制定和修改业主大会议事规则" ;break;
        case 2 : title ="制定和修改管理规约" ;break;
        case 3 : title ="制定物业服务内容、标准以及物业服务收费方案" ;break;
        case 4 : title ="选聘和解聘物业服务企业" ;break;
        case 5 : title ="筹集和使用专项维修资金" ;break;
        case 6 : title ="改建、重建建筑物及其附属设施" ;break;
        case 7 : title ="改变共有部分的用途" ;break;
        case 8 : title ="利用共有部分进行经营以及所得收益的分配与使用"  ;break;
        case 9 : title ="法律法规或者管理规约确定应由业主共同决定的事项"  ;break;        
    }
    return title;
  },
//判断文件是否为图片的方法
    isAssetTypeAnImage(ext) {
    
    
      return [
      'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'svg',].indexOf(ext.toLowerCase()) !== -1;
    },
    //查看附件的
    redWord(e){
    
    
      let isUrl = e.currentTarget.dataset.url //例如返回的图片路径是/common/Img?Src=4C78017251154C07AF74B6D93CD16204.jpg
      var imgArrUrl = this.data.ItemUrl.substring(0,this.data.ItemUrl.length-1) + isUrl;//imgArrUrl代表全部路径http://www.baidu.com/common/Img?Src=4C78017251154C07AF74B6D93CD16204.jpg
      console.log(isUrl)
      //获取最后一个.的位置
      var index= imgArrUrl.lastIndexOf(".");
      //获取后缀
      var ext = imgArrUrl.substr(index+1);
      if(this.isAssetTypeAnImage(ext) == true){
    
    
        wx.previewImage({
    
    
          current: imgArrUrl,  //当前图片地址
          urls: imgArrUrl.split(","), //所有要预览的图片的地址集合 数组形式
          success: function(res) {
    
    },
          fail: function(res) {
    
    },
          complete: function(res) {
    
    },
        })
      }else{
    
    
        wx.navigateTo({
    
    
          url: '/pages/test/pdfviewer/index?Url=' + escape(isUrl),
        })
      }
      
    }

3. Convert the returned time, /Date(1605542400000)/ into 2020-11-17

formatTime: date => {
    
    
    if (date == null) {
    
    
      return "";
    }
    date = date.replace('/Date(', '').replace(')/', '');
    return new Date(parseInt(date)).format("yyyy-MM-dd");
  },

Guess you like

Origin blog.csdn.net/qq_45432996/article/details/109352453