1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //1.格式化日期 start ---------------------------------------->
- //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 == 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}`;
- }
- }
- //1.格式化日期 end ---------------------------------------->
- //2.格式化标题长度 start ---------------------------------------->
- //title 标题 length 长度
- const getTitleLength = function(title:string,length:number){
- if(title.length >= length){
- return title.substring(0, length) + "...";
- }else{
- return title;
- }
- }
- //2.格式化标题长度 start ---------------------------------------->
- //3.格式化跳转路径 start ---------------------------------------->
- //3.1跳转到频道页面或者一级列表页
- const getLinkPath = (item:any) => {
- if (item.children_count == 0) {
- return `/${item.aLIas_pinyin}/list-1.html`;
- } else {
- return `/${item.aLIas_pinyin}/index.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];
- if(type == 1){
- return targetSegmentOne;
- }
- if(type == 2){
- return targetSegmentTwo;
- }
- }
- //4.获得路由路径 end ---------------------------------------->
- export { getTime,getTitleLength,getLinkPath,getLinkPathDetail,getRoutePath};
|