File tree Expand file tree Collapse file tree
components/hooks/useAsyncTip Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,18 +11,22 @@ type UseAsyncTipOptions = {
1111 onError ?: TipHandler
1212}
1313
14+ const hasOwn = ( obj : any , prop : PropertyKey ) => {
15+ return obj != null && Object . hasOwn ( obj , prop )
16+ }
17+
1418const isBusinessEnvelope = ( val : any ) => {
15- return ! ! ( val && typeof val === 'object' && Object . hasOwn ( val , 'code' ) )
19+ return ! ! ( val && typeof val === 'object' && hasOwn ( val , 'code' ) )
1620}
1721
1822const isOk = ( res : any ) => {
1923 if ( ! res || typeof res !== 'object' ) return ! ! res
2024 // 兼容 { success: true/false }
21- if ( Object . hasOwn ( res , 'success' ) ) return ! ! res . success
25+ if ( hasOwn ( res , 'success' ) ) return ! ! res . success
2226 // 兼容 { code: 0/200 }
2327 if ( isBusinessEnvelope ( res ) ) return res . code === 0 || res . code === 200
2428 // 兼容 axios error 分支可能返回 { status: 4xx/5xx, data: {...} }
25- if ( Object . hasOwn ( res , 'status' ) ) return res . status >= 200 && res . status < 300
29+ if ( hasOwn ( res , 'status' ) ) return res . status >= 200 && res . status < 300
2630 return true
2731}
2832
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ const PAGE_CANDIDATE_TEMPLATES = [
1818
1919const pageModules = import . meta?. glob ?. ( '/src/pages/**/*.{js,jsx,ts,tsx}' ) ?? { }
2020
21+ const hasOwn = ( obj , key ) => obj != null && Object . hasOwn ( obj , key )
22+
2123const resolvePageModuleKey = ( ( ) => {
2224 const cache = new Map ( )
2325
@@ -43,7 +45,7 @@ const resolvePageModuleKey = (() => {
4345 if ( cache . has ( pathKey ) ) return cache . get ( pathKey )
4446
4547 for ( const c of makeCandidates ( pathKey ) ) {
46- if ( Object . hasOwn ( pageModules , c ) ) {
48+ if ( hasOwn ( pageModules , c ) ) {
4749 cache . set ( pathKey , c )
4850 return c
4951 }
@@ -52,7 +54,7 @@ const resolvePageModuleKey = (() => {
5254 if ( pathKey . includes ( ':' ) ) {
5355 const paramPath = paramify ( pathKey )
5456 for ( const c of makeCandidates ( paramPath ) ) {
55- if ( Object . hasOwn ( pageModules , c ) ) {
57+ if ( hasOwn ( pageModules , c ) ) {
5658 cache . set ( pathKey , c )
5759 return c
5860 }
You can’t perform that action at this time.
0 commit comments