feat:优化 vben + antd 百度统计的实现
parent
4ccda9a5a1
commit
97d20d627b
|
@ -14,3 +14,6 @@ VITE_APP_CAPTCHA_ENABLE=false
|
||||||
|
|
||||||
# 文档地址的开关
|
# 文档地址的开关
|
||||||
VITE_APP_DOCALERT_ENABLE=true
|
VITE_APP_DOCALERT_ENABLE=true
|
||||||
|
|
||||||
|
# 百度统计
|
||||||
|
VITE_APP_BAIDU_CODE = e98f2eab6ceb8688bc6d8fc5332ff093
|
|
@ -15,13 +15,13 @@
|
||||||
<title><%= VITE_APP_TITLE %></title>
|
<title><%= VITE_APP_TITLE %></title>
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="/favicon.ico" />
|
||||||
<script>
|
<script>
|
||||||
// 生产环境下注入百度统计
|
var HM_ID = '<%= VITE_APP_BAIDU_CODE %>'
|
||||||
if (window._VBEN_ADMIN_PRO_APP_CONF_) {
|
if (HM_ID) {
|
||||||
var _hmt = _hmt || [];
|
var _hmt = _hmt || [];
|
||||||
(function () {
|
(function () {
|
||||||
var hm = document.createElement('script');
|
var hm = document.createElement('script');
|
||||||
hm.src =
|
hm.src =
|
||||||
'https://hm.baidu.com/hm.js?b38e689f40558f20a9a686d7f6f33edf';
|
'https://hm.baidu.com/hm.js?' + HM_ID;
|
||||||
var s = document.getElementsByTagName('script')[0];
|
var s = document.getElementsByTagName('script')[0];
|
||||||
s.parentNode.insertBefore(hm, s);
|
s.parentNode.insertBefore(hm, s);
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { resetStaticRoutes } from '@vben/utils';
|
import { resetStaticRoutes } from '@vben/utils';
|
||||||
|
|
||||||
import { createRouterGuard } from './guard';
|
import { createRouterGuard } from './guard';
|
||||||
|
import { setupBaiduTongJi } from './tongji';
|
||||||
import { routes } from './routes';
|
import { routes } from './routes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,5 +34,7 @@ const resetRoutes = () => resetStaticRoutes(router, routes);
|
||||||
|
|
||||||
// 创建路由守卫
|
// 创建路由守卫
|
||||||
createRouterGuard(router);
|
createRouterGuard(router);
|
||||||
|
// 设置百度统计
|
||||||
|
setupBaiduTongJi(router);
|
||||||
|
|
||||||
export { resetRoutes, router };
|
export { resetRoutes, router };
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import type { Router } from 'vue-router';
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
_hmt: any[];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const HM_ID = import.meta.env.VITE_APP_BAIDU_CODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置百度统计
|
||||||
|
* @param router
|
||||||
|
*/
|
||||||
|
function setupBaiduTongJi(router: Router) {
|
||||||
|
// 如果没有配置百度统计的 ID,则不进行设置
|
||||||
|
if (!HM_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// _hmt:用于 router push
|
||||||
|
window._hmt = window._hmt || [];
|
||||||
|
|
||||||
|
router.afterEach((to) => {
|
||||||
|
// 添加到 _hmt 中
|
||||||
|
window._hmt.push(['_trackPageview', to.fullPath]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export { setupBaiduTongJi };
|
Loading…
Reference in New Issue