Skip to content

Commit 431dde9

Browse files
committed
fix: Uncaught TypeError
1 parent 9b3c7e4 commit 431dde9

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/components/hooks/useAsyncTip/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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+
1418
const isBusinessEnvelope = (val: any) => {
15-
return !!(val && typeof val === 'object' && Object.hasOwn(val, 'code'))
19+
return !!(val && typeof val === 'object' && hasOwn(val, 'code'))
1620
}
1721

1822
const 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

src/pages/layout/proSecNav/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const PAGE_CANDIDATE_TEMPLATES = [
1818

1919
const pageModules = import.meta?.glob?.('/src/pages/**/*.{js,jsx,ts,tsx}') ?? {}
2020

21+
const hasOwn = (obj, key) => obj != null && Object.hasOwn(obj, key)
22+
2123
const 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
}

0 commit comments

Comments
 (0)