-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types & deepclone): 全局类型声明及深克隆函数
- Loading branch information
Showing
6 changed files
with
93 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,20 @@ | ||
import { MessageApi } from 'ant-design-vue'; | ||
|
||
export interface Options { | ||
label?: string; | ||
value?: string | number; | ||
} | ||
|
||
export interface StrOptions extends Options { | ||
value: string | ||
} | ||
|
||
export interface NumOptions extends Options { | ||
value: number | ||
} | ||
|
||
export type Func = () => void; | ||
|
||
export interface Uncertainty { | ||
[key: string]: any; | ||
} | ||
|
||
export interface UncertaintyStr { | ||
[key: string]: string; | ||
} | ||
|
||
export interface BootStrapOptions { | ||
message: MessageApi | ||
} | ||
message: MessageApi | ||
} | ||
|
||
export interface ReqInterceptor { | ||
onFulfilled: (config: AxiosRequestConfig, options: BootStrapOptions) => void; | ||
onRejected: (error: Error, options: BootStrapOptions) => void; | ||
} | ||
onFulfilled: (config: AxiosRequestConfig, options: BootStrapOptions) => void; | ||
onRejected: (error: Error, options: BootStrapOptions) => void; | ||
} | ||
|
||
export interface ResInterceptor { | ||
onFulfilled: (response: AxiosResponse, options: BootStrapOptions) => void; | ||
onRejected: (error: Error, options: BootStrapOptions) => void; | ||
} | ||
onFulfilled: (response: AxiosResponse, options: BootStrapOptions) => void; | ||
onRejected: (error: Error, options: BootStrapOptions) => void; | ||
} | ||
|
||
export interface Interceptors { | ||
reqInterceptors: ReqInterceptor[]; | ||
resInterceptors: ResInterceptor[]; | ||
} | ||
reqInterceptors: ReqInterceptor[]; | ||
resInterceptors: ResInterceptor[]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 选择项类型 | ||
declare interface Options { | ||
label?: string; | ||
value?: string | number; | ||
} | ||
|
||
// 值是字符串的选择项类型 | ||
declare interface StrOptions extends Options { | ||
value: string; | ||
} | ||
|
||
// 值是数字的选择项类型 | ||
declare interface NumOptions extends Options { | ||
value: number; | ||
} | ||
|
||
// 无返回值的函数类型 | ||
declare type Func = () => void; | ||
|
||
// 不定值的对象类型 | ||
declare interface Uncertainty { | ||
[key: string]: any; | ||
} | ||
|
||
// 定字符串值的对象类型 | ||
declare interface UncertaintyStr { | ||
[key: string]: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* 深度复制 | ||
* @param {*} obj | ||
* @returns object | ||
*/ | ||
export function deepClone(params: Uncertainty): Uncertainty | Uncertainty[] { | ||
if (!params) { | ||
throw new Error('params is empty'); | ||
} | ||
|
||
if (typeof params !== 'object') { | ||
throw new Error('params is not object'); | ||
} | ||
|
||
if (params.constructor === Date) { | ||
return new Date(params); | ||
} | ||
|
||
if (params.constructor === RegExp) { | ||
return new RegExp(params); | ||
} | ||
|
||
const newObject: Uncertainty | Uncertainty[] = Array.isArray(params) ? [] : {}; | ||
|
||
Object.keys(params).forEach((key) => { | ||
if (Object.prototype.hasOwnProperty.call(params, key)) { | ||
// @ts-ignore | ||
newObject[key] = typeof params[key] === 'object' ? deepClone(params[key]) : params[key]; | ||
} | ||
}); | ||
|
||
return newObject; | ||
} | ||
|
||
export const common = { | ||
deepClone, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters