Skip to content

Commit

Permalink
perf: adjust the logic of
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Oct 27, 2020
1 parent 259754d commit 9099187
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
- 依赖更新
- 文档更新

### ⚡ Performance Improvements

- `setTitle`逻辑调整

### ✨ Refactor

- 独立出`vite-plugin-html`,并修改相关插入 html 的逻辑

### 🐛 Bug Fixes

- 修复热更新时多次注册组件警告问题
- 修复登录后出现登录标签页

## 2.0.0-rc.5 (2020-10-26)

Expand Down
14 changes: 11 additions & 3 deletions src/router/guard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { Router } from 'vue-router';

import { Modal, notification } from 'ant-design-vue';
import { AxiosCanceler } from '/@/utils/http/axios/axiosCancel';
import { createPageTitleGuard } from './pageTitleGuard';
import { createProgressGuard } from './progressGuard';
import { createPermissionGuard } from './permissionGuard';
import { createPageLoadingGuard } from './pageLoadingGuard';
import { useSetting } from '/@/hooks/core/useSetting';
import { getIsOpenTab, setCurrentTo } from '/@/utils/helper/routeHelper';
import { setTitle } from '/@/utils/browser';

const { projectSetting } = useSetting();
const { projectSetting, globSetting } = useSetting();
export function createGuard(router: Router) {
const { openNProgress, closeMessageOnSwitch, removeAllHttpPending } = projectSetting;
let axiosCanceler: AxiosCanceler | null;
Expand All @@ -33,8 +33,16 @@ export function createGuard(router: Router) {
setCurrentTo(to);
return true;
});

router.afterEach((to) => {
// change html title

setTimeout(() => {
setTitle(to.meta.title, globSetting.title);
}, 0);
});

openNProgress && createProgressGuard(router);
createPermissionGuard(router);
createPageTitleGuard(router);
createPageLoadingGuard(router);
}
39 changes: 0 additions & 39 deletions src/router/guard/pageTitleGuard.ts

This file was deleted.

29 changes: 29 additions & 0 deletions src/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,32 @@ export function isFirefoxFn() {
export function isOperaFn() {
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);
}
}
6 changes: 5 additions & 1 deletion src/views/demo/feat/tab-params/index.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<template>
<div class="p-4"> Current Param : {{ params }} </div>
<div class="p-4">
Current Param : {{ params }}
<input />
</div>
</template>
<script lang="ts">
import { computed, defineComponent, unref } from 'vue';
import { useRouter } from 'vue-router';
export default defineComponent({
name: 'TestTab',
setup() {
const { currentRoute } = useRouter();
return {
Expand Down

0 comments on commit 9099187

Please sign in to comment.