接数据统计(部分)

This commit is contained in:
expdsn 2024-11-12 18:32:36 +08:00
parent d89f7f3d8c
commit 517999cc6a
7 changed files with 110 additions and 51 deletions

View File

@ -5,6 +5,7 @@ import startUseImg from '~/icons/welcome/startUse.png'
import useBackgroundStore from '../background/useBackgroundStore' import useBackgroundStore from '../background/useBackgroundStore'
import useLayoutStore from '../useLayoutStore' import useLayoutStore from '../useLayoutStore'
import request from '@/utils/request' import request from '@/utils/request'
import useStatisticStore from '@/utils/useStatisticStore'
export const DefaultPageSetting = [ export const DefaultPageSetting = [
{ {
name: '游戏', name: '游戏',
@ -44,6 +45,11 @@ export default defineComponent(() => {
if (!visited) { if (!visited) {
// 如果没有记录,说明是第一次访问 // 如果没有记录,说明是第一次访问
isFirst.value = true isFirst.value = true
useStatisticStore().send({
widget: 'WELCOME',
action: 'OPEN',
space: 'TAB',
})
} }
}) })
return () => return () =>
@ -88,10 +94,10 @@ export default defineComponent(() => {
} }
onClick={() => { onClick={() => {
selectMode.value = idx selectMode.value = idx
}} }}
style={{ style={{
transform: `translate(${idx === selectMode.value ? 80 : idx === (selectMode.value + 1) % 2 ? 219 : -52}px) scale(${ transform: `translate(${idx === selectMode.value ? 80 : idx === (selectMode.value + 1) % 2 ? 219 : -52}px) scale(${idx === selectMode.value ? 1 : 0.85
idx === selectMode.value ? 1 : 0.85
})`, })`,
backgroundImage: `url('${DivBgImg}')`, backgroundImage: `url('${DivBgImg}')`,
backgroundSize: '100% 100%', backgroundSize: '100% 100%',
@ -130,6 +136,13 @@ export default defineComponent(() => {
if (!res) return if (!res) return
layout.state.dir = res.dir layout.state.dir = res.dir
layout.state.content = res.content layout.state.content = res.content
})
layout.state.current = selectMode.value as 0 | 1 | 2
useStatisticStore().send({
widget: selectMode.value === 0 ? "WELCOME_GAME" : selectMode.value === 1 ? "WELCOME_WORK" : "WELCOME_RELAX",
action: 'CLICK',
space: 'TAB',
}) })
}} }}
style={{ style={{

View File

@ -4,6 +4,7 @@ import useSearchStore from './useSearchStore'
import { OhVueIcon, addIcons } from 'oh-vue-icons' import { OhVueIcon, addIcons } from 'oh-vue-icons'
import { FaPlus } from 'oh-vue-icons/icons' import { FaPlus } from 'oh-vue-icons/icons'
import useRouterStore from '@/useRouterStore' import useRouterStore from '@/useRouterStore'
import useStatisticStore from '@/utils/useStatisticStore'
addIcons(FaPlus) addIcons(FaPlus)
@ -34,6 +35,13 @@ export default defineComponent({
onClick={() => { onClick={() => {
searchConfig.current = { ...item } searchConfig.current = { ...item }
search.showSearchConfig = false search.showSearchConfig = false
useStatisticStore().send({
widget: 'search',
action: 'search',
key: `key=${item.name}`
})
}} }}
> >
<div <div

View File

@ -1,9 +1,10 @@
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import { OhVueIcon, addIcons } from 'oh-vue-icons' import { OhVueIcon, addIcons } from 'oh-vue-icons'
import { MdHistory, MdRemove, RiCloseCircleLine } from 'oh-vue-icons/icons' import { MdHistory, RiCloseCircleLine } from 'oh-vue-icons/icons'
import useSearchConfigStore from './useSearchConfigStore' import useSearchConfigStore from './useSearchConfigStore'
import jump from '@/utils/jump' import jump from '@/utils/jump'
import useSettingsStore from '@/settings/useSettingsStore' import useSettingsStore from '@/settings/useSettingsStore'
import useStatisticStore from '@/utils/useStatisticStore'
addIcons(MdHistory, RiCloseCircleLine) addIcons(MdHistory, RiCloseCircleLine)
export default defineComponent(() => { export default defineComponent(() => {
const searchConfig = useSearchConfigStore() const searchConfig = useSearchConfigStore()
@ -17,6 +18,12 @@ export default defineComponent(() => {
class="flex justify-between hover:pl-[20px] duration-300 items-center text-black/80 cursor-pointer hover:bg-white/40 py-1 px-2 rounded transition-all" class="flex justify-between hover:pl-[20px] duration-300 items-center text-black/80 cursor-pointer hover:bg-white/40 py-1 px-2 rounded transition-all"
onMousedown={() => { onMousedown={() => {
jump(searchConfig.current.url + item) jump(searchConfig.current.url + item)
useStatisticStore().send({
widget: 'search',
action: 'search',
key: `key=${item}&engine=${searchConfig.current.name}&type=直接搜索`
})
}} }}
> >
<div class="flex items-center w-0 flex-grow"> <div class="flex items-center w-0 flex-grow">

View File

@ -41,50 +41,7 @@ const defaultCustomSearchList: SearchInfo[] = [
] ]
// const defaultCustomSearchList: SearchInfo[] = [
// {
// name: '知乎',
// url: 'https://www.zhihu.com/search?type=content&q=',
// icon: 'searchIcons/zhihu.svg',
// show: true
// },
// {
// name: 'GitHub',
// url: 'https://github.com/search?q=',
// icon: 'searchIcons/GitHub.svg',
// show: true
// },
// {
// name: 'F搜',
// url: 'https://fsoufsou.com/search?q=',
// icon: 'searchIcons/F.svg',
// show: true
// },
// {
// name: '豆瓣',
// url: 'https://www.douban.com/search?q=',
// icon: 'searchIcons/douban.svg',
// show: true
// },
// {
// name: 'Yandex',
// url: 'https://yandex.com/search/?text=',
// icon: 'searchIcons/yandex.svg',
// show: true
// },
// {
// name: '开发者',
// url: 'https://kaifa.baidu.com/searchPage?wd=',
// icon: 'searchIcons/kaifa.svg',
// show: true
// },
// {
// name: 'B站',
// url: 'https://search.bilibili.com/all?keyword=',
// icon: 'searchIcons/bilibili.svg',
// show: true
// }
// ]
export default defineStore( export default defineStore(
'searchConfig', 'searchConfig',
() => { () => {

View File

@ -5,6 +5,7 @@ import jump from '@/utils/jump'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
import { aIUrl, translateUrl } from '@/config' import { aIUrl, translateUrl } from '@/config'
import request from '@/utils/request' import request from '@/utils/request'
import useStatisticStore from '@/utils/useStatisticStore'
export type SearchAdType = { export type SearchAdType = {
name: string name: string
icon: string icon: string
@ -81,6 +82,12 @@ export default defineStore('search', () => {
searchConfig.addHistory(str) searchConfig.addHistory(str)
searchStr.value = '' searchStr.value = ''
jump(searchConfig.current.url + str) jump(searchConfig.current.url + str)
useStatisticStore().send({
widget: 'search',
action: 'search',
key: `key=${str}&engine=${searchConfig.current.name}&type=直接搜索`
})
return return
} }
if (current.value <= 1) { if (current.value <= 1) {

View File

@ -1,3 +1,5 @@
import useLayoutStore from "@/layout/useLayoutStore";
import request from "./request";
/** /**
* *
* @param min * @param min
@ -37,3 +39,21 @@ export function formatSeconds(seconds: number): string {
// 返回格式化后的字符串,确保分钟和秒数都是两位数 // 返回格式化后的字符串,确保分钟和秒数都是两位数
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`; return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
} }
export function sendEvent(list: {
widget: string;
space?: string;
action: string;
key: string;
}[]) {
const store = useLayoutStore()
request('POST', '/api/app/statistics', {
data: list.map((item) => ({
widget: item.widget,
space: item.space || store.state.current === 0 ? 'TAB_GAME' : store.state.current === 1 ? 'TAB_WORK' : 'TAB_EAZY',
action: item.action,
key: item.key
}))
})
}

View File

@ -0,0 +1,47 @@
import { debounce } from "lodash";
import { defineStore } from "pinia"
import { ref, watch, type Ref } from "vue"
import request from "./request";
import { message } from "ant-design-vue";
import useLayoutStore from "@/layout/useLayoutStore";
export type StatisticType = {
widget: string;
space?: string;
action: string;
key?: string;
}
export default defineStore('statistic', () => {
const list = ref([] as StatisticType[])
const store = useLayoutStore()
const send = (item: StatisticType) => {
list.value.push(item)
}
const debouncedHandler = debounce((newValue: StatisticType[]) => {
console.log('数值改变并已防抖处理:', newValue)
if (newValue.length === 0) return
request("POST", `/api/app/statistics`, {
data: newValue.map((item) => ({
widget: item.widget,
space: item.space || store.state.current === 0 ? 'TAB_GAME' : store.state.current === 1 ? 'TAB_WORK' : 'TAB_EAZY',
action: item.action,
key: item.key
})),
returnType: 'text'
}).then(() => {
list.value = []
message.success('发送统计成功')
})
}, 2500) //
watch(list, (newValue) => {
console.log(list);
debouncedHandler(newValue)
}, {
deep: true
})
return {
list,
send
}
})