/**
* @description 根据时间戳获取时间
* @param {*} timestamp 必传，number类型，时间戳数据（10位及以下，10位至13位）;若不传，则返回：“无时间戳”
* @param {*} format  选传，string类型，提供以下时间格式：YYYY-MM-DD hh:mm:ss、YYYY/MM/DD hh:mm:ss、YYYY.MM.DD hh:mm:ss、YYYY MM DD hh:mm:ss、YYYY年MM月DD日 hh:mm:ss、YYYY-MM-DD、YYYY/MM/DD、YYYY.MM.DD、YYYY MM DD、YYYY年MM月DD日；若不传，则默认为：YYYY-MM-DD
* @returns 根据要求的时间格式
* @version V 1.0, Created by YWQ, 2022.10.20
*/
export const timestampToTime = (timestamp, format) => {
  //时间戳为10位需*1000，时间戳为13位不需乘1000
  const length = timestamp.length
  if (length <= 10) {
    var date = new Date(timestamp * 1000)
  } else {
    var date = new Date(timestamp)
  }
  let Y = String(date.getFullYear())
  let M = String(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
  let D = String(date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate())
  let h = String(date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours())
  let m = String(date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
  let s = String(date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds())
  // return Y + M + D + h + m + s
  if (format == "YYYY-MM-DD hh:mm:ss") {
    return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s
  } else if (format == "YYYY/MM/DD hh:mm:ss") {
    return Y + "/" + M + "/" + D + " " + h + ":" + m + ":" + s
  } else if (format == "YYYY.MM.DD hh:mm:ss") {
    return Y + "." + M + "." + D + " " + h + ":" + m + ":" + s
  } else if (format == "YYYY MM DD hh:mm:ss") {
    return Y + " " + M + " " + D + " " + h + ":" + m + ":" + s
  } else if (format == "YYYY年MM月DD日 hh:mm:ss") {
    return Y + "年" + M + "月" + D + "日" + " " + h + ":" + m + ":" + s
  } else if (format == "YYYY-MM-DD") {
    return Y + "-" + M + "-" + D
  } else if (format == "YYYY/MM/DD") {
    return Y + "/" + M + "/" + D
  } else if (format == "YYYY.MM.DD") {
    return Y + "." + M + "." + D
  } else if (format == "YYYY MM DD") {
    return Y + " " + M + " " + D
  } else if (format == "YYYY年MM月DD日") {
    return Y + "年" + M + "月" + D + "日"
  } else {
    return Y + "-" + M + "-" + D
  }
}

/**
* @description:滚动到对应id的位置
* @param {type} id
*/
export const scrollToID = id => {
  wx.createSelectorQuery().select("#" + id).scrollIntoView({
    behavior: "smooth",
    block: "start",
    inline: "nearest",
  });
}
/**
* @description:命中标签枚举值
* @return {string} 100 正常；10001 广告；20001 时政；20002 色情；20003 辱骂；20006 违法犯罪；20008 欺诈；20012 低俗；20013 版权；21000 其他
*/
export const keyWordsEnum = [
  // {
  //   msg: '正常',
  //   label: 100
  // },
  {
    msg: '广告',
    label: 10001
  },
  {
    msg: '时政',
    label: 20001
  },
  {
    msg: '色情',
    label: 20002
  },
  {
    msg: '辱骂',
    label: 20003
  },
  {
    msg: '违法犯罪',
    label: 20006
  },
  {
    msg: '欺诈',
    label: 20008
  },
  {
    msg: '低俗',
    label: 20012
  },
  {
    msg: '版权',
    label: 20013
  },
  // {
  //   msg: '其他',
  //   label: 21000
  // },
]
