From 517999cc6a1514614706624c4fbaf49cb579d4a7 Mon Sep 17 00:00:00 2001 From: expdsn <18111002318@163.com> Date: Tue, 12 Nov 2024 18:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=EF=BC=88=E9=83=A8=E5=88=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/grid/WelcomePage.tsx | 23 +++++++-- src/layout/header/search/SearchConfig.tsx | 8 ++++ src/layout/header/search/SearchHistory.tsx | 9 +++- .../header/search/useSearchConfigStore.ts | 45 +----------------- src/layout/header/search/useSearchStore.ts | 7 +++ src/utils/tool.ts | 22 ++++++++- src/utils/useStatisticStore.ts | 47 +++++++++++++++++++ 7 files changed, 110 insertions(+), 51 deletions(-) create mode 100644 src/utils/useStatisticStore.ts diff --git a/src/layout/grid/WelcomePage.tsx b/src/layout/grid/WelcomePage.tsx index d9c70cf..ceac05f 100644 --- a/src/layout/grid/WelcomePage.tsx +++ b/src/layout/grid/WelcomePage.tsx @@ -5,6 +5,7 @@ import startUseImg from '~/icons/welcome/startUse.png' import useBackgroundStore from '../background/useBackgroundStore' import useLayoutStore from '../useLayoutStore' import request from '@/utils/request' +import useStatisticStore from '@/utils/useStatisticStore' export const DefaultPageSetting = [ { name: '游戏', @@ -44,6 +45,11 @@ export default defineComponent(() => { if (!visited) { // 如果没有记录,说明是第一次访问 isFirst.value = true + useStatisticStore().send({ + widget: 'WELCOME', + action: 'OPEN', + space: 'TAB', + }) } }) return () => @@ -53,7 +59,7 @@ export default defineComponent(() => { {show.value && (
{}} + onClick={() => { }} style={{ backgroundImage: `url('${DefaultPageSetting[selectMode.value].backgroundUrl}')`, backgroundSize: '100% 100%', @@ -61,7 +67,7 @@ export default defineComponent(() => { backgroundRepeat: 'no-repeat' }} > -
{}}>
+
{ }}>
)} @@ -88,11 +94,11 @@ export default defineComponent(() => { } onClick={() => { selectMode.value = idx + }} style={{ - transform: `translate(${idx === selectMode.value ? 80 : idx === (selectMode.value + 1) % 2 ? 219 : -52}px) scale(${ - idx === selectMode.value ? 1 : 0.85 - })`, + transform: `translate(${idx === selectMode.value ? 80 : idx === (selectMode.value + 1) % 2 ? 219 : -52}px) scale(${idx === selectMode.value ? 1 : 0.85 + })`, backgroundImage: `url('${DivBgImg}')`, backgroundSize: '100% 100%', zIndex: selectMode.value === idx ? 10 : 0 @@ -130,6 +136,13 @@ export default defineComponent(() => { if (!res) return layout.state.dir = res.dir 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={{ diff --git a/src/layout/header/search/SearchConfig.tsx b/src/layout/header/search/SearchConfig.tsx index 9577b14..099e46a 100644 --- a/src/layout/header/search/SearchConfig.tsx +++ b/src/layout/header/search/SearchConfig.tsx @@ -4,6 +4,7 @@ import useSearchStore from './useSearchStore' import { OhVueIcon, addIcons } from 'oh-vue-icons' import { FaPlus } from 'oh-vue-icons/icons' import useRouterStore from '@/useRouterStore' +import useStatisticStore from '@/utils/useStatisticStore' addIcons(FaPlus) @@ -34,6 +35,13 @@ export default defineComponent({ onClick={() => { searchConfig.current = { ...item } search.showSearchConfig = false + + useStatisticStore().send({ + widget: 'search', + action: 'search', + key: `key=${item.name}` + }) + }} >
{ 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" onMousedown={() => { jump(searchConfig.current.url + item) + + useStatisticStore().send({ + widget: 'search', + action: 'search', + key: `key=${item}&engine=${searchConfig.current.name}&type=直接搜索` + }) }} >
diff --git a/src/layout/header/search/useSearchConfigStore.ts b/src/layout/header/search/useSearchConfigStore.ts index 25e7b60..208479e 100644 --- a/src/layout/header/search/useSearchConfigStore.ts +++ b/src/layout/header/search/useSearchConfigStore.ts @@ -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( 'searchConfig', () => { diff --git a/src/layout/header/search/useSearchStore.ts b/src/layout/header/search/useSearchStore.ts index 34c0f39..538cfec 100644 --- a/src/layout/header/search/useSearchStore.ts +++ b/src/layout/header/search/useSearchStore.ts @@ -5,6 +5,7 @@ import jump from '@/utils/jump' import debounce from 'lodash/debounce' import { aIUrl, translateUrl } from '@/config' import request from '@/utils/request' +import useStatisticStore from '@/utils/useStatisticStore' export type SearchAdType = { name: string icon: string @@ -81,6 +82,12 @@ export default defineStore('search', () => { searchConfig.addHistory(str) searchStr.value = '' jump(searchConfig.current.url + str) + + useStatisticStore().send({ + widget: 'search', + action: 'search', + key: `key=${str}&engine=${searchConfig.current.name}&type=直接搜索` + }) return } if (current.value <= 1) { diff --git a/src/utils/tool.ts b/src/utils/tool.ts index 58c4abd..d9536d6 100644 --- a/src/utils/tool.ts +++ b/src/utils/tool.ts @@ -1,3 +1,5 @@ +import useLayoutStore from "@/layout/useLayoutStore"; +import request from "./request"; /** * 生成随机数 * @param min 最小值 @@ -33,7 +35,25 @@ export function formatSeconds(seconds: number): string { const minutes = Math.floor(seconds / 60); // 计算剩余的秒数 const remainingSeconds = seconds % 60; - + // 返回格式化后的字符串,确保分钟和秒数都是两位数 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 + })) + + }) + +} \ No newline at end of file diff --git a/src/utils/useStatisticStore.ts b/src/utils/useStatisticStore.ts new file mode 100644 index 0000000..ed68931 --- /dev/null +++ b/src/utils/useStatisticStore.ts @@ -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 + } +}) \ No newline at end of file