From ac56bfbd6d022f3246c47f041ff6d8802484f040 Mon Sep 17 00:00:00 2001 From: czm <2192718639@qq.com> Date: Tue, 6 Dec 2022 14:33:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf(=E5=B0=9D=E8=AF=95=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E6=AD=A3=E5=BC=8F=E7=8E=AF=E5=A2=83=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=99=BD=E5=B1=8F=E9=97=AE=E9=A2=98):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 13 ++++++++++--- src/components/sideBar/index.tsx | 6 +++--- src/use/useHttp.ts | 8 ++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index e794830..a996343 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,8 @@ { - "extends": ["taro/react","@aaronghx/eslint-config-react"], + "extends": [ + "taro/react", + "@aaronghx/eslint-config-react" + ], "rules": { "no-console": "off", "@typescript-eslint/no-shadow": "off", @@ -9,6 +12,10 @@ "import/first": "off", "react/no-children-prop": "off", "import/no-commonjs": "off", - "react/display-name": "off" + "react/display-name": "off", + "no-use-before-define": "off", + "@typescript-eslint/no-use-before-define": [ + "error" + ] } -} +} \ No newline at end of file diff --git a/src/components/sideBar/index.tsx b/src/components/sideBar/index.tsx index 1ceae27..e03c60b 100644 --- a/src/components/sideBar/index.tsx +++ b/src/components/sideBar/index.tsx @@ -61,7 +61,7 @@ const SideBar = ({ const getClassData = async(id) => { const res = await fetchData({ id }) if (res.success) { - if (res.data?.list.length > 0) { + if (res.data?.list?.length > 0) { res.data.list = [{ id: -1, name: '全部' }, ...res.data.list] } setClassList(() => res.data?.list) @@ -130,8 +130,8 @@ const SideBar = ({ ) })} - 0 ? '90rpx' : '20rpx' }}> - {classList.length > 0 && ( + 0 ? '90rpx' : '20rpx' }}> + {classList?.length > 0 && ( setOpenClass(val)} onSelect={getSelectClass} defaultSelectId={classId} /> diff --git a/src/use/useHttp.ts b/src/use/useHttp.ts index bf9f339..a1eadf5 100644 --- a/src/use/useHttp.ts +++ b/src/use/useHttp.ts @@ -155,7 +155,7 @@ export const useRequest = ( data: stateRef.current.query, } : { - data: options.type?.toUpperCase() == 'FORMDATA' ? qs.stringify(stateRef.current.query) : stateRef.current.query, + data: options.type?.toUpperCase() == 'FORMDATA' ? qs.stringify(stateRef.current?.query) : stateRef.current.query, }), } const result = await Taro.request(q as any) @@ -181,14 +181,14 @@ export const useRequest = ( }) console.log('错误::', msg) } - } + } else { if (statusCode === 401) { removeToken() removeSessionKey() removeUserInfo() login() - } + } else { Taro.showToast({ title: `错误:${showStatus(statusCode)}`, @@ -196,7 +196,7 @@ export const useRequest = ( }) } } - } + } catch (e) { stateRef.current.success = false stateRef.current.error = true