diff --git a/src/components/state-view/index.module.scss b/src/components/state-view/index.module.scss
new file mode 100644
index 0000000..94bef01
--- /dev/null
+++ b/src/components/state-view/index.module.scss
@@ -0,0 +1,19 @@
+.stateView {
+ margin-top: 80px;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+}
+
+.retryBtn {
+ margin-top: 40px;
+ width: 240px;
+ height: 80px;
+ background: $color-primary;
+ border-radius: 40px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ color: #ffffff;
+ font-size: 28px;
+}
diff --git a/src/components/state-view/index.tsx b/src/components/state-view/index.tsx
new file mode 100644
index 0000000..39c2048
--- /dev/null
+++ b/src/components/state-view/index.tsx
@@ -0,0 +1,30 @@
+import { View, Text } from '@tarojs/components'
+import { Empty } from '@/components/empty'
+import styles from './index.module.scss'
+
+interface Props {
+ status: 'error'
+ mode?: 'list' | 'wifi' | 'error' | 'message'
+ text?: string
+ onRetry?: () => void
+ retryText?: string
+}
+
+export function StateView({
+ status,
+ mode = 'wifi',
+ text = '加载失败,请检查网络',
+ onRetry,
+ retryText = '重试'
+}: Props) {
+ return (
+
+
+ {onRetry && (
+
+ {retryText}
+
+ )}
+
+ )
+}
diff --git a/src/pages/device/detail.module.scss b/src/pages/device/detail.module.scss
index 2e4b301..f47a89c 100644
--- a/src/pages/device/detail.module.scss
+++ b/src/pages/device/detail.module.scss
@@ -10,18 +10,6 @@
align-items: center;
}
-.retryBtn {
- margin-top: 40px;
- width: 240px;
- height: 80px;
- background: $color-primary;
- border-radius: 40px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
-}
-
.heartCard {
margin: 24px;
padding: 32px;
diff --git a/src/pages/device/detail.tsx b/src/pages/device/detail.tsx
index 68e074b..e5fe0e0 100644
--- a/src/pages/device/detail.tsx
+++ b/src/pages/device/detail.tsx
@@ -3,7 +3,7 @@ import Taro, { useRouter, useDidShow, useDidHide } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { Navbar } from '@/components/navbar'
import { Loading } from '@/components/loading'
-import { Empty } from '@/components/empty'
+import { StateView } from '@/components/state-view'
import { VitalWave } from '@/components/vital-wave'
import { getVitalSigns, getHeartRateHistory, type VitalSigns } from '@/api/device'
import { MOVE_STATE_MAP, BODY_STATUS_MAP, ONBED_STATUS_MAP, type DeviceModel } from '@/constants/enums'
@@ -108,10 +108,7 @@ export default function Detail() {
{loading ? (
) : loadError ? (
-
-
- 重试
-
+
) : (
<>
diff --git a/src/pages/device/index.module.scss b/src/pages/device/index.module.scss
index eeaa140..39d98d0 100644
--- a/src/pages/device/index.module.scss
+++ b/src/pages/device/index.module.scss
@@ -32,19 +32,6 @@
align-items: center;
}
-.retryBtn {
- margin-top: 40px;
- width: 240px;
- height: 80px;
- background: $color-primary;
- border-radius: 40px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
- font-size: 28px;
-}
-
.grid {
display: flex;
flex-wrap: wrap;
diff --git a/src/pages/device/index.tsx b/src/pages/device/index.tsx
index fe5ddd2..807b051 100644
--- a/src/pages/device/index.tsx
+++ b/src/pages/device/index.tsx
@@ -5,7 +5,7 @@ import { useAppSelector, useAppDispatch } from '@/store/hooks'
import { setDeviceList, type Device } from '@/store/deviceSlice'
import { Navbar } from '@/components/navbar'
import { Loading } from '@/components/loading'
-import { Empty } from '@/components/empty'
+import { StateView } from '@/components/state-view'
import { getDeviceList } from '@/api/device'
import { DEVICE_ICON_MAP, type DeviceModel } from '@/constants/enums'
import { ROUTES } from '@/constants/routes'
@@ -62,15 +62,9 @@ export default function DeviceList() {
{loading ? (
) : loadError ? (
-
-
- 重试
-
+
) : deviceList.length === 0 ? (
-
-
- 添加设备
-
+
) : (
{deviceList.map((device) => (
diff --git a/src/pages/index/index.module.scss b/src/pages/index/index.module.scss
index 6222c1d..1023c43 100644
--- a/src/pages/index/index.module.scss
+++ b/src/pages/index/index.module.scss
@@ -11,19 +11,6 @@
align-items: center;
}
-.retryBtn {
- margin-top: 40px;
- width: 240px;
- height: 80px;
- background: $color-primary;
- border-radius: 40px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
- font-size: 28px;
-}
-
// ===== 家庭圈入口 =====
.familyEntry {
margin: 24px;
diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx
index e3dd71a..c647f2b 100644
--- a/src/pages/index/index.tsx
+++ b/src/pages/index/index.tsx
@@ -4,6 +4,7 @@ import { View, Text } from '@tarojs/components'
import { Navbar } from '@/components/navbar'
import { Loading } from '@/components/loading'
import { Empty } from '@/components/empty'
+import { StateView } from '@/components/state-view'
import { getEventList, type EventItem } from '@/api/event'
import { ROUTES } from '@/constants/routes'
import { navigateTo } from '@/utils/navigation'
@@ -46,10 +47,7 @@ export default function Index() {
{loading ? (
) : loadError ? (
-
-
- 重试
-
+
) : (
<>
diff --git a/src/pages/scene/select.module.scss b/src/pages/scene/select.module.scss
index 92ca186..d01843c 100644
--- a/src/pages/scene/select.module.scss
+++ b/src/pages/scene/select.module.scss
@@ -10,18 +10,6 @@
align-items: center;
}
-.retryBtn {
- margin-top: 40px;
- width: 240px;
- height: 80px;
- background: $color-primary;
- border-radius: 40px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #ffffff;
-}
-
.list { margin-top: 20px; }
.item {
diff --git a/src/pages/scene/select.tsx b/src/pages/scene/select.tsx
index 7811eff..94fe370 100644
--- a/src/pages/scene/select.tsx
+++ b/src/pages/scene/select.tsx
@@ -5,6 +5,7 @@ import { setScene, type Scene } from '@/store/sceneSlice'
import { Navbar } from '@/components/navbar'
import { Loading } from '@/components/loading'
import { Empty } from '@/components/empty'
+import { StateView } from '@/components/state-view'
import { getSceneList } from '@/api/scene'
import { navigateBack } from '@/utils/navigation'
import styles from './select.module.scss'
@@ -43,10 +44,7 @@ export default function SceneSelect() {
{loading ? (
) : loadError ? (
-
-
- 重试
-
+
) : list.length === 0 ? (
) : (