mirror of
https://github.com/vbenjs/vben-admin-thin-next.git
synced 2025-01-24 02:00:22 +08:00
perf: adjust the logic of
This commit is contained in:
parent
bfac425d1e
commit
b350098f44
@ -12,6 +12,10 @@
|
|||||||
- 依赖更新
|
- 依赖更新
|
||||||
- 文档更新
|
- 文档更新
|
||||||
|
|
||||||
|
### ⚡ Performance Improvements
|
||||||
|
|
||||||
|
- `setTitle`逻辑调整
|
||||||
|
|
||||||
### ✨ Refactor
|
### ✨ Refactor
|
||||||
|
|
||||||
- 独立出`vite-plugin-html`,并修改相关插入 html 的逻辑
|
- 独立出`vite-plugin-html`,并修改相关插入 html 的逻辑
|
||||||
@ -19,6 +23,7 @@
|
|||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
- 修复热更新时多次注册组件警告问题
|
- 修复热更新时多次注册组件警告问题
|
||||||
|
- 修复登录后出现登录标签页
|
||||||
|
|
||||||
## 2.0.0-rc.5 (2020-10-26)
|
## 2.0.0-rc.5 (2020-10-26)
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@ import type { Router } from 'vue-router';
|
|||||||
|
|
||||||
import { Modal, notification } from 'ant-design-vue';
|
import { Modal, notification } from 'ant-design-vue';
|
||||||
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
|
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
|
||||||
import { createPageTitleGuard } from './pageTitleGuard';
|
|
||||||
import { createProgressGuard } from './progressGuard';
|
import { createProgressGuard } from './progressGuard';
|
||||||
import { createPermissionGuard } from './permissionGuard';
|
import { createPermissionGuard } from './permissionGuard';
|
||||||
import { createPageLoadingGuard } from './pageLoadingGuard';
|
import { createPageLoadingGuard } from './pageLoadingGuard';
|
||||||
import { useSetting } from '/@/hooks/core/useSetting';
|
import { useSetting } from '/@/hooks/core/useSetting';
|
||||||
import { getIsOpenTab, setCurrentTo } from '/@/utils/helper/routeHelper';
|
import { getIsOpenTab, setCurrentTo } from '/@/utils/helper/routeHelper';
|
||||||
|
import { setTitle } from '/@/utils/browser';
|
||||||
|
|
||||||
const { projectSetting } = useSetting();
|
const { projectSetting, globSetting } = useSetting();
|
||||||
export function createGuard(router: Router) {
|
export function createGuard(router: Router) {
|
||||||
const { openNProgress, closeMessageOnSwitch, removeAllHttpPending } = projectSetting;
|
const { openNProgress, closeMessageOnSwitch, removeAllHttpPending } = projectSetting;
|
||||||
let axiosCanceler: AxiosCanceler | null;
|
let axiosCanceler: AxiosCanceler | null;
|
||||||
@ -33,8 +33,16 @@ export function createGuard(router: Router) {
|
|||||||
setCurrentTo(to);
|
setCurrentTo(to);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.afterEach((to) => {
|
||||||
|
// change html title
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
setTitle(to.meta.title, globSetting.title);
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
openNProgress && createProgressGuard(router);
|
openNProgress && createProgressGuard(router);
|
||||||
createPermissionGuard(router);
|
createPermissionGuard(router);
|
||||||
createPageTitleGuard(router);
|
|
||||||
createPageLoadingGuard(router);
|
createPageLoadingGuard(router);
|
||||||
}
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import type { Router } from 'vue-router';
|
|
||||||
|
|
||||||
import { useSetting } from '/@/hooks/core/useSetting';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置页面标题
|
|
||||||
* @param {*} title :页面标题
|
|
||||||
*/
|
|
||||||
const setDocumentTitle = (title: string) => {
|
|
||||||
document.title = title;
|
|
||||||
const ua = navigator.userAgent;
|
|
||||||
const regex = /\bMicroMessenger\/([\d.]+)/;
|
|
||||||
// 兼容
|
|
||||||
if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
|
|
||||||
const i = document.createElement('iframe');
|
|
||||||
i.src = '/favicon.ico';
|
|
||||||
i.style.display = 'none';
|
|
||||||
i.onload = function () {
|
|
||||||
setTimeout(function () {
|
|
||||||
i.remove();
|
|
||||||
}, 9);
|
|
||||||
};
|
|
||||||
document.body.appendChild(i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
export const createPageTitleGuard = (router: Router) => {
|
|
||||||
router.beforeEach(async (to) => {
|
|
||||||
// This operation does not require synchronization
|
|
||||||
setTimeout(() => {
|
|
||||||
const { globSetting } = useSetting();
|
|
||||||
if (to.meta.title) {
|
|
||||||
const { title } = globSetting;
|
|
||||||
const _title = to.meta.title ? ` ${to.meta.title}-${title} ` : `${title}`;
|
|
||||||
setDocumentTitle(_title);
|
|
||||||
}
|
|
||||||
}, 30);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
};
|
|
@ -70,3 +70,32 @@ export function isFirefoxFn() {
|
|||||||
export function isOperaFn() {
|
export function isOperaFn() {
|
||||||
return type === 'Opera';
|
return type === 'Opera';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set page Title
|
||||||
|
* @param {*} title :page Title
|
||||||
|
*/
|
||||||
|
const setDocumentTitle = (title: string) => {
|
||||||
|
document.title = title;
|
||||||
|
const ua = navigator.userAgent;
|
||||||
|
const regex = /\bMicroMessenger\/([\d.]+)/;
|
||||||
|
// 兼容
|
||||||
|
if (regex.test(ua) && /ip(hone|od|ad)/i.test(ua)) {
|
||||||
|
const i = document.createElement('iframe');
|
||||||
|
i.src = '/favicon.ico';
|
||||||
|
i.style.display = 'none';
|
||||||
|
i.onload = function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
i.remove();
|
||||||
|
}, 9);
|
||||||
|
};
|
||||||
|
document.body.appendChild(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export function setTitle(title: string, appTitle?: string) {
|
||||||
|
if (title) {
|
||||||
|
const _title = title ? ` ${title}-${appTitle} ` : `${appTitle}`;
|
||||||
|
setDocumentTitle(_title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="p-4"> Current Param : {{ params }} </div>
|
<div class="p-4">
|
||||||
|
Current Param : {{ params }}
|
||||||
|
<input />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, unref } from 'vue';
|
import { computed, defineComponent, unref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
|
name: 'TestTab',
|
||||||
setup() {
|
setup() {
|
||||||
const { currentRoute } = useRouter();
|
const { currentRoute } = useRouter();
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user