Browse Source

perf: 同步完整版

i18n
xiaoxian521 3 years ago
parent
commit
eb9d1e8238
  1. 85
      build/info.ts
  2. 2
      build/plugins.ts
  3. 7
      package.json
  4. 59
      pnpm-lock.yaml
  5. 4
      src/layout/components/setting/index.vue
  6. 2
      src/layout/components/sidebar/breadCrumb.vue
  7. 2
      src/layout/components/tag/index.vue
  8. 2
      src/plugins/i18n/index.ts
  9. 2
      src/router/index.ts
  10. 12
      src/router/utils.ts
  11. 2
      src/store/modules/multiTags.ts
  12. 2
      src/store/modules/permission.ts
  13. 11
      src/style/element-plus.scss

85
build/info.ts

@ -0,0 +1,85 @@
import { readdir, stat } from "fs";
import type { Plugin } from "vite";
import dayjs, { Dayjs } from "dayjs";
import { sum } from "lodash-unified";
import duration from "dayjs/plugin/duration";
import { green, blue, bold } from "picocolors";
dayjs.extend(duration);
const staticPath = "dist";
const fileListTotal: number[] = [];
const recursiveDirectory = (folder: string, callback: Function): void => {
readdir(folder, (err, files: string[]) => {
if (err) throw err;
let count = 0;
const checkEnd = () => {
++count == files.length && callback();
};
files.forEach((item: string) => {
stat(folder + "/" + item, async (err, stats) => {
if (err) throw err;
if (stats.isFile()) {
fileListTotal.push(stats.size);
checkEnd();
} else if (stats.isDirectory()) {
recursiveDirectory(`${staticPath}/${item}/`, checkEnd);
}
});
});
files.length === 0 && callback();
});
};
const formatBytes = (a: number, b?: number): string => {
if (0 == a) return "0 Bytes";
const c = 1024,
d = b || 2,
e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
f = Math.floor(Math.log(a) / Math.log(c));
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
};
export function viteBuildInfo(): Plugin {
let config: { command: string };
let startTime: Dayjs;
let endTime: Dayjs;
return {
name: "vite:buildInfo",
configResolved(resolvedConfig: { command: string }) {
config = resolvedConfig;
},
buildStart() {
if (config.command === "build") {
startTime = dayjs(new Date());
}
},
closeBundle() {
if (config.command === "build") {
console.log(
bold(
green(
`👏欢迎使用${blue(
"[vue-pure-admin]"
)}star哦💖 https://github.com/xiaoxian521/vue-pure-admin`
)
)
);
endTime = dayjs(new Date());
recursiveDirectory(staticPath, () => {
console.log(
bold(
green(
`恭喜打包完成🎉(总用时${dayjs
.duration(endTime.diff(startTime))
.format("mm分ss秒")}${formatBytes(
sum(fileListTotal)
)}`
)
)
);
});
}
}
};
}

2
build/plugins.ts

@ -1,4 +1,5 @@
import vue from "@vitejs/plugin-vue";
import { viteBuildInfo } from "./info";
import svgLoader from "vite-svg-loader";
import legacy from "@vitejs/plugin-legacy";
import vueJsx from "@vitejs/plugin-vue-jsx";
@ -20,6 +21,7 @@ export function getPluginsList(command, VITE_LEGACY) {
WindiCSS(),
// 线上环境删除console
removeConsole(),
viteBuildInfo(),
// 修改layout文件夹下的文件时自动重载浏览器 解决 https://github.com/xiaoxian521/vue-pure-admin/issues/170
liveReload(["src/layout/**/*", "src/router/**/*"]),
// 自定义主题

7
package.json

@ -37,10 +37,11 @@
"axios": "^0.25.0",
"css-color-function": "^1.3.3",
"dayjs": "^1.10.7",
"element-plus": "^2.0.2",
"element-plus": "^2.0.3",
"element-resize-detector": "^1.2.3",
"js-cookie": "^3.0.1",
"lodash-es": "^4.17.21",
"lodash-unified": "^1.0.2",
"mitt": "^3.0.0",
"mockjs": "^1.1.0",
"nprogress": "^0.2.0",
@ -65,6 +66,7 @@
"@iconify/vue": "^3.1.3",
"@types/element-resize-detector": "1.1.3",
"@types/js-cookie": "^3.0.1",
"@types/lodash-es": "^4.17.6",
"@types/mockjs": "1.0.3",
"@types/node": "14.14.14",
"@types/nprogress": "0.2.0",
@ -84,6 +86,7 @@
"eslint-plugin-vue": "^8.4.1",
"husky": "7.0.2",
"lint-staged": "11.1.2",
"picocolors": "^1.0.0",
"postcss": "^8.4.6",
"postcss-html": "^1.3.0",
"postcss-import": "14.0.0",
@ -91,7 +94,7 @@
"prettier": "^2.5.1",
"pretty-quick": "3.1.1",
"rimraf": "3.0.2",
"rollup-plugin-visualizer": "^5.5.4",
"rollup-plugin-visualizer": "^5.6.0",
"sass": "^1.49.0",
"sass-loader": "^12.4.0",
"stylelint": "^14.3.0",

59
pnpm-lock.yaml

@ -11,6 +11,7 @@ specifiers:
"@iconify/vue": ^3.1.3
"@types/element-resize-detector": 1.1.3
"@types/js-cookie": ^3.0.1
"@types/lodash-es": ^4.17.6
"@types/mockjs": 1.0.3
"@types/node": 14.14.14
"@types/nprogress": 0.2.0
@ -32,7 +33,7 @@ specifiers:
cross-env: 7.0.3
css-color-function: ^1.3.3
dayjs: ^1.10.7
element-plus: ^2.0.2
element-plus: ^2.0.3
element-resize-detector: ^1.2.3
eslint: ^8.8.0
eslint-plugin-prettier: ^4.0.0
@ -41,10 +42,12 @@ specifiers:
js-cookie: ^3.0.1
lint-staged: 11.1.2
lodash-es: ^4.17.21
lodash-unified: ^1.0.2
mitt: ^3.0.0
mockjs: ^1.1.0
nprogress: ^0.2.0
path: ^0.12.7
picocolors: ^1.0.0
pinia: ^2.0.11
postcss: ^8.4.6
postcss-html: ^1.3.0
@ -57,7 +60,7 @@ specifiers:
responsive-storage: ^1.0.11
rgb-hex: ^4.0.0
rimraf: 3.0.2
rollup-plugin-visualizer: ^5.5.4
rollup-plugin-visualizer: ^5.6.0
sass: ^1.49.0
sass-loader: ^12.4.0
stylelint: ^14.3.0
@ -91,10 +94,11 @@ dependencies:
axios: 0.25.0
css-color-function: 1.3.3
dayjs: 1.10.7
element-plus: 2.0.2_vue@3.2.31
element-plus: 2.0.3_1a412d14def5ff5ca1122000e4bee666
element-resize-detector: 1.2.4
js-cookie: 3.0.1
lodash-es: 4.17.21
lodash-unified: 1.0.2_f567d1d3c0c6a67669f03af7a1aa4dad
mitt: 3.0.0
mockjs: 1.1.0
nprogress: 0.2.0
@ -119,6 +123,7 @@ devDependencies:
"@iconify/vue": 3.1.3_vue@3.2.31
"@types/element-resize-detector": 1.1.3
"@types/js-cookie": 3.0.1
"@types/lodash-es": 4.17.6
"@types/mockjs": 1.0.3
"@types/node": 14.14.14
"@types/nprogress": 0.2.0
@ -138,6 +143,7 @@ devDependencies:
eslint-plugin-vue: 8.4.1_eslint@8.9.0
husky: 7.0.2
lint-staged: 11.1.2
picocolors: 1.0.0
postcss: 8.4.6
postcss-html: 1.3.0
postcss-import: 14.0.0_postcss@8.4.6
@ -145,7 +151,7 @@ devDependencies:
prettier: 2.5.1
pretty-quick: 3.1.1_prettier@2.5.1
rimraf: 3.0.2
rollup-plugin-visualizer: 5.5.4
rollup-plugin-visualizer: 5.6.0
sass: 1.49.7
sass-loader: 12.6.0_sass@1.49.7
stylelint: 14.5.0
@ -1098,6 +1104,22 @@ packages:
}
dev: true
/@types/lodash-es/4.17.6:
resolution:
{
integrity: sha512-R+zTeVUKDdfoRxpAryaQNRKk3105Rrgx2CFRClIgRGaqDTdjsm8h6IYA8ir584W3ePzkZfst5xIgDwYrlh9HLg==
}
dependencies:
"@types/lodash": 4.14.179
dev: true
/@types/lodash/4.14.179:
resolution:
{
integrity: sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w==
}
dev: true
/@types/minimatch/3.0.5:
resolution:
{
@ -2805,10 +2827,10 @@ packages:
}
dev: true
/element-plus/2.0.2_vue@3.2.31:
/element-plus/2.0.3_1a412d14def5ff5ca1122000e4bee666:
resolution:
{
integrity: sha512-URjC0HwwiqtlLxqTmHXQ31WXrdAq4ChWyyn52OcQs3PRsnMPfahGVq2AWnfzzlzlhVeI5lY3HQiuB1zDathS+g==
integrity: sha512-k+b4V4sGmgOpOYjrAWyp0k+N1mVaIZQ9LpbXWvmJNzE+j21DYOe9m1zGn5mFDPgeLOZcUS7QzzwYAommhwFj0g==
}
peerDependencies:
vue: ^3.2.0
@ -2821,7 +2843,7 @@ packages:
dayjs: 1.10.7
lodash: 4.17.21
lodash-es: 4.17.21
lodash-unified: 1.0.1_lodash-es@4.17.21+lodash@4.17.21
lodash-unified: 1.0.2_da03a4540fbd16bbaafbb96724306afd
memoize-one: 6.0.0
normalize-wheel-es: 1.1.1
vue: 3.2.31
@ -4388,20 +4410,35 @@ packages:
}
dev: false
/lodash-unified/1.0.1_lodash-es@4.17.21+lodash@4.17.21:
/lodash-unified/1.0.2_da03a4540fbd16bbaafbb96724306afd:
resolution:
{
integrity: sha512-Py+twfpWn+2dFQWCuGcp21WiQRwZwnm1cyE3piSt/VtBVKVyxlR58WgOVRzXtmdmDRGJKH8F8GPaA29WK/yK8g==
integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==
}
peerDependencies:
"@types/lodash-es": "*"
lodash: "*"
lodash-es: "*"
dependencies:
"@types/lodash-es": 4.17.6
lodash: 4.17.21
lodash-es: 4.17.21
dev: false
/lodash-unified/1.0.2_f567d1d3c0c6a67669f03af7a1aa4dad:
resolution:
{
integrity: sha512-OGbEy+1P+UT26CYi4opY4gebD8cWRDxAT6MAObIVQMiqYdxZr1g3QHWCToVsm31x2NkLS4K3+MC2qInaRMa39g==
}
peerDependencies:
"@types/lodash-es": "*"
lodash: "*"
lodash-es: "*"
dependencies:
"@types/lodash-es": 4.17.6
lodash-es: 4.17.21
dev: false
/lodash.get/4.4.2:
resolution: { integrity: sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= }
dev: true
@ -5866,10 +5903,10 @@ packages:
glob: 7.2.0
dev: true
/rollup-plugin-visualizer/5.5.4:
/rollup-plugin-visualizer/5.6.0:
resolution:
{
integrity: sha512-CJQFUuZ75S1daGEkk62UH7lL6UFCoP86Sn/iz4gXBdamdwFeD5nPGCHHXfXCrly/wNgQOYTH7cdcxk4+OG3Xjw==
integrity: sha512-CKcc8GTUZjC+LsMytU8ocRr/cGZIfMR7+mdy4YnlyetlmIl/dM8BMnOEpD4JPIGt+ZVW7Db9ZtSsbgyeBH3uTA==
}
engines: { node: ">=12" }
hasBin: true

4
src/layout/components/setting/index.vue

@ -10,7 +10,7 @@ import {
getCurrentInstance
} from "vue";
import rgbHex from "rgb-hex";
import { find } from "lodash-es";
import { find } from "lodash-unified";
import { getConfig } from "/@/config";
import { useRouter } from "vue-router";
import panel from "../panel/index.vue";
@ -111,7 +111,7 @@ function storageConfigureChange<T>(key: string, val: T): void {
function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
const targetEl = target || document.body;
let { className } = targetEl;
className = className.replace(clsName, "");
className = className.replace(clsName, "").trim();
targetEl.className = flag ? `${className} ${clsName} ` : className;
}

2
src/layout/components/sidebar/breadCrumb.vue

@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { isEqual } from "lodash-es";
import { isEqual } from "lodash-unified";
import { transformI18n } from "/@/plugins/i18n";
import { getParentPaths, findRouteByPath } from "/@/router/utils";
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";

2
src/layout/components/tag/index.vue

@ -21,10 +21,10 @@ import closeRight from "/@/assets/svg/close_right.svg?component";
import { emitter } from "/@/utils/mitt";
import { $t as t } from "/@/plugins/i18n";
import { isEqual, isEmpty } from "lodash-es";
import { transformI18n } from "/@/plugins/i18n";
import { storageLocal } from "/@/utils/storage";
import { useRoute, useRouter } from "vue-router";
import { isEqual, isEmpty } from "lodash-unified";
import { RouteConfigs, tagsViewsType } from "../../types";
import { useSettingStoreHook } from "/@/store/modules/settings";
import { handleAliveRoute, delAliveRoutes } from "/@/router/utils";

2
src/plugins/i18n/index.ts

@ -1,6 +1,6 @@
// 多组件库的国际化和本地项目国际化兼容
import { App } from "vue";
import { set } from "lodash-es";
import { set } from "lodash-unified";
import { createI18n } from "vue-i18n";
import { localesConfigs } from "./config";
import { storageLocal } from "/@/utils/storage";

2
src/router/index.ts

@ -2,7 +2,7 @@ import { toRouteType } from "./types";
import { openLink } from "/@/utils/link";
import NProgress from "/@/utils/progress";
import { constantRoutes } from "./modules";
import { split, findIndex } from "lodash-es";
import { split, findIndex } from "lodash-unified";
import { transformI18n } from "/@/plugins/i18n";
import remainingRouter from "./modules/remaining";
import { storageSession } from "/@/utils/storage";

12
src/router/utils.ts

@ -11,6 +11,7 @@ import { loadEnv } from "../../build";
import Layout from "/@/layout/index.vue";
import { useTimeoutFn } from "@vueuse/core";
import { RouteConfigs } from "/@/layout/types";
import { buildHierarchyTree } from "/@/utils/tree";
import { usePermissionStoreHook } from "/@/store/modules/permission";
// https://cn.vitejs.dev/guide/features.html#glob-import
const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
@ -146,14 +147,15 @@ function initRouter(name: string) {
*/
function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
if (routesList.length === 0) return routesList;
for (let i = 0; i < routesList.length; i++) {
if (routesList[i].children) {
routesList = routesList
let hierarchyList = buildHierarchyTree(routesList);
for (let i = 0; i < hierarchyList.length; i++) {
if (hierarchyList[i].children) {
hierarchyList = hierarchyList
.slice(0, i + 1)
.concat(routesList[i].children, routesList.slice(i + 1));
.concat(hierarchyList[i].children, hierarchyList.slice(i + 1));
}
}
return routesList;
return hierarchyList;
}
/**

2
src/store/modules/multiTags.ts

@ -1,6 +1,6 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { isEqual } from "lodash-es";
import { isEqual } from "lodash-unified";
import { storageLocal } from "/@/utils/storage";
import { multiType, positionType } from "./types";

2
src/store/modules/permission.ts

@ -1,7 +1,7 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { cacheType } from "./types";
import { cloneDeep } from "lodash-es";
import { cloneDeep } from "lodash-unified";
import { RouteConfigs } from "/@/layout/types";
import { constantMenus } from "/@/router/modules";
import { ascending, filterTree } from "/@/router/utils";

11
src/style/element-plus.scss

@ -38,25 +38,14 @@
/* 动态改变cssvar 用于主题切换 https://github.com/element-plus/element-plus/issues/4856#issuecomment-1000174357 */
.el-button--primary {
--el-button-bg-color: var(--el-color-primary) !important;
--el-button-border-color: var(--el-color-primary) !important;
--el-button-hover-bg-color: var(--el-color-primary-light-2) !important;
--el-button-hover-border-color: var(--el-color-primary-light-2) !important;
--el-button-active-bg-color: var(--el-color-primary-active) !important;
--el-button-active-border-color: var(--el-color-primary-active) !important;
}
/* button--primary plain */
.el-button--primary.is-plain {
--el-button-bg-color: var(--el-color-primary-light-9) !important;
--el-button-border-color: var(--el-color-primary-light-6) !important;
--el-button-hover-bg-color: var(--el-color-primary-light-1) !important;
--el-button-hover-border-color: var(--el-color-primary) !important;
--el-button-active-bg-color: var(--el-color-primary) !important;
--el-button-active-border-color: var(--el-color-primary) !important;
--el-button-text-color: var(--el-color-primary) !important;
--el-button-hover-text-color: var(--el-color-white) !important;
--el-button-active-text-color: var(--el-color-white) !important;
}
/* nprogress适配ep的primary */

Loading…
Cancel
Save