| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import http from '@src/http';
- import { uploadLogApi } from '@src/http/api';
- import sso from '@src/http/sso';
- import { VideoItem } from '@src/views/publishContent/types';
- import { RecentNotUsedType, SortTypeEnum, TagType, VideoLibraryType } from '@src/views/publishContent/weCom/components/videoSelectModal';
- import { VideoSearchPlanType } from '@src/views/publishContent/weCom/type';
- type NormalLogParams = {
- traceId: number;
- requestId: number;
- planType?: VideoSearchPlanType;
- gzhAccountId?: number;
- subChannel?: string;
- }
- type VideoListQueryLogParams = {
- category?: string;
- title?: string;
- recentNotUsed?: RecentNotUsedType;
- sortType?: SortTypeEnum;
- tags?: TagType[];
- videoLibraryType?: VideoLibraryType;
- } & NormalLogParams;
- type VideoLogParams = {
- videoId: number;
- score?: number;
- tags?: TagType[];
- title?: string;
- cover?: string;
- libraryType?: VideoLibraryType;
- playTime?: number;
- idx?: number;
- collect?: number;
- } & NormalLogParams;
- interface PublishPlanLogParams extends NormalLogParams {
- videoList: VideoItem[];
- }
- const useLogger = () => {
- const token = sso.getUserInfo()?.token;
- const channel = sso.getUserInfo()?.channel;
- const userId = sso.getUserInfo()?.id;
- const timestamp = Date.now();
- const userAgent = navigator.userAgent;
- const page = window.location.pathname;
- const uploadLog = async ({ businessType, objectType, extParams }: { businessType: string, objectType?: string, extParams?: Record<string, any> }) => {
- const log = {
- token,
- channel,
- userId,
- page,
- userAgent,
- timestamp,
- businessType,
- objectType,
- extParams,
- };
- const response = await http.post(uploadLogApi, {
- key: 'content-platform-user-behavior',
- data: log,
- });
- return response;
- }
- const uploadLogVideoListQuery = ({
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- category,
- title,
- recentNotUsed,
- sortType,
- tags,
- videoLibraryType,
- }:VideoListQueryLogParams) => {
- return uploadLog({
- businessType: 'video_list_query',
- objectType: 'video_list',
- extParams: {
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- category,
- title,
- recentNotUsed,
- sortType,
- tags,
- videoLibraryType,
- },
- });
- }
- const uploadLogVideoPlay = ({videoId, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => {
- return uploadLog({
- businessType: 'video_play',
- objectType: 'video',
- extParams: {
- videoId,
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- },
- });
- }
- const uploadLogVideoPlayEnd = ({videoId, playTime, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => {
- return uploadLog({
- businessType: 'video_play_end',
- objectType: 'video',
- extParams: {
- videoId,
- playTime,
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- },
- });
- }
- const uploadLogVideoView = ({videoId, idx, score, tags, title, cover, libraryType, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => {
- return uploadLog({
- businessType: 'video_view',
- objectType: 'video',
- extParams: {
- videoId,
- idx,
- score,
- tags,
- title,
- cover,
- libraryType,
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- },
- });
- }
- const uploadLogVideoCollect = ({videoId, traceId, requestId, collect, planType, gzhAccountId, subChannel}: VideoLogParams) => {
- return uploadLog({
- businessType: 'video_collect',
- objectType: 'video',
- extParams: {
- videoId,
- traceId,
- requestId,
- collect,
- planType,
- gzhAccountId,
- subChannel,
- },
- });
- }
- const uploadLogVideoCreatePublish = ({
- videoList,
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel
- }: PublishPlanLogParams) => {
- return uploadLog({
- businessType: 'publish_plan_create',
- objectType: 'publish_plan',
- extParams: {
- videoList,
- traceId,
- requestId,
- planType,
- gzhAccountId,
- subChannel,
- },
- });
- }
- return {
- uploadLog,
- uploadLogVideoPlay,
- uploadLogVideoView,
- uploadLogVideoPlayEnd,
- uploadLogVideoCollect,
- uploadLogVideoListQuery,
- uploadLogVideoCreatePublish,
- };
- };
- export default useLogger;
|