vuefunc.js 1.24 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11

export function findCodeLabel(codes,val)
{
    if(!codes)
        return val;
    let item = codes.find(item=>item.value==val)
    if(!item)
        return val;
    return item.label
} 

fukai committed
12
export function dateFormat (date, format) {
13 14 15 16 17
    if(!date)
      return date
    if(typeof date == 'string')
      date = new Date(date)  

fukai committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    let _format = format || 'yyyy-MM-dd';
  
    const d = date;
    const o = {
      'M+' : d.getMonth() + 1, // month
      'd+' : d.getDate(), // day
      'h+' : d.getHours(), // hour
      'm+' : d.getMinutes(), // minute
      's+' : d.getSeconds(), // second
      'q+' : Math.floor((d.getMonth() + 3) / 3), // quarter
      'S' : d.getMilliseconds() // millisecond
    };
    if (/(y+)/.test(_format)) {
        _format = _format.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
    
      for (const k in o) {
        if (o.hasOwnProperty(k) && new RegExp('(' + k + ')').test(_format)) {
          _format = _format.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
        }
      }
    
      return _format;
}
fukai committed
42 43 44
export default {
    install(Vue){
        Vue.prototype.findCodeLabel = findCodeLabel
fukai committed
45
        Vue.prototype.dateFormat = dateFormat
fukai committed
46 47
    }
}