perf: tags

This commit is contained in:
xiaoxian521 2021-12-01 17:20:25 +08:00
parent cec5af55d9
commit a8a3e5b303
11 changed files with 62 additions and 55 deletions

View File

@ -11,7 +11,7 @@ import { unref, watch, getCurrentInstance } from "vue";
import { deviceDetection } from "/@/utils/deviceDetection";
import screenfull from "../components/screenfull/index.vue";
import globalization from "/@/assets/svg/globalization.svg";
import { transformI18n } from "/@/utils/i18n";
import { transformI18n } from "/@/plugins/i18n";
const instance =
getCurrentInstance().appContext.config.globalProperties.$storage;

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { useRoute, useRouter, RouteLocationMatched } from "vue-router";
import { transformI18n } from "/@/utils/i18n";
import { transformI18n } from "/@/plugins/i18n";
const levelList = ref([]);
const route = useRoute();

View File

@ -4,7 +4,7 @@ import { PropType, ref, nextTick, getCurrentInstance } from "vue";
import { childrenType } from "../../types";
import { useAppStoreHook } from "/@/store/modules/app";
import Icon from "/@/components/ReIcon/src/Icon.vue";
import { transformI18n } from "/@/utils/i18n";
import { transformI18n } from "/@/plugins/i18n";
import { findIconReg } from "/@/components/ReIcon";
const instance = getCurrentInstance().appContext.app.config.globalProperties;
const menuMode = instance.$storage.layout?.layout === "vertical";

View File

@ -18,7 +18,7 @@ import closeOther from "/@/assets/svg/close_other.svg";
import closeRight from "/@/assets/svg/close_right.svg";
import { emitter } from "/@/utils/mitt";
import { transformI18n } from "/@/utils/i18n";
import { transformI18n } from "/@/plugins/i18n";
import { storageLocal } from "/@/utils/storage";
import { useRoute, useRouter } from "vue-router";
import { RouteConfigs, tagsViewsType } from "../../types";

View File

@ -13,3 +13,27 @@ export const i18n = createI18n({
export function usI18n(app: App) {
app.use(i18n);
}
/**
*
* @param message message
* @param isI18n true,,
* @returns message
*/
export function transformI18n(message: string | object = "", isI18n = false) {
if (!message) {
return "";
}
// 处理存储动态路由的title,格式 {zh:"",en:""}
if (typeof message === "object") {
return message[i18n.global?.locale];
}
if (isI18n) {
//@ts-ignore
return i18n.global.tc.call(i18n.global, message);
} else {
return message;
}
}

View File

@ -27,7 +27,7 @@ import flowChartRouter from "./modules/flowchart";
import componentsRouter from "./modules/components";
// 动态路由
import { getAsyncRoutes } from "/@/api/routes";
import { transformI18n } from "../utils/i18n";
import { transformI18n } from "/@/plugins/i18n";
// https://cn.vitejs.dev/guide/features.html#glob-import
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");

View File

@ -1,23 +1,13 @@
import { storageLocal } from "/@/utils/storage";
import { deviceDetection } from "/@/utils/deviceDetection";
import { defineStore } from "pinia";
import { store } from "/@/store";
import { appType } from "./types";
import { defineStore } from "pinia";
import { getConfig } from "/@/config";
interface AppState {
sidebar: {
opened: boolean;
withoutAnimation: boolean;
// 判断是否手动点击Hamburger
isClickHamburger: boolean;
};
layout: string;
device: string;
}
export const useAppStore = defineStore({
id: "pure-app",
state: (): AppState => ({
state: (): appType => ({
sidebar: {
opened: storageLocal.getItem("sidebarStatus")
? !!+storageLocal.getItem("sidebarStatus")

View File

@ -1,15 +1,8 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { getConfig } from "/@/config";
import { positionType } from "./types";
import { storageLocal } from "/@/utils/storage";
interface Itag {
path: string;
parentPath: string;
name: string;
meta: any;
}
import { multiType, positionType } from "./types";
export const useMultiTagsStore = defineStore({
id: "pure-multiTags",
@ -43,16 +36,16 @@ export const useMultiTagsStore = defineStore({
},
handleTags<T>(
mode: string,
value?: T | Itag,
value?: T | multiType,
position?: positionType
): any {
): T {
switch (mode) {
case "equal":
this.multiTags = value;
break;
case "push":
{
const tagVal = value as Itag;
const tagVal = value as multiType;
// 判断tag是否已存在:
const tagHasExits = this.multiTags.some(tag => {
return tag.path === tagVal?.path;

View File

@ -1,16 +1,11 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { setType } from "./types";
import { getConfig } from "/@/config";
interface SettingState {
title: string;
fixedHeader: boolean;
hiddenSideBar: boolean;
}
export const useSettingStore = defineStore({
id: "pure-setting",
state: (): SettingState => ({
state: (): setType => ({
title: getConfig().Title,
fixedHeader: getConfig().FixedHeader,
hiddenSideBar: getConfig().HiddenSideBar

View File

@ -9,3 +9,27 @@ export type positionType = {
startIndex?: number;
length?: number;
};
export type appType = {
sidebar: {
opened: boolean;
withoutAnimation: boolean;
// 判断是否手动点击Hamburger
isClickHamburger: boolean;
};
layout: string;
device: string;
};
export type multiType = {
path: string;
parentPath: string;
name: string;
meta: any;
};
export type setType = {
title: string;
fixedHeader: boolean;
hiddenSideBar: boolean;
};

View File

@ -1,19 +0,0 @@
import { i18n } from "../plugins/i18n";
/**
*
* @param message message
* @param isI18n true,,this
* @returns message
*/
export function transformI18n(message = "", isI18n = false) {
if (!message) {
return "";
}
if (isI18n) {
//@ts-ignore
return i18n.global.tc.call(i18n.global, message);
} else {
return message;
}
}