Commit be3a3ed699f73d352d49623ef07288093a3332c4
1 parent
562189df
perf: remove useless code
Showing
23 changed files
with
46 additions
and
521 deletions
.env.production
@@ -7,7 +7,7 @@ VITE_PUBLIC_PATH = / | @@ -7,7 +7,7 @@ VITE_PUBLIC_PATH = / | ||
7 | # Delete console | 7 | # Delete console |
8 | VITE_DROP_CONSOLE = true | 8 | VITE_DROP_CONSOLE = true |
9 | 9 | ||
10 | -# Whether to enable gizp or brotli compression | 10 | +# Whether to enable gzip or brotli compression |
11 | # Optional: gzip | brotli | none | 11 | # Optional: gzip | brotli | none |
12 | # If you need multiple forms, you can use `,` to separate | 12 | # If you need multiple forms, you can use `,` to separate |
13 | VITE_BUILD_COMPRESS = 'none' | 13 | VITE_BUILD_COMPRESS = 'none' |
src/App.vue
@@ -22,10 +22,12 @@ | @@ -22,10 +22,12 @@ | ||
22 | setup() { | 22 | setup() { |
23 | // support Multi-language | 23 | // support Multi-language |
24 | const { antConfigLocale, setLocale } = useLocale(); | 24 | const { antConfigLocale, setLocale } = useLocale(); |
25 | + | ||
25 | setLocale(); | 26 | setLocale(); |
26 | 27 | ||
27 | // Initialize vuex internal system configuration | 28 | // Initialize vuex internal system configuration |
28 | initAppConfigStore(); | 29 | initAppConfigStore(); |
30 | + | ||
29 | // Create a lock screen monitor | 31 | // Create a lock screen monitor |
30 | const lockEvent = useLockPage(); | 32 | const lockEvent = useLockPage(); |
31 | 33 |
src/components/Form/src/hooks/useFormEvents.ts
@@ -5,10 +5,10 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; | @@ -5,10 +5,10 @@ import type { NamePath } from 'ant-design-vue/lib/form/interface'; | ||
5 | import { unref, toRaw } from 'vue'; | 5 | import { unref, toRaw } from 'vue'; |
6 | 6 | ||
7 | import { isArray, isFunction, isObject, isString } from '/@/utils/is'; | 7 | import { isArray, isFunction, isObject, isString } from '/@/utils/is'; |
8 | -import { deepMerge, unique } from '/@/utils'; | 8 | +import { deepMerge } from '/@/utils'; |
9 | import { dateItemType, handleInputNumberValue } from '../helper'; | 9 | import { dateItemType, handleInputNumberValue } from '../helper'; |
10 | import { dateUtil } from '/@/utils/dateUtil'; | 10 | import { dateUtil } from '/@/utils/dateUtil'; |
11 | -import { cloneDeep } from 'lodash-es'; | 11 | +import { cloneDeep, uniqBy } from 'lodash-es'; |
12 | import { error } from '/@/utils/log'; | 12 | import { error } from '/@/utils/log'; |
13 | 13 | ||
14 | interface UseFormActionContext { | 14 | interface UseFormActionContext { |
@@ -160,7 +160,7 @@ export function useFormEvents({ | @@ -160,7 +160,7 @@ export function useFormEvents({ | ||
160 | } | 160 | } |
161 | }); | 161 | }); |
162 | }); | 162 | }); |
163 | - schemaRef.value = unique(schema, 'field'); | 163 | + schemaRef.value = uniqBy(schema, 'field'); |
164 | } | 164 | } |
165 | 165 | ||
166 | function getFieldsValue(): Recordable { | 166 | function getFieldsValue(): Recordable { |
src/components/Menu/src/useOpenKeys.ts
@@ -5,7 +5,7 @@ import type { MenuState } from './types'; | @@ -5,7 +5,7 @@ import type { MenuState } from './types'; | ||
5 | import { computed, Ref, toRaw } from 'vue'; | 5 | import { computed, Ref, toRaw } from 'vue'; |
6 | 6 | ||
7 | import { unref } from 'vue'; | 7 | import { unref } from 'vue'; |
8 | -import { es6Unique } from '/@/utils'; | 8 | +import { uniq } from 'lodash-es'; |
9 | import { useMenuSetting } from '/@/hooks/setting/useMenuSetting'; | 9 | import { useMenuSetting } from '/@/hooks/setting/useMenuSetting'; |
10 | import { getAllParentPath } from '/@/router/helper/menuHelper'; | 10 | import { getAllParentPath } from '/@/router/helper/menuHelper'; |
11 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; | 11 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
@@ -31,10 +31,7 @@ export function useOpenKeys( | @@ -31,10 +31,7 @@ export function useOpenKeys( | ||
31 | return; | 31 | return; |
32 | } | 32 | } |
33 | if (!unref(accordion)) { | 33 | if (!unref(accordion)) { |
34 | - menuState.openKeys = es6Unique([ | ||
35 | - ...menuState.openKeys, | ||
36 | - ...getAllParentPath(menuList, path), | ||
37 | - ]); | 34 | + menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)]); |
38 | } else { | 35 | } else { |
39 | menuState.openKeys = getAllParentPath(menuList, path); | 36 | menuState.openKeys = getAllParentPath(menuList, path); |
40 | } | 37 | } |
src/components/SimpleMenu/src/useOpenKeys.ts
@@ -4,8 +4,9 @@ import type { MenuState } from './types'; | @@ -4,8 +4,9 @@ import type { MenuState } from './types'; | ||
4 | import { computed, Ref, toRaw } from 'vue'; | 4 | import { computed, Ref, toRaw } from 'vue'; |
5 | 5 | ||
6 | import { unref } from 'vue'; | 6 | import { unref } from 'vue'; |
7 | -import { es6Unique } from '/@/utils'; | 7 | +import { uniq } from 'lodash-es'; |
8 | import { getAllParentPath } from '/@/router/helper/menuHelper'; | 8 | import { getAllParentPath } from '/@/router/helper/menuHelper'; |
9 | + | ||
9 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; | 10 | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
10 | 11 | ||
11 | export function useOpenKeys( | 12 | export function useOpenKeys( |
@@ -31,7 +32,7 @@ export function useOpenKeys( | @@ -31,7 +32,7 @@ export function useOpenKeys( | ||
31 | } | 32 | } |
32 | const keys = getAllParentPath(menuList, path); | 33 | const keys = getAllParentPath(menuList, path); |
33 | if (!unref(accordion)) { | 34 | if (!unref(accordion)) { |
34 | - menuState.openNames = es6Unique([...menuState.openNames, ...keys]); | 35 | + menuState.openNames = uniq([...menuState.openNames, ...keys]); |
35 | } else { | 36 | } else { |
36 | menuState.openNames = keys; | 37 | menuState.openNames = keys; |
37 | } | 38 | } |
src/components/VirtualScroll/src/index.tsx
@@ -11,12 +11,22 @@ import { | @@ -11,12 +11,22 @@ import { | ||
11 | } from 'vue'; | 11 | } from 'vue'; |
12 | import { useEventListener } from '/@/hooks/event/useEventListener'; | 12 | import { useEventListener } from '/@/hooks/event/useEventListener'; |
13 | 13 | ||
14 | -import { convertToUnit } from '/@/components/util'; | ||
15 | import { props as basicProps } from './props'; | 14 | import { props as basicProps } from './props'; |
16 | import { getSlot } from '/@/utils/helper/tsxHelper'; | 15 | import { getSlot } from '/@/utils/helper/tsxHelper'; |
17 | import './index.less'; | 16 | import './index.less'; |
18 | 17 | ||
19 | const prefixCls = 'virtual-scroll'; | 18 | const prefixCls = 'virtual-scroll'; |
19 | + | ||
20 | +function convertToUnit(str: string | number | null | undefined, unit = 'px'): string | undefined { | ||
21 | + if (str == null || str === '') { | ||
22 | + return undefined; | ||
23 | + } else if (isNaN(+str!)) { | ||
24 | + return String(str); | ||
25 | + } else { | ||
26 | + return `${Number(str)}${unit}`; | ||
27 | + } | ||
28 | +} | ||
29 | + | ||
20 | export default defineComponent({ | 30 | export default defineComponent({ |
21 | name: 'VirtualScroll', | 31 | name: 'VirtualScroll', |
22 | props: basicProps, | 32 | props: basicProps, |
src/components/registerGlobComp.ts
@@ -3,42 +3,6 @@ import { Button } from './Button'; | @@ -3,42 +3,6 @@ import { Button } from './Button'; | ||
3 | import { | 3 | import { |
4 | // Need | 4 | // Need |
5 | Button as AntButton, | 5 | Button as AntButton, |
6 | - | ||
7 | - // Optional | ||
8 | - // Select, | ||
9 | - // Alert, | ||
10 | - // Checkbox, | ||
11 | - // DatePicker, | ||
12 | - // Radio, | ||
13 | - // Switch, | ||
14 | - // Card, | ||
15 | - // List, | ||
16 | - // Tabs, | ||
17 | - // Descriptions, | ||
18 | - // Tree, | ||
19 | - // Table, | ||
20 | - // Divider, | ||
21 | - // Modal, | ||
22 | - // Drawer, | ||
23 | - // Dropdown, | ||
24 | - // Tag, | ||
25 | - // Tooltip, | ||
26 | - // Badge, | ||
27 | - // Popover, | ||
28 | - // Upload, | ||
29 | - // Transfer, | ||
30 | - // Steps, | ||
31 | - // PageHeader, | ||
32 | - // Result, | ||
33 | - // Empty, | ||
34 | - // Avatar, | ||
35 | - // Menu, | ||
36 | - // Breadcrumb, | ||
37 | - // Form, | ||
38 | - // Input, | ||
39 | - // Row, | ||
40 | - // Col, | ||
41 | - // Spin, | ||
42 | } from 'ant-design-vue'; | 6 | } from 'ant-design-vue'; |
43 | 7 | ||
44 | import { App } from 'vue'; | 8 | import { App } from 'vue'; |
@@ -47,45 +11,6 @@ const compList = [Icon, Button, AntButton.Group]; | @@ -47,45 +11,6 @@ const compList = [Icon, Button, AntButton.Group]; | ||
47 | 11 | ||
48 | export function registerGlobComp(app: App) { | 12 | export function registerGlobComp(app: App) { |
49 | compList.forEach((comp: any) => { | 13 | compList.forEach((comp: any) => { |
50 | - app.component(comp.name, comp); | 14 | + app.component(comp.name || comp.displayName, comp); |
51 | }); | 15 | }); |
52 | - | ||
53 | - // Optional | ||
54 | - // If you need to customize global components, you can write here | ||
55 | - // If you don’t need it, you can delete it | ||
56 | - // app | ||
57 | - // .use(Select) | ||
58 | - // .use(Alert) | ||
59 | - // .use(Breadcrumb) | ||
60 | - // .use(Checkbox) | ||
61 | - // .use(DatePicker) | ||
62 | - // .use(Radio) | ||
63 | - // .use(Switch) | ||
64 | - // .use(Card) | ||
65 | - // .use(List) | ||
66 | - // .use(Descriptions) | ||
67 | - // .use(Tree) | ||
68 | - // .use(Table) | ||
69 | - // .use(Divider) | ||
70 | - // .use(Modal) | ||
71 | - // .use(Drawer) | ||
72 | - // .use(Dropdown) | ||
73 | - // .use(Tag) | ||
74 | - // .use(Tooltip) | ||
75 | - // .use(Badge) | ||
76 | - // .use(Popover) | ||
77 | - // .use(Upload) | ||
78 | - // .use(Transfer) | ||
79 | - // .use(Steps) | ||
80 | - // .use(PageHeader) | ||
81 | - // .use(Result) | ||
82 | - // .use(Empty) | ||
83 | - // .use(Avatar) | ||
84 | - // .use(Menu) | ||
85 | - // .use(Tabs) | ||
86 | - // .use(Form) | ||
87 | - // .use(Input) | ||
88 | - // .use(Row) | ||
89 | - // .use(Col) | ||
90 | - // .use(Spin); | ||
91 | } | 16 | } |
src/components/types.ts deleted
100644 → 0
src/components/util.tsx deleted
100644 → 0
1 | -import type { VNodeChild } from 'vue'; | ||
2 | - | ||
3 | -export function convertToUnit( | ||
4 | - str: string | number | null | undefined, | ||
5 | - unit = 'px' | ||
6 | -): string | undefined { | ||
7 | - if (str == null || str === '') { | ||
8 | - return undefined; | ||
9 | - } else if (isNaN(+str!)) { | ||
10 | - return String(str); | ||
11 | - } else { | ||
12 | - return `${Number(str)}${unit}`; | ||
13 | - } | ||
14 | -} | ||
15 | - | ||
16 | -/** | ||
17 | - * Camelize a hyphen-delimited string. | ||
18 | - */ | ||
19 | -const camelizeRE = /-(\w)/g; | ||
20 | -export const camelize = (str: string): string => { | ||
21 | - return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); | ||
22 | -}; | ||
23 | - | ||
24 | -export function wrapInArray<T>(v: T | T[] | null | undefined): T[] { | ||
25 | - return v != null ? (Array.isArray(v) ? v : [v]) : []; | ||
26 | -} | ||
27 | - | ||
28 | -const pattern = { | ||
29 | - styleList: /;(?![^(]*\))/g, | ||
30 | - styleProp: /:(.*)/, | ||
31 | -} as const; | ||
32 | - | ||
33 | -function parseStyle(style: string) { | ||
34 | - const styleMap: Recordable = {}; | ||
35 | - | ||
36 | - for (const s of style.split(pattern.styleList)) { | ||
37 | - let [key, val] = s.split(pattern.styleProp); | ||
38 | - key = key.trim(); | ||
39 | - if (!key) { | ||
40 | - continue; | ||
41 | - } | ||
42 | - // May be undefined if the `key: value` pair is incomplete. | ||
43 | - if (typeof val === 'string') { | ||
44 | - val = val.trim(); | ||
45 | - } | ||
46 | - styleMap[camelize(key)] = val; | ||
47 | - } | ||
48 | - | ||
49 | - return styleMap; | ||
50 | -} | ||
51 | - | ||
52 | -/** | ||
53 | - * Intelligently merges data for createElement. | ||
54 | - * Merges arguments left to right, preferring the right argument. | ||
55 | - * Returns new VNodeData object. | ||
56 | - */ | ||
57 | -export function mergeData(...vNodeData: VNodeChild[]): VNodeChild; | ||
58 | -export function mergeData(...args: any[]): VNodeChild { | ||
59 | - const mergeTarget: any = {}; | ||
60 | - let i: number = args.length; | ||
61 | - let prop: string; | ||
62 | - | ||
63 | - // Allow for variadic argument length. | ||
64 | - while (i--) { | ||
65 | - // Iterate through the data properties and execute merge strategies | ||
66 | - // Object.keys eliminates need for hasOwnProperty call | ||
67 | - for (prop of Object.keys(args[i])) { | ||
68 | - switch (prop) { | ||
69 | - // Array merge strategy (array concatenation) | ||
70 | - case 'class': | ||
71 | - case 'directives': | ||
72 | - if (args[i][prop]) { | ||
73 | - mergeTarget[prop] = mergeClasses(mergeTarget[prop], args[i][prop]); | ||
74 | - } | ||
75 | - break; | ||
76 | - case 'style': | ||
77 | - if (args[i][prop]) { | ||
78 | - mergeTarget[prop] = mergeStyles(mergeTarget[prop], args[i][prop]); | ||
79 | - } | ||
80 | - break; | ||
81 | - // Space delimited string concatenation strategy | ||
82 | - case 'staticClass': | ||
83 | - if (!args[i][prop]) { | ||
84 | - break; | ||
85 | - } | ||
86 | - if (mergeTarget[prop] === undefined) { | ||
87 | - mergeTarget[prop] = ''; | ||
88 | - } | ||
89 | - if (mergeTarget[prop]) { | ||
90 | - // Not an empty string, so concatenate | ||
91 | - mergeTarget[prop] += ' '; | ||
92 | - } | ||
93 | - mergeTarget[prop] += args[i][prop].trim(); | ||
94 | - break; | ||
95 | - // Object, the properties of which to merge via array merge strategy (array concatenation). | ||
96 | - // Callback merge strategy merges callbacks to the beginning of the array, | ||
97 | - // so that the last defined callback will be invoked first. | ||
98 | - // This is done since to mimic how Object.assign merging | ||
99 | - // uses the last given value to assign. | ||
100 | - case 'on': | ||
101 | - case 'nativeOn': | ||
102 | - if (args[i][prop]) { | ||
103 | - mergeTarget[prop] = mergeListeners(mergeTarget[prop], args[i][prop]); | ||
104 | - } | ||
105 | - break; | ||
106 | - // Object merge strategy | ||
107 | - case 'attrs': | ||
108 | - case 'props': | ||
109 | - case 'domProps': | ||
110 | - case 'scopedSlots': | ||
111 | - case 'staticStyle': | ||
112 | - case 'hook': | ||
113 | - case 'transition': | ||
114 | - if (!args[i][prop]) { | ||
115 | - break; | ||
116 | - } | ||
117 | - if (!mergeTarget[prop]) { | ||
118 | - mergeTarget[prop] = {}; | ||
119 | - } | ||
120 | - mergeTarget[prop] = { ...args[i][prop], ...mergeTarget[prop] }; | ||
121 | - break; | ||
122 | - // Reassignment strategy (no merge) | ||
123 | - default: | ||
124 | - // slot, key, ref, tag, show, keepAlive | ||
125 | - if (!mergeTarget[prop]) { | ||
126 | - mergeTarget[prop] = args[i][prop]; | ||
127 | - } | ||
128 | - } | ||
129 | - } | ||
130 | - } | ||
131 | - | ||
132 | - return mergeTarget; | ||
133 | -} | ||
134 | - | ||
135 | -export function mergeStyles( | ||
136 | - target: undefined | string | object[] | object, | ||
137 | - source: undefined | string | object[] | object | ||
138 | -) { | ||
139 | - if (!target) return source; | ||
140 | - if (!source) return target; | ||
141 | - | ||
142 | - target = wrapInArray(typeof target === 'string' ? parseStyle(target) : target); | ||
143 | - | ||
144 | - return (target as object[]).concat(typeof source === 'string' ? parseStyle(source) : source); | ||
145 | -} | ||
146 | - | ||
147 | -export function mergeClasses(target: any, source: any) { | ||
148 | - if (!source) return target; | ||
149 | - if (!target) return source; | ||
150 | - | ||
151 | - return target ? wrapInArray(target).concat(source) : source; | ||
152 | -} | ||
153 | - | ||
154 | -export function mergeListeners( | ||
155 | - target: Indexable<Function | Function[]> | undefined, | ||
156 | - source: Indexable<Function | Function[]> | undefined | ||
157 | -) { | ||
158 | - if (!target) return source; | ||
159 | - if (!source) return target; | ||
160 | - | ||
161 | - let event: string; | ||
162 | - | ||
163 | - for (event of Object.keys(source)) { | ||
164 | - // Concat function to array of functions if callback present. | ||
165 | - if (target[event]) { | ||
166 | - // Insert current iteration data in beginning of merged array. | ||
167 | - target[event] = wrapInArray(target[event]); | ||
168 | - (target[event] as Function[]).push(...wrapInArray(source[event])); | ||
169 | - } else { | ||
170 | - // Straight assign. | ||
171 | - target[event] = source[event]; | ||
172 | - } | ||
173 | - } | ||
174 | - | ||
175 | - return target; | ||
176 | -} |
src/hooks/core/useDebouncedRef.ts deleted
100644 → 0
1 | -import { customRef } from 'vue'; | ||
2 | - | ||
3 | -export function useDebouncedRef<T = any>(value: T, delay = 100) { | ||
4 | - let timeout: TimeoutHandle; | ||
5 | - return customRef((track, trigger) => { | ||
6 | - return { | ||
7 | - get() { | ||
8 | - track(); | ||
9 | - return value; | ||
10 | - }, | ||
11 | - set(newValue: T) { | ||
12 | - clearTimeout(timeout); | ||
13 | - timeout = setTimeout(() => { | ||
14 | - value = newValue; | ||
15 | - trigger(); | ||
16 | - }, delay); | ||
17 | - }, | ||
18 | - }; | ||
19 | - }); | ||
20 | -} |
src/hooks/core/useEffect.ts deleted
100644 → 0
1 | -import { watch } from 'vue'; | ||
2 | -import { isFunction } from '/@/utils/is'; | ||
3 | - | ||
4 | -export function useEffect<T extends any = any>( | ||
5 | - effectHandler: (deps: T[], prevDeps?: T[]) => () => void, | ||
6 | - dependencies: T[] | ||
7 | -) { | ||
8 | - return watch( | ||
9 | - dependencies, | ||
10 | - (changedDependencies, prevDependencies, onCleanUp) => { | ||
11 | - const effectCleaner = effectHandler(changedDependencies, prevDependencies); | ||
12 | - if (isFunction(effectCleaner)) { | ||
13 | - onCleanUp(effectCleaner); | ||
14 | - } | ||
15 | - }, | ||
16 | - { immediate: true, deep: true } | ||
17 | - ); | ||
18 | -} |
src/hooks/core/useState.ts deleted
100644 → 0
1 | -import { isObject } from '@vue/shared'; | ||
2 | -import { reactive, Ref, ref, readonly } from 'vue'; | ||
3 | -import { isFunction } from '/@/utils/is'; | ||
4 | - | ||
5 | -type State<T> = ((s: T) => T) | T; | ||
6 | -type Dispatch<T> = (t: T) => void; | ||
7 | - | ||
8 | -type DispatchState<T> = Dispatch<State<T>>; | ||
9 | - | ||
10 | -type ResultState<T> = Readonly<Ref<T>>; | ||
11 | - | ||
12 | -export function useState<T extends undefined>( | ||
13 | - initialState: (() => T) | T | ||
14 | -): [ResultState<T>, DispatchState<T>]; | ||
15 | - | ||
16 | -export function useState<T extends null>( | ||
17 | - initialState: (() => T) | T | ||
18 | -): [ResultState<T>, DispatchState<T>]; | ||
19 | - | ||
20 | -export function useState<T extends boolean>( | ||
21 | - initialState: (() => T) | T | ||
22 | -): [ResultState<boolean>, DispatchState<boolean>]; | ||
23 | - | ||
24 | -export function useState<T extends string>( | ||
25 | - initialState: (() => T) | T | ||
26 | -): [ResultState<string>, DispatchState<string>]; | ||
27 | - | ||
28 | -export function useState<T extends number>( | ||
29 | - initialState: (() => T) | T | ||
30 | -): [ResultState<number>, DispatchState<number>]; | ||
31 | - | ||
32 | -export function useState<T extends object>( | ||
33 | - initialState: (() => T) | T | ||
34 | -): [Readonly<T>, DispatchState<T>]; | ||
35 | - | ||
36 | -export function useState<T extends any>( | ||
37 | - initialState: (() => T) | T | ||
38 | -): [Readonly<T>, DispatchState<T>]; | ||
39 | - | ||
40 | -export function useState<T>(initialState: (() => T) | T): [ResultState<T> | T, DispatchState<T>] { | ||
41 | - if (isFunction(initialState)) { | ||
42 | - initialState = (initialState as Fn)(); | ||
43 | - } | ||
44 | - | ||
45 | - if (isObject(initialState)) { | ||
46 | - const state = reactive({ data: initialState }) as any; | ||
47 | - const setState = (newState: T) => { | ||
48 | - state.data = newState; | ||
49 | - }; | ||
50 | - return [readonly(state), setState]; | ||
51 | - } else { | ||
52 | - const state = ref(initialState) as any; | ||
53 | - const setState = (newState: T) => { | ||
54 | - state.value = newState; | ||
55 | - }; | ||
56 | - return [readonly(state), setState]; | ||
57 | - } | ||
58 | -} |
src/layouts/iframe/index.vue
@@ -21,9 +21,7 @@ | @@ -21,9 +21,7 @@ | ||
21 | setup() { | 21 | setup() { |
22 | const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive(); | 22 | const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive(); |
23 | 23 | ||
24 | - const showFrame = computed(() => { | ||
25 | - return unref(getFramePages).length > 0; | ||
26 | - }); | 24 | + const showFrame = computed(() => unref(getFramePages).length > 0); |
27 | 25 | ||
28 | return { getFramePages, hasRenderFrame, showIframe, showFrame }; | 26 | return { getFramePages, hasRenderFrame, showIframe, showFrame }; |
29 | }, | 27 | }, |
src/layouts/iframe/useFrameKeepAlive.ts
@@ -4,7 +4,7 @@ import { computed, toRaw, unref } from 'vue'; | @@ -4,7 +4,7 @@ import { computed, toRaw, unref } from 'vue'; | ||
4 | 4 | ||
5 | import { tabStore } from '/@/store/modules/tab'; | 5 | import { tabStore } from '/@/store/modules/tab'; |
6 | 6 | ||
7 | -import { unique } from '/@/utils'; | 7 | +import { uniqBy } from 'lodash-es'; |
8 | 8 | ||
9 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; | 9 | import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting'; |
10 | 10 | ||
@@ -40,7 +40,7 @@ export function useFrameKeepAlive() { | @@ -40,7 +40,7 @@ export function useFrameKeepAlive() { | ||
40 | res.push(...getAllFramePages(children)); | 40 | res.push(...getAllFramePages(children)); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | - res = unique(res, 'name'); | 43 | + res = uniqBy(res, 'name'); |
44 | return res; | 44 | return res; |
45 | } | 45 | } |
46 | 46 |
src/router/guard/permissionGuard.ts
@@ -3,7 +3,7 @@ import type { Router, RouteRecordRaw } from 'vue-router'; | @@ -3,7 +3,7 @@ import type { Router, RouteRecordRaw } from 'vue-router'; | ||
3 | import { permissionStore } from '/@/store/modules/permission'; | 3 | import { permissionStore } from '/@/store/modules/permission'; |
4 | 4 | ||
5 | import { PageEnum } from '/@/enums/pageEnum'; | 5 | import { PageEnum } from '/@/enums/pageEnum'; |
6 | -import { getToken } from '/@/utils/auth'; | 6 | +import { userStore } from '/@/store/modules/user'; |
7 | 7 | ||
8 | import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant'; | 8 | import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant'; |
9 | 9 | ||
@@ -25,7 +25,7 @@ export function createPermissionGuard(router: Router) { | @@ -25,7 +25,7 @@ export function createPermissionGuard(router: Router) { | ||
25 | return; | 25 | return; |
26 | } | 26 | } |
27 | 27 | ||
28 | - const token = getToken(); | 28 | + const token = userStore.getTokenState; |
29 | 29 | ||
30 | // token does not exist | 30 | // token does not exist |
31 | if (!token) { | 31 | if (!token) { |
src/router/types.ts
1 | import type { RouteRecordRaw } from 'vue-router'; | 1 | import type { RouteRecordRaw } from 'vue-router'; |
2 | import { RoleEnum } from '/@/enums/roleEnum'; | 2 | import { RoleEnum } from '/@/enums/roleEnum'; |
3 | 3 | ||
4 | -import type { Component } from '/@/components/types'; | 4 | +import { defineComponent } from 'vue'; |
5 | + | ||
6 | +export type Component<T extends any = any> = | ||
7 | + | ReturnType<typeof defineComponent> | ||
8 | + | (() => Promise<typeof import('*.vue')>) | ||
9 | + | (() => Promise<T>); | ||
5 | 10 | ||
6 | export interface RouteMeta { | 11 | export interface RouteMeta { |
7 | // title | 12 | // title |
src/types/shims-volar.d.ts deleted
100644 → 0
1 | -import { RouterLink, RouterView } from 'vue-router'; | ||
2 | - | ||
3 | -import { Button } from '/@/components/Button'; | ||
4 | -import { Col, Row } from 'ant-design-vue'; | ||
5 | - | ||
6 | -declare global { | ||
7 | - interface __VLS_GlobalComponents { | ||
8 | - RouterLink: typeof RouterLink; | ||
9 | - RouterView: typeof RouterView; | ||
10 | - 'a-button': typeof Button; | ||
11 | - 'a-col': typeof Col; | ||
12 | - 'a-row': typeof Row; | ||
13 | - } | ||
14 | -} |
src/utils/auth/index.ts deleted
100644 → 0
src/utils/cache/cookie.ts deleted
100644 → 0
1 | -import { DEFAULT_CACHE_TIME } from '../../settings/encryptionSetting'; | ||
2 | -import { getStorageShortName } from '/@/utils/helper/envHelper'; | ||
3 | -import { cacheCipher } from '/@/settings/encryptionSetting'; | ||
4 | -import Encryption from '/@/utils/encryption/aesEncryption'; | ||
5 | - | ||
6 | -export default class WebCookie { | ||
7 | - private encryption: Encryption; | ||
8 | - private hasEncrypt: boolean; | ||
9 | - | ||
10 | - constructor(hasEncrypt = true, key = cacheCipher.key, iv = cacheCipher.iv) { | ||
11 | - const encryption = new Encryption({ key, iv }); | ||
12 | - this.encryption = encryption; | ||
13 | - this.hasEncrypt = hasEncrypt; | ||
14 | - } | ||
15 | - | ||
16 | - private getKey(key: string) { | ||
17 | - return `${getStorageShortName()}${key}`.toUpperCase(); | ||
18 | - } | ||
19 | - | ||
20 | - /** | ||
21 | - * Add cookie | ||
22 | - * @param name cookie key | ||
23 | - * @param value cookie value | ||
24 | - * @param expire | ||
25 | - * If the expiration time is not set, the default management browser will automatically delete | ||
26 | - * e.g: | ||
27 | - * cookieData.set('name','value',) | ||
28 | - */ | ||
29 | - setCookie(key: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) { | ||
30 | - value = this.hasEncrypt ? this.encryption.encryptByAES(JSON.stringify(value)) : value; | ||
31 | - document.cookie = this.getKey(key) + '=' + value + '; Max-Age=' + expire; | ||
32 | - } | ||
33 | - | ||
34 | - /** | ||
35 | - * Get the cook value according to the key | ||
36 | - * @param key cookie key | ||
37 | - */ | ||
38 | - getCookie(key: string) { | ||
39 | - const arr = document.cookie.split('; '); | ||
40 | - for (let i = 0; i < arr.length; i++) { | ||
41 | - const arr2 = arr[i].split('='); | ||
42 | - if (arr2[0] === this.getKey(key)) { | ||
43 | - let message: any = null; | ||
44 | - const str = arr2[1]; | ||
45 | - if (this.hasEncrypt && str) { | ||
46 | - message = this.encryption.decryptByAES(str); | ||
47 | - try { | ||
48 | - return JSON.parse(message); | ||
49 | - } catch (e) { | ||
50 | - return str; | ||
51 | - } | ||
52 | - } | ||
53 | - return str; | ||
54 | - } | ||
55 | - } | ||
56 | - return ''; | ||
57 | - } | ||
58 | - | ||
59 | - /** | ||
60 | - * Delete cookie based on cookie key | ||
61 | - * @param key cookie key | ||
62 | - */ | ||
63 | - removeCookie(key: string) { | ||
64 | - this.setCookie(key, 1, -1); | ||
65 | - } | ||
66 | - | ||
67 | - /** | ||
68 | - * clear cookie | ||
69 | - */ | ||
70 | - clearCookie(): void { | ||
71 | - const keys = document.cookie.match(/[^ =;]+(?==)/g); | ||
72 | - if (keys) { | ||
73 | - for (let i = keys.length; i--; ) { | ||
74 | - document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString(); | ||
75 | - } | ||
76 | - } | ||
77 | - } | ||
78 | -} |
src/utils/domUtils.ts
@@ -73,13 +73,13 @@ export function removeClass(el: Element, cls: string) { | @@ -73,13 +73,13 @@ export function removeClass(el: Element, cls: string) { | ||
73 | } | 73 | } |
74 | } | 74 | } |
75 | /** | 75 | /** |
76 | - * 获取当前元素的left、top偏移 | ||
77 | - * left:元素最左侧距离文档左侧的距离 | ||
78 | - * top:元素最顶端距离文档顶端的距离 | ||
79 | - * right:元素最右侧距离文档右侧的距离 | ||
80 | - * bottom:元素最底端距离文档底端的距离 | ||
81 | - * rightIncludeBody:元素最左侧距离文档右侧的距离 | ||
82 | - * bottomIncludeBody:元素最底端距离文档最底部的距离 | 76 | + * Get the left and top offset of the current element |
77 | + * left: the distance between the leftmost element and the left side of the document | ||
78 | + * top: the distance from the top of the element to the top of the document | ||
79 | + * right: the distance from the far right of the element to the right of the document | ||
80 | + * bottom: the distance from the bottom of the element to the bottom of the document | ||
81 | + * rightIncludeBody: the distance between the leftmost element and the right side of the document | ||
82 | + * bottomIncludeBody: the distance from the bottom of the element to the bottom of the document | ||
83 | * | 83 | * |
84 | * @description: | 84 | * @description: |
85 | */ | 85 | */ |
src/utils/encryption/aesEncryption.ts
@@ -14,7 +14,7 @@ export class Encryption { | @@ -14,7 +14,7 @@ export class Encryption { | ||
14 | this.iv = CryptoES.enc.Utf8.parse(iv); | 14 | this.iv = CryptoES.enc.Utf8.parse(iv); |
15 | } | 15 | } |
16 | 16 | ||
17 | - get getOpt(): CryptoES.lib.CipherCfg { | 17 | + get getOptions(): CryptoES.lib.CipherCfg { |
18 | return { | 18 | return { |
19 | mode: CryptoES.mode.CBC as any, | 19 | mode: CryptoES.mode.CBC as any, |
20 | padding: CryptoES.pad.Pkcs7, | 20 | padding: CryptoES.pad.Pkcs7, |
@@ -23,13 +23,11 @@ export class Encryption { | @@ -23,13 +23,11 @@ export class Encryption { | ||
23 | } | 23 | } |
24 | 24 | ||
25 | encryptByAES(str: string) { | 25 | encryptByAES(str: string) { |
26 | - const encrypted = CryptoES.AES.encrypt(str, this.key, this.getOpt); | ||
27 | - return encrypted.toString(); | 26 | + return CryptoES.AES.encrypt(str, this.key, this.getOptions).toString(); |
28 | } | 27 | } |
29 | 28 | ||
30 | decryptByAES(str: string) { | 29 | decryptByAES(str: string) { |
31 | - const decrypted = CryptoES.AES.decrypt(str, this.key, this.getOpt); | ||
32 | - return decrypted.toString(CryptoES.enc.Utf8); | 30 | + return CryptoES.AES.decrypt(str, this.key, this.getOptions).toString(CryptoES.enc.Utf8); |
33 | } | 31 | } |
34 | } | 32 | } |
35 | export default Encryption; | 33 | export default Encryption; |
src/utils/http/axios/index.ts
@@ -4,7 +4,6 @@ | @@ -4,7 +4,6 @@ | ||
4 | import type { AxiosResponse } from 'axios'; | 4 | import type { AxiosResponse } from 'axios'; |
5 | import type { CreateAxiosOptions, RequestOptions, Result } from './types'; | 5 | import type { CreateAxiosOptions, RequestOptions, Result } from './types'; |
6 | import { VAxios } from './Axios'; | 6 | import { VAxios } from './Axios'; |
7 | -import { getToken } from '/@/utils/auth'; | ||
8 | import { AxiosTransform } from './axiosTransform'; | 7 | import { AxiosTransform } from './axiosTransform'; |
9 | 8 | ||
10 | import { checkStatus } from './checkStatus'; | 9 | import { checkStatus } from './checkStatus'; |
@@ -20,6 +19,7 @@ import { errorStore } from '/@/store/modules/error'; | @@ -20,6 +19,7 @@ import { errorStore } from '/@/store/modules/error'; | ||
20 | import { errorResult } from './const'; | 19 | import { errorResult } from './const'; |
21 | import { useI18n } from '/@/hooks/web/useI18n'; | 20 | import { useI18n } from '/@/hooks/web/useI18n'; |
22 | import { createNow, formatRequestDate } from './helper'; | 21 | import { createNow, formatRequestDate } from './helper'; |
22 | +import { userStore } from '/@/store/modules/user'; | ||
23 | 23 | ||
24 | const globSetting = useGlobSetting(); | 24 | const globSetting = useGlobSetting(); |
25 | const prefix = globSetting.urlPrefix; | 25 | const prefix = globSetting.urlPrefix; |
@@ -137,7 +137,7 @@ const transform: AxiosTransform = { | @@ -137,7 +137,7 @@ const transform: AxiosTransform = { | ||
137 | */ | 137 | */ |
138 | requestInterceptors: (config) => { | 138 | requestInterceptors: (config) => { |
139 | // 请求之前处理config | 139 | // 请求之前处理config |
140 | - const token = getToken(); | 140 | + const token = userStore.getTokenState; |
141 | if (token) { | 141 | if (token) { |
142 | // jwt token | 142 | // jwt token |
143 | config.headers.Authorization = token; | 143 | config.headers.Authorization = token; |
src/utils/index.ts
@@ -38,24 +38,6 @@ export function deepMerge<T = any>(src: any = {}, target: any = {}): T { | @@ -38,24 +38,6 @@ export function deepMerge<T = any>(src: any = {}, target: any = {}): T { | ||
38 | return src; | 38 | return src; |
39 | } | 39 | } |
40 | 40 | ||
41 | -/** | ||
42 | - * @description: Deduplication according to the value of an object in the array | ||
43 | - */ | ||
44 | -export function unique<T = any>(arr: T[], key: string): T[] { | ||
45 | - const map = new Map(); | ||
46 | - return arr.filter((item) => { | ||
47 | - const _item = item as any; | ||
48 | - return !map.has(_item[key]) && map.set(_item[key], 1); | ||
49 | - }); | ||
50 | -} | ||
51 | - | ||
52 | -/** | ||
53 | - * @description: es6 array to repeat | ||
54 | - */ | ||
55 | -export function es6Unique<T>(arr: T[]): T[] { | ||
56 | - return Array.from(new Set(arr)); | ||
57 | -} | ||
58 | - | ||
59 | export function openWindow( | 41 | export function openWindow( |
60 | url: string, | 42 | url: string, |
61 | opt?: { target?: TargetContext | string; noopener?: boolean; noreferrer?: boolean } | 43 | opt?: { target?: TargetContext | string; noopener?: boolean; noreferrer?: boolean } |
@@ -80,20 +62,6 @@ export function getDynamicProps<T, U>(props: T): Partial<U> { | @@ -80,20 +62,6 @@ export function getDynamicProps<T, U>(props: T): Partial<U> { | ||
80 | return ret as Partial<U>; | 62 | return ret as Partial<U>; |
81 | } | 63 | } |
82 | 64 | ||
83 | -export function getLastItem<T extends any>(list: T) { | ||
84 | - if (Array.isArray(list)) { | ||
85 | - return list.slice(-1)[0]; | ||
86 | - } | ||
87 | - | ||
88 | - if (list instanceof Set) { | ||
89 | - return Array.from(list).slice(-1)[0]; | ||
90 | - } | ||
91 | - | ||
92 | - if (list instanceof Map) { | ||
93 | - return Array.from(list.values()).slice(-1)[0]; | ||
94 | - } | ||
95 | -} | ||
96 | - | ||
97 | /** | 65 | /** |
98 | * set page Title | 66 | * set page Title |
99 | * @param {*} title :page Title | 67 | * @param {*} title :page Title |