From 1f8fd9a137d963e012ca5c78c9ae77b83b8ac153 Mon Sep 17 00:00:00 2001 From: zjwmiao <1723168479@qq.com> Date: Thu, 27 Mar 2025 15:47:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8B=92=E7=BB=9Dcookie=E5=90=8E?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=99=BE=E5=BA=A6=E7=BB=9F=E8=AE=A1=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CookieNotice.vue | 16 +++++----------- src/shared/analytics/index.ts | 34 +++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/components/CookieNotice.vue b/src/components/CookieNotice.vue index 9dbac52..8e54a81 100644 --- a/src/components/CookieNotice.vue +++ b/src/components/CookieNotice.vue @@ -5,7 +5,7 @@ import { type DialogActionT, OButton, ODialog, OIcon, OSwitch, isBoolean } from import ContentWrapper from '@/components/ContentWrapper.vue'; -import { enableOA, disableOA } from '@/shared/analytics'; +import { enableOA, disableOA, removeHM } from '@/shared/analytics'; import { setCustomCookie, removeCustomCookie } from '@/utils/cookie'; import { useCookieStore, COOKIE_AGREED_STATUS, COOKIE_KEY } from '@/stores/common'; import { useLoginStore } from '@/stores/user'; @@ -64,14 +64,6 @@ const initSensor = () => { ); }; -const removeSensor = () => { - disableOA(); - const scripts = document.querySelectorAll('script.analytics-script'); - scripts.forEach((script) => { - script.remove(); - }); -}; - // -------------------- 展示底部提示 -------------------- const isNoticeVisible = ref(false); @@ -100,7 +92,8 @@ const rejectAll = () => { removeCustomCookie(COOKIE_KEY); setCustomCookie(COOKIE_KEY, `${COOKIE_AGREED_STATUS.NECCESSARY_AGREED}`, 180, COOKIE_DOMAIN); toggleNoticeVisible(false); - removeSensor(); + disableOA(); + removeHM(); }; // -------------------- 展示弹出框 -------------------- @@ -170,7 +163,8 @@ onMounted(() => { analysisAllowed.value = true; initSensor(); } else { - removeSensor(); + disableOA(); + removeHM(); } }); diff --git a/src/shared/analytics/index.ts b/src/shared/analytics/index.ts index 129e5e4..2019104 100644 --- a/src/shared/analytics/index.ts +++ b/src/shared/analytics/index.ts @@ -4,12 +4,15 @@ import type { Awaitable } from '@vueuse/core'; import { COOKIE_AGREED_STATUS, useCookieStore } from '@/stores/common'; import router from '@/router'; import { useLoginStore } from '@/stores/user'; +import { removeCustomCookie } from '@/utils/cookie'; export const oa = new OpenAnalytics({ appKey: 'openEuler', request: (data) => { if (useCookieStore().getUserCookieStatus() !== COOKIE_AGREED_STATUS.ALL_AGREED) { - return disableOA(); + disableOA(); + removeHM(); + return; } reportAnalytics(data); }, @@ -60,7 +63,34 @@ export const disableOA = () => { }); }; -type Service = 'software' | 'search_software' +export const removeHM = () => { + const scripts = document.querySelectorAll('script.analytics-script'); + scripts.forEach((script) => { + script.remove(); + }); + const hm = /^hm/i; + document.cookie + .split(';') + .map((c) => c.trim()) + .forEach((c) => { + const key = decodeURIComponent(c.split('=')[0]); + if (hm.test(key)) { + removeCustomCookie(key); + } + }); + [sessionStorage, localStorage].forEach((storage) => { + const keys = []; + for (let i = 0; i < storage.length; i++) { + const key = storage.key(i)!; + if (hm.test(key)) { + keys.push(key); + } + } + keys.forEach((key) => storage.removeItem(key)); + }); +}; + +type Service = 'software' | 'search_software'; export const getReportFn = ($service: Service = 'software') => { return ( -- Gitee