mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-06-11 12:49:30 +08:00
feat: 添加文章访问统计功能
1. 新增getDomainOnly工具函数用于提取URL域名 2. 新增postTrackersCounter接口调用方法 3. 在文章详情页添加访问数据上报 #31 #41
This commit is contained in:
+5
-1
@@ -177,5 +177,9 @@ export default {
|
|||||||
|
|
||||||
getDoubanDetail: (url) => {
|
getDoubanDetail: (url) => {
|
||||||
return HttpHandler.Get(`/apis/api.douban.moony.la/v1alpha1/doubanmovies/-/getDoubanDetail`, { url })
|
return HttpHandler.Get(`/apis/api.douban.moony.la/v1alpha1/doubanmovies/-/getDoubanDetail`, { url })
|
||||||
}
|
},
|
||||||
|
|
||||||
|
postTrackersCounter: (data) => {
|
||||||
|
return HttpHandler.Post(`/apis/api.halo.run/v1alpha1/trackers/counter`, data)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -401,6 +401,7 @@ import ArticleDouban from '@/components/article-douban/article-douban.vue';
|
|||||||
import barrage from '@/components/barrage/barrage.vue';
|
import barrage from '@/components/barrage/barrage.vue';
|
||||||
import { getAppConfigs } from '@/config/index.js';
|
import { getAppConfigs } from '@/config/index.js';
|
||||||
import { upvote } from '@/utils/upvote.js';
|
import { upvote } from '@/utils/upvote.js';
|
||||||
|
import { getDomainOnly } from '@/utils/url.params.js'
|
||||||
import { checkPostRestrictRead, copyToClipboard, getRestrictReadTypeName, getShowableContent } from '@/utils/restrictRead';
|
import { checkPostRestrictRead, copyToClipboard, getRestrictReadTypeName, getShowableContent } from '@/utils/restrictRead';
|
||||||
import HaloTokenConfig from '@/config/uhalo.config';
|
import HaloTokenConfig from '@/config/uhalo.config';
|
||||||
import RestrictReadSkeleton from '@/components/restrict-read-skeleton/restrict-read-skeleton.vue';
|
import RestrictReadSkeleton from '@/components/restrict-read-skeleton/restrict-read-skeleton.vue';
|
||||||
@@ -636,6 +637,7 @@ export default {
|
|||||||
this.reloadVote = true;
|
this.reloadVote = true;
|
||||||
this.fnHandleSetFlotButtonItems(this.haloConfigs);
|
this.fnHandleSetFlotButtonItems(this.haloConfigs);
|
||||||
this.handleQueryCommentListScrollTop();
|
this.handleQueryCommentListScrollTop();
|
||||||
|
this.fnTrackersCounter();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('错误', err);
|
console.log('错误', err);
|
||||||
@@ -740,6 +742,20 @@ export default {
|
|||||||
uni.$tm.toast('点赞失败');
|
uni.$tm.toast('点赞失败');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
fnTrackersCounter(){
|
||||||
|
const winInfo = uni.getWindowInfo()
|
||||||
|
const appBaseInfo = uni.getAppBaseInfo()
|
||||||
|
this.$httpApi.v2.postTrackersCounter({
|
||||||
|
group: 'content.halo.run',
|
||||||
|
plural: 'posts',
|
||||||
|
name: this.result?.metadata?.name,
|
||||||
|
hostname: getDomainOnly(HaloTokenConfig.BASE_API),
|
||||||
|
screen: `${winInfo.screenWidth}x${winInfo.screenHeight}`,
|
||||||
|
language: appBaseInfo.language,
|
||||||
|
url: `/archives/${HaloTokenConfig.BASE_API}`,
|
||||||
|
referrer: `${HaloTokenConfig.BASE_API}/`
|
||||||
|
})
|
||||||
|
},
|
||||||
async fnShowShare() {
|
async fnShowShare() {
|
||||||
this.poster.show = true;
|
this.poster.show = true;
|
||||||
await this.handleCreatePoster();
|
await this.handleCreatePoster();
|
||||||
|
|||||||
@@ -50,3 +50,12 @@ export function jsonToUrlParams2(json) {
|
|||||||
})
|
})
|
||||||
).join('&')
|
).join('&')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅获取域名
|
||||||
|
* @param {String} url
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
export function getDomainOnly(url){
|
||||||
|
return url.replace(/^(https?:\/\/)/, '').split('/')[0]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user