//1.格式化日期
//time 日期字符串 type 从什么时候开始返回 year = 返回年月日 month = 返回月日..
//style 样式，比如 年-月-日 年.月.日
const getTime = function (time: string, type: string, style: Number) {
  const date = new Date(time);
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  //返回 年.月.日
  if (type == 'year' && style == 0) {
    return `${year}.${month}.${day}`;
  }
  //返回 年-月-日
  if (type == 'year' && style == 1) {
    return `${year}-${month}-${day}`;
  }
  //返回 年-月
  if (type == 'year' && style == 2) {
    return `${year}-${month}`;
  }
  //返回 年
  if (type == 'year' && style == 3) {
    return `${year}`;
  }
  //返回 月-日
  if (type == 'month' && style == 1) {
    return `${month}-${day}`;
  }
  //返回 月.日
  if (type == 'month' && style == 2) {
    return `${month}.${day}`;
  }
  //返回 日
  if (type == 'day' && style == 1) {
    return `${day}`;
  }
}

//2.格式化标题长度
//title 标题 length 长度
const getTitleLength = function (title: string, length: number) {
  if (title.length >= length) {
    return title.substring(0, length) + "...";
  } else {
    return title;
  }
}
//3.格式化跳转路径 start ---------------------------------------->
//3.1跳转到频道页面或者一级列表页
const getLinkPath = (item: any) => {
  if (item.is_url == 1) {
    return `${item.web_url}`;
  } else if (item.alias == "供求信息") {
    return `/gongqiuxinxi/gongyingxinxi/index.html`;
  } else if (item.children_count == 0) {
    return `/${item.aLIas_pinyin}/list-1.html`;
  } else {
    return `/${item.aLIas_pinyin}/index.html`;
  }
}
const getLinkPath1 = (item: any) => {
  return `/${item.aLIas_pinyin}/list-1.html`;
}
//3.2跳转到详情页
const getLinkPathDetail = (item: any) => {
  if (item.islink == 1) {
    return `${item.linkurl}`;
  } else {
    return `/${item.pinyin}/${item.id}.html`;
  }
}
//3.格式化跳转路径 end ---------------------------------------->


//4.获得路由路径 start ---------------------------------------->
const getRoutePath = (type: Number) => {
  const route = useRoute();
  //获得当前的完整路径
  const fullPath = route.path;
  //拆分，取出来中间这一段，然后提取数字部分
  const segments = fullPath.split('/');
  const targetSegmentOne = segments[1];
  const targetSegmentTwo = segments[2];
  const targetSegmentThree = segments[3];

  if (type == 1) {
    return targetSegmentOne;
  }
  if (type == 2) {
    return targetSegmentTwo;
  }
  if (type == 3) {
    return targetSegmentThree;
  }
}



//4.获得路由路径 end ---------------------------------------->
export { getTime, getTitleLength, getLinkPath, getLinkPath1, getLinkPathDetail, getRoutePath };


// export { getTime, getTitleLength };
