23 changed files with 46 additions and 521 deletions
@ -1,6 +0,0 @@ |
|||||
import { defineComponent } from 'vue'; |
|
||||
|
|
||||
export type Component<T extends any = any> = |
|
||||
| ReturnType<typeof defineComponent> |
|
||||
| (() => Promise<typeof import('*.vue')>) |
|
||||
| (() => Promise<T>); |
|
||||
@ -1,176 +0,0 @@ |
|||||
import type { VNodeChild } from 'vue'; |
|
||||
|
|
||||
export function convertToUnit( |
|
||||
str: string | number | null | undefined, |
|
||||
unit = 'px' |
|
||||
): string | undefined { |
|
||||
if (str == null || str === '') { |
|
||||
return undefined; |
|
||||
} else if (isNaN(+str!)) { |
|
||||
return String(str); |
|
||||
} else { |
|
||||
return `${Number(str)}${unit}`; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Camelize a hyphen-delimited string. |
|
||||
*/ |
|
||||
const camelizeRE = /-(\w)/g; |
|
||||
export const camelize = (str: string): string => { |
|
||||
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : '')); |
|
||||
}; |
|
||||
|
|
||||
export function wrapInArray<T>(v: T | T[] | null | undefined): T[] { |
|
||||
return v != null ? (Array.isArray(v) ? v : [v]) : []; |
|
||||
} |
|
||||
|
|
||||
const pattern = { |
|
||||
styleList: /;(?![^(]*\))/g, |
|
||||
styleProp: /:(.*)/, |
|
||||
} as const; |
|
||||
|
|
||||
function parseStyle(style: string) { |
|
||||
const styleMap: Recordable = {}; |
|
||||
|
|
||||
for (const s of style.split(pattern.styleList)) { |
|
||||
let [key, val] = s.split(pattern.styleProp); |
|
||||
key = key.trim(); |
|
||||
if (!key) { |
|
||||
continue; |
|
||||
} |
|
||||
// May be undefined if the `key: value` pair is incomplete.
|
|
||||
if (typeof val === 'string') { |
|
||||
val = val.trim(); |
|
||||
} |
|
||||
styleMap[camelize(key)] = val; |
|
||||
} |
|
||||
|
|
||||
return styleMap; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Intelligently merges data for createElement. |
|
||||
* Merges arguments left to right, preferring the right argument. |
|
||||
* Returns new VNodeData object. |
|
||||
*/ |
|
||||
export function mergeData(...vNodeData: VNodeChild[]): VNodeChild; |
|
||||
export function mergeData(...args: any[]): VNodeChild { |
|
||||
const mergeTarget: any = {}; |
|
||||
let i: number = args.length; |
|
||||
let prop: string; |
|
||||
|
|
||||
// Allow for variadic argument length.
|
|
||||
while (i--) { |
|
||||
// Iterate through the data properties and execute merge strategies
|
|
||||
// Object.keys eliminates need for hasOwnProperty call
|
|
||||
for (prop of Object.keys(args[i])) { |
|
||||
switch (prop) { |
|
||||
// Array merge strategy (array concatenation)
|
|
||||
case 'class': |
|
||||
case 'directives': |
|
||||
if (args[i][prop]) { |
|
||||
mergeTarget[prop] = mergeClasses(mergeTarget[prop], args[i][prop]); |
|
||||
} |
|
||||
break; |
|
||||
case 'style': |
|
||||
if (args[i][prop]) { |
|
||||
mergeTarget[prop] = mergeStyles(mergeTarget[prop], args[i][prop]); |
|
||||
} |
|
||||
break; |
|
||||
// Space delimited string concatenation strategy
|
|
||||
case 'staticClass': |
|
||||
if (!args[i][prop]) { |
|
||||
break; |
|
||||
} |
|
||||
if (mergeTarget[prop] === undefined) { |
|
||||
mergeTarget[prop] = ''; |
|
||||
} |
|
||||
if (mergeTarget[prop]) { |
|
||||
// Not an empty string, so concatenate
|
|
||||
mergeTarget[prop] += ' '; |
|
||||
} |
|
||||
mergeTarget[prop] += args[i][prop].trim(); |
|
||||
break; |
|
||||
// Object, the properties of which to merge via array merge strategy (array concatenation).
|
|
||||
// Callback merge strategy merges callbacks to the beginning of the array,
|
|
||||
// so that the last defined callback will be invoked first.
|
|
||||
// This is done since to mimic how Object.assign merging
|
|
||||
// uses the last given value to assign.
|
|
||||
case 'on': |
|
||||
case 'nativeOn': |
|
||||
if (args[i][prop]) { |
|
||||
mergeTarget[prop] = mergeListeners(mergeTarget[prop], args[i][prop]); |
|
||||
} |
|
||||
break; |
|
||||
// Object merge strategy
|
|
||||
case 'attrs': |
|
||||
case 'props': |
|
||||
case 'domProps': |
|
||||
case 'scopedSlots': |
|
||||
case 'staticStyle': |
|
||||
case 'hook': |
|
||||
case 'transition': |
|
||||
if (!args[i][prop]) { |
|
||||
break; |
|
||||
} |
|
||||
if (!mergeTarget[prop]) { |
|
||||
mergeTarget[prop] = {}; |
|
||||
} |
|
||||
mergeTarget[prop] = { ...args[i][prop], ...mergeTarget[prop] }; |
|
||||
break; |
|
||||
// Reassignment strategy (no merge)
|
|
||||
default: |
|
||||
// slot, key, ref, tag, show, keepAlive
|
|
||||
if (!mergeTarget[prop]) { |
|
||||
mergeTarget[prop] = args[i][prop]; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return mergeTarget; |
|
||||
} |
|
||||
|
|
||||
export function mergeStyles( |
|
||||
target: undefined | string | object[] | object, |
|
||||
source: undefined | string | object[] | object |
|
||||
) { |
|
||||
if (!target) return source; |
|
||||
if (!source) return target; |
|
||||
|
|
||||
target = wrapInArray(typeof target === 'string' ? parseStyle(target) : target); |
|
||||
|
|
||||
return (target as object[]).concat(typeof source === 'string' ? parseStyle(source) : source); |
|
||||
} |
|
||||
|
|
||||
export function mergeClasses(target: any, source: any) { |
|
||||
if (!source) return target; |
|
||||
if (!target) return source; |
|
||||
|
|
||||
return target ? wrapInArray(target).concat(source) : source; |
|
||||
} |
|
||||
|
|
||||
export function mergeListeners( |
|
||||
target: Indexable<Function | Function[]> | undefined, |
|
||||
source: Indexable<Function | Function[]> | undefined |
|
||||
) { |
|
||||
if (!target) return source; |
|
||||
if (!source) return target; |
|
||||
|
|
||||
let event: string; |
|
||||
|
|
||||
for (event of Object.keys(source)) { |
|
||||
// Concat function to array of functions if callback present.
|
|
||||
if (target[event]) { |
|
||||
// Insert current iteration data in beginning of merged array.
|
|
||||
target[event] = wrapInArray(target[event]); |
|
||||
(target[event] as Function[]).push(...wrapInArray(source[event])); |
|
||||
} else { |
|
||||
// Straight assign.
|
|
||||
target[event] = source[event]; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return target; |
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
import { customRef } from 'vue'; |
|
||||
|
|
||||
export function useDebouncedRef<T = any>(value: T, delay = 100) { |
|
||||
let timeout: TimeoutHandle; |
|
||||
return customRef((track, trigger) => { |
|
||||
return { |
|
||||
get() { |
|
||||
track(); |
|
||||
return value; |
|
||||
}, |
|
||||
set(newValue: T) { |
|
||||
clearTimeout(timeout); |
|
||||
timeout = setTimeout(() => { |
|
||||
value = newValue; |
|
||||
trigger(); |
|
||||
}, delay); |
|
||||
}, |
|
||||
}; |
|
||||
}); |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
import { watch } from 'vue'; |
|
||||
import { isFunction } from '/@/utils/is'; |
|
||||
|
|
||||
export function useEffect<T extends any = any>( |
|
||||
effectHandler: (deps: T[], prevDeps?: T[]) => () => void, |
|
||||
dependencies: T[] |
|
||||
) { |
|
||||
return watch( |
|
||||
dependencies, |
|
||||
(changedDependencies, prevDependencies, onCleanUp) => { |
|
||||
const effectCleaner = effectHandler(changedDependencies, prevDependencies); |
|
||||
if (isFunction(effectCleaner)) { |
|
||||
onCleanUp(effectCleaner); |
|
||||
} |
|
||||
}, |
|
||||
{ immediate: true, deep: true } |
|
||||
); |
|
||||
} |
|
||||
@ -1,58 +0,0 @@ |
|||||
import { isObject } from '@vue/shared'; |
|
||||
import { reactive, Ref, ref, readonly } from 'vue'; |
|
||||
import { isFunction } from '/@/utils/is'; |
|
||||
|
|
||||
type State<T> = ((s: T) => T) | T; |
|
||||
type Dispatch<T> = (t: T) => void; |
|
||||
|
|
||||
type DispatchState<T> = Dispatch<State<T>>; |
|
||||
|
|
||||
type ResultState<T> = Readonly<Ref<T>>; |
|
||||
|
|
||||
export function useState<T extends undefined>( |
|
||||
initialState: (() => T) | T |
|
||||
): [ResultState<T>, DispatchState<T>]; |
|
||||
|
|
||||
export function useState<T extends null>( |
|
||||
initialState: (() => T) | T |
|
||||
): [ResultState<T>, DispatchState<T>]; |
|
||||
|
|
||||
export function useState<T extends boolean>( |
|
||||
initialState: (() => T) | T |
|
||||
): [ResultState<boolean>, DispatchState<boolean>]; |
|
||||
|
|
||||
export function useState<T extends string>( |
|
||||
initialState: (() => T) | T |
|
||||
): [ResultState<string>, DispatchState<string>]; |
|
||||
|
|
||||
export function useState<T extends number>( |
|
||||
initialState: (() => T) | T |
|
||||
): [ResultState<number>, DispatchState<number>]; |
|
||||
|
|
||||
export function useState<T extends object>( |
|
||||
initialState: (() => T) | T |
|
||||
): [Readonly<T>, DispatchState<T>]; |
|
||||
|
|
||||
export function useState<T extends any>( |
|
||||
initialState: (() => T) | T |
|
||||
): [Readonly<T>, DispatchState<T>]; |
|
||||
|
|
||||
export function useState<T>(initialState: (() => T) | T): [ResultState<T> | T, DispatchState<T>] { |
|
||||
if (isFunction(initialState)) { |
|
||||
initialState = (initialState as Fn)(); |
|
||||
} |
|
||||
|
|
||||
if (isObject(initialState)) { |
|
||||
const state = reactive({ data: initialState }) as any; |
|
||||
const setState = (newState: T) => { |
|
||||
state.data = newState; |
|
||||
}; |
|
||||
return [readonly(state), setState]; |
|
||||
} else { |
|
||||
const state = ref(initialState) as any; |
|
||||
const setState = (newState: T) => { |
|
||||
state.value = newState; |
|
||||
}; |
|
||||
return [readonly(state), setState]; |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
import { RouterLink, RouterView } from 'vue-router'; |
|
||||
|
|
||||
import { Button } from '/@/components/Button'; |
|
||||
import { Col, Row } from 'ant-design-vue'; |
|
||||
|
|
||||
declare global { |
|
||||
interface __VLS_GlobalComponents { |
|
||||
RouterLink: typeof RouterLink; |
|
||||
RouterView: typeof RouterView; |
|
||||
'a-button': typeof Button; |
|
||||
'a-col': typeof Col; |
|
||||
'a-row': typeof Row; |
|
||||
} |
|
||||
} |
|
||||
@ -1,9 +0,0 @@ |
|||||
import { userStore } from '/@/store/modules/user'; |
|
||||
|
|
||||
/** |
|
||||
* @description: Get token |
|
||||
* @return jwt token |
|
||||
*/ |
|
||||
export function getToken(): string { |
|
||||
return userStore.getTokenState; |
|
||||
} |
|
||||
@ -1,78 +0,0 @@ |
|||||
import { DEFAULT_CACHE_TIME } from '../../settings/encryptionSetting'; |
|
||||
import { getStorageShortName } from '/@/utils/helper/envHelper'; |
|
||||
import { cacheCipher } from '/@/settings/encryptionSetting'; |
|
||||
import Encryption from '/@/utils/encryption/aesEncryption'; |
|
||||
|
|
||||
export default class WebCookie { |
|
||||
private encryption: Encryption; |
|
||||
private hasEncrypt: boolean; |
|
||||
|
|
||||
constructor(hasEncrypt = true, key = cacheCipher.key, iv = cacheCipher.iv) { |
|
||||
const encryption = new Encryption({ key, iv }); |
|
||||
this.encryption = encryption; |
|
||||
this.hasEncrypt = hasEncrypt; |
|
||||
} |
|
||||
|
|
||||
private getKey(key: string) { |
|
||||
return `${getStorageShortName()}${key}`.toUpperCase(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Add cookie |
|
||||
* @param name cookie key |
|
||||
* @param value cookie value |
|
||||
* @param expire |
|
||||
* If the expiration time is not set, the default management browser will automatically delete |
|
||||
* e.g: |
|
||||
* cookieData.set('name','value',) |
|
||||
*/ |
|
||||
setCookie(key: string, value: any, expire: number | null = DEFAULT_CACHE_TIME) { |
|
||||
value = this.hasEncrypt ? this.encryption.encryptByAES(JSON.stringify(value)) : value; |
|
||||
document.cookie = this.getKey(key) + '=' + value + '; Max-Age=' + expire; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Get the cook value according to the key |
|
||||
* @param key cookie key |
|
||||
*/ |
|
||||
getCookie(key: string) { |
|
||||
const arr = document.cookie.split('; '); |
|
||||
for (let i = 0; i < arr.length; i++) { |
|
||||
const arr2 = arr[i].split('='); |
|
||||
if (arr2[0] === this.getKey(key)) { |
|
||||
let message: any = null; |
|
||||
const str = arr2[1]; |
|
||||
if (this.hasEncrypt && str) { |
|
||||
message = this.encryption.decryptByAES(str); |
|
||||
try { |
|
||||
return JSON.parse(message); |
|
||||
} catch (e) { |
|
||||
return str; |
|
||||
} |
|
||||
} |
|
||||
return str; |
|
||||
} |
|
||||
} |
|
||||
return ''; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Delete cookie based on cookie key |
|
||||
* @param key cookie key |
|
||||
*/ |
|
||||
removeCookie(key: string) { |
|
||||
this.setCookie(key, 1, -1); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* clear cookie |
|
||||
*/ |
|
||||
clearCookie(): void { |
|
||||
const keys = document.cookie.match(/[^ =;]+(?==)/g); |
|
||||
if (keys) { |
|
||||
for (let i = keys.length; i--; ) { |
|
||||
document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue