File tree Expand file tree Collapse file tree 3 files changed +58
-4
lines changed
Expand file tree Collapse file tree 3 files changed +58
-4
lines changed Original file line number Diff line number Diff line change 11{
2- "hash" : " 3e39ebdb " ,
3- "browserHash" : " 1ccd550d " ,
2+ "hash" : " 95f455e2 " ,
3+ "browserHash" : " d5235caa " ,
44 "optimized" : {
55 "vue" : {
66 "src" :
" ../../../../node_modules/.pnpm/[email protected] /node_modules/vue/dist/vue.runtime.esm-bundler.js" ,
77 "file" : " vue.js" ,
8- "fileHash" : " 31a5a212 " ,
8+ "fileHash" : " 5d71ae07 " ,
99 "needsInterop" : false
1010 }
1111 },
Original file line number Diff line number Diff line change 1+ /**
2+ * 判断是否为空对象
3+ * @param obj
4+ * @returns {boolean }
5+ */
6+ const isObject = ( obj : any ) : boolean => {
7+ return obj !== null && typeof obj === 'object' && ! Array . isArray ( obj ) ;
8+ } ;
9+ /**
10+ * 深拷贝合并对象
11+ * @param {object } obj1 外部的参数对象
12+ * @param {object } obj2 默认参数对象
13+ * @returns {Object }
14+ */
15+ export const mergeObejct = ( obj1 : any , obj2 : Object ) : Object => {
16+ if ( ! isObject ( obj1 ) ) {
17+ return mergeObejct ( { } , obj2 ) ;
18+ }
19+ if ( ! isObject ( obj2 ) ) {
20+ return mergeObejct ( { } , obj1 ) ;
21+ }
22+ // 定义一个以默认值为基础的新对象
23+ let newObj = Object . assign ( { } , obj2 ) ;
24+ // 遍历传参对象
25+ Object . keys ( obj1 ) . forEach ( function ( key ) {
26+ let val = obj1 [ key ] ;
27+ if ( key === '__proto__' || key === 'constructor' ) {
28+ return ;
29+ }
30+ if ( val === null ) {
31+ return ;
32+ }
33+ // 如果传参对象中的值为对象,则递归调用
34+ if ( isObject ( val ) && isObject ( newObj [ key ] ) ) {
35+ newObj [ key ] = mergeObejct ( val , newObj [ key ] ) ;
36+ } else {
37+ newObj [ key ] = val ;
38+ }
39+ } ) ;
40+ return newObj ;
41+ } ;
Original file line number Diff line number Diff line change 1- export const randomString = ( ) => { } ;
1+ /**
2+ * 随机生成字符串
3+ * @param {number } length
4+ * @returns {string }
5+ */
6+ export const randomString = ( length : number ) : string => {
7+ let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz123456789' ;
8+ let charsLen = chars . length ;
9+ let resultStr = '' ;
10+ for ( let i = 0 ; i < length ; i ++ ) {
11+ resultStr += chars . charAt ( Math . floor ( Math . random ( ) * charsLen ) ) ;
12+ }
13+ return resultStr ;
14+ } ;
You can’t perform that action at this time.
0 commit comments