/*
 * @Author: 倚楼听风雨 18408246387@163.com
 * @Date: 2023-01-09 14:37:34
 * @LastEditors: 倚楼听风雨 18408246387@163.com
 * @LastEditTime: 2023-01-16 19:45:18
 * @FilePath: \log-server-web\src\utils\format.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { formatTimeToStr } from "@/utils/date";
import { getDict } from "@/utils/dictionary";

export const formatBoolean = (bool) => {
  if (bool !== null) {
    return bool ? "是" : "否";
  } else {
    return "";
  }
};
export const formatDate = (time) => {
  if (time !== null && time !== "") {
    var date = new Date(time);
    return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  } else {
    return "";
  }
};

export const filterDict = (value, options) => {
  const rowLabel = options && options.filter((item) => item.value === value);
  return rowLabel && rowLabel[0] && rowLabel[0].label;
};

export const getDictFunc = async (type) => {
  const dicts = await getDict(type);
  return dicts;
};
