All files tool.js

48.15% Statements 13/27
33.33% Branches 6/18
100% Functions 0/0
48.15% Lines 13/27
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211                                                                                                                                                                                                                                                                                                    40x 40x   40x 40x       40x             40x   40x 40x                                                                     40x 40x   40x 40x           400x  
export function gmCount(currentPage=1, totalPage=1, howMuchPageButtons, baseOnCurrentPageButtonOffset) {
  let startPage, endPage, result = [];
  if (currentPage > baseOnCurrentPageButtonOffset) {
    startPage = currentPage - baseOnCurrentPageButtonOffset;
    endPage = ( totalPage > (currentPage + baseOnCurrentPageButtonOffset) )
              ? (currentPage + baseOnCurrentPageButtonOffset)
              : totalPage;
  }
  else {
    startPage = 1;
    endPage = (totalPage > howMuchPageButtons)
              ? howMuchPageButtons
              : totalPage;
  }
  if ( (currentPage + baseOnCurrentPageButtonOffset) > totalPage ) {
    startPage = startPage - (currentPage + baseOnCurrentPageButtonOffset - endPage);
  }
 
  if (startPage <= 0) startPage = 1
  for (let i = startPage; i <= endPage; i++) {
    result.push(i);
  }
  return result; 
}
 
export function show_msg(msg, timeOut) {
    var timer = null;
    var timeOut = timeOut || 1000;
    var index = 0;
    index++;
    if (index > 1) {
        return
    }
    clearTimeout(timer);
    var msg_dis_container = document.createElement("div");
    var msg_dis_content = document.createElement("div");
 
    msg_dis_container.id = "msg_dis_container"
    msg_dis_container.style.block = "none";
    msg_dis_container.className = "motify";
    msg_dis_content.id = "msg_dis_content"
    msg_dis_content.className = "motify-inner";
 
    msg_dis_container.appendChild(msg_dis_content)
    document.body.appendChild(msg_dis_container);
    msg_dis_content.innerHTML = msg;
    msg_dis_container.style.display = "block";
    timer = setTimeout(function() {
        msg_dis_container.style.display = "none";
        document.body.removeChild(msg_dis_container);
        index = 0
    }, timeOut);
}
 
//映射表
//edit == 编辑
//add == 添加
//delete == 删除
//menu == 进入某菜单详情
//push == 推送事件按钮
//view == 查看/详情
//export == 导出
//verify == 审核
 
 
//时间转换 公用
//扩展时分秒
// 时间属性
// | 61| 年月日
// | 62| 年月日 时分
// | 63| 年月日时分秒
// | 64| 时分
// | 65| 时分秒
 
// 秒为单位
function getDateSplit(timstamp,timeType) {
     if(!timeType) timeType = 61
    let date = new Date(Number(timstamp.value) *1000 ) ? new Date(Number(timstamp.value) * 1000) :"";
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let today = date.getDate();
    let hour = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    if (typeof timstamp=="string") { return timstamp; }
    if (month < 10) {month = "0" + month;}
    if (today < 10) { today = "0" + today;}
    if(hour<10){ hour="0"+hour;}
    if(minute<10){minute="0"+minute;}
    if(second<10){second="0"+second;}
 
    if(timstamp.value == ''){
      return {
        value:""
      }
      return;
    }
 
    if(timeType == 61 && date){
       return {
        value: date.getFullYear() + "/" + month + "/" + today
      }
    }
 
    if(timeType == 62 && date){
       return {
        value: date.getFullYear() + "/" + month + "/" + today + " " + hour + ":" + minute
      }
    }
   
    if(timeType == 63 && date){
       return {
        value: date.getFullYear() + "/" + month + "/" + today + " " + hour + ":" + minute  + ":" + second
      }
    }
 
    if(timeType == 64 && date){
       return {
        value:  hour + ":" + minute
      }
    }
 
    if(timeType == 65 && date){
       return {
        value: hour + ":" + minute  + ":" + second
      }
    }
}
 
//文本截断
function getContentOverflow(text,length){
if(!length) length =10
 return{
   value: text.value.substring(0,length)+"..."
 }
}
 
//邮件奖励
function getEmailAttachment(attachment){
 let len = attachment.value.length
 return {
  value: len ?  "是" : "否"
 }
 
 // let str = ''
 // for(let i=0;i<len;i++){
 //  str += Object.values(attachment.value[i]).join(":") + ','
 // }
 // return {
 //  value:str.substring(0,str.length-1)
 // }
}
 
//收件人数
function getReceiver(users){
  return{
   value: users.value.length ?  users.value.length : 0
 }
}
 
// ["1","2","3"].join() "1,2,3"
//tabel 字段格式
//例如时间,价格,状态等等
//模拟了vue filter效果
//修改为obj--value
 export  function formatTdFilters(keys,value,gmTimeStamp) {
    switch (keys){
          case "price":
          value = value.toFixed(2) +"元";
          break;
          case "limitId":
          if(value == 1){
             value = '同步添加'
          }
          if(value == 2){
             value = '运营添加'
          }
           break;
          case "originId":
          if(value == 1){
             value = '盈利'
          }
          if(value == 2){
             value = '亏损'
          }
          break;
          case "sendtime":
          value = getDateSplit(value,gmTimeStamp);
          break;
          case "create_time":
          value = getDateSplit(value,gmTimeStamp);
          break;
          case "update_time":
          value = getDateSplit(value,gmTimeStamp);
          break;
          case "content":
          value = getContentOverflow(value);
          break;
          case "receiver":
          value = getReceiver(value);
          break;
          case "attachment":
          value = getEmailAttachment(value);
          break;
          case "attr":
          value = Object.values(value).join()
          break;
      }
 
    return value
}