import dayjs from "dayjs";
// https://dayjs.fenxianglu.cn/category/display.html#%E6%A0%BC%E5%BC%8F%E5%8C%96

const dateFilter = (val, format = "YYYY-MM-DD HH:mm:ss") => {
  if (val) {
    if (!isNaN(val)) {
      val = parseInt(val);
    }
    return dayjs(val).format(format);
  } else {
    return '--'
  }
};

const isAvailable = (val) => {
  if (val === 0) return true;
  if (val == null || val == undefined || val == '' || val == 'undefined' || val == 'null') {
    return false
  } else {
    return true
  }
}

export default (app) => {
  app.config.globalProperties.$filters = {
    dateFilter,
    isAvailable
  };
};
