feat(首页): 添加离线模式提示和网络状态检测
检测网络状态并在离线时显示提示横幅 修改背景样式增强视觉效果 离线状态下阻止预约跳转
Showing
1 changed file
with
47 additions
and
3 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-06-21 10:23:09 | 2 | * @Date: 2023-06-21 10:23:09 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2026-01-13 15:35:17 | 4 | + * @LastEditTime: 2026-01-13 15:47:00 |
| 5 | * @FilePath: /xyxBooking-weapp/src/pages/index/index.vue | 5 | * @FilePath: /xyxBooking-weapp/src/pages/index/index.vue |
| 6 | * @Description: 预约页首页 | 6 | * @Description: 预约页首页 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | <view class="index-page"> | 9 | <view class="index-page"> |
| 10 | + <view v-if="is_offline" class="offline-banner mx-6 mt-4 rounded-xl px-4 py-3"> | ||
| 11 | + <view class="flex items-center"> | ||
| 12 | + <IconFont name="tips" size="18" /> | ||
| 13 | + <text class="ml-2 font-medium">离线模式</text> | ||
| 14 | + </view> | ||
| 15 | + <view class="mt-1 text-sm opacity-80">网络不佳,已启用本地显示</view> | ||
| 16 | + </view> | ||
| 10 | <view class="index-content"> | 17 | <view class="index-content"> |
| 11 | <view style="height: 28vh;"> | 18 | <view style="height: 28vh;"> |
| 12 | <swiper class="my-swipe" :autoplay="true" :interval="3000" indicator-dots indicator-color="white" :circular="true"> | 19 | <swiper class="my-swipe" :autoplay="true" :interval="3000" indicator-dots indicator-color="white" :circular="true"> |
| ... | @@ -45,17 +52,38 @@ | ... | @@ -45,17 +52,38 @@ |
| 45 | </template> | 52 | </template> |
| 46 | 53 | ||
| 47 | <script setup> | 54 | <script setup> |
| 48 | -import Taro, { useShareAppMessage } from '@tarojs/taro' | 55 | +import Taro, { useDidShow, useShareAppMessage } from '@tarojs/taro' |
| 56 | +import { IconFont } from '@nutui/icons-vue-taro' | ||
| 49 | // import { showSuccessToast, showFailToast } from 'vant'; // NutUI 或 Taro API | 57 | // import { showSuccessToast, showFailToast } from 'vant'; // NutUI 或 Taro API |
| 58 | +import { ref } from 'vue' | ||
| 50 | import { useGo } from '@/hooks/useGo' | 59 | import { useGo } from '@/hooks/useGo' |
| 60 | +import { get_network_type, is_usable_network } from '@/utils/network' | ||
| 51 | import icon_1 from '@/assets/images/立即预约@2x.png' | 61 | import icon_1 from '@/assets/images/立即预约@2x.png' |
| 52 | import icon_3 from '@/assets/images/首页02@2x.png' | 62 | import icon_3 from '@/assets/images/首页02@2x.png' |
| 53 | import icon_4 from '@/assets/images/二维码icon.png' | 63 | import icon_4 from '@/assets/images/二维码icon.png' |
| 54 | import icon_5 from '@/assets/images/我的01@2x.png' | 64 | import icon_5 from '@/assets/images/我的01@2x.png' |
| 55 | 65 | ||
| 56 | const go = useGo(); | 66 | const go = useGo(); |
| 67 | +const is_offline = ref(false) | ||
| 68 | + | ||
| 69 | +const refresh_offline_state = async () => { | ||
| 70 | + const network_type = await get_network_type() | ||
| 71 | + is_offline.value = !is_usable_network(network_type) | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +useDidShow(() => { | ||
| 75 | + refresh_offline_state() | ||
| 76 | +}) | ||
| 57 | 77 | ||
| 58 | const toBooking = () => { // 跳转到预约须知 | 78 | const toBooking = () => { // 跳转到预约须知 |
| 79 | + // 如果是离线模式,不跳转 | ||
| 80 | + if (is_offline.value) { | ||
| 81 | + Taro.showToast({ | ||
| 82 | + title: '当前为离线模式,无法预约', | ||
| 83 | + icon: 'none' | ||
| 84 | + }) | ||
| 85 | + return | ||
| 86 | + } | ||
| 59 | go('/notice'); | 87 | go('/notice'); |
| 60 | } | 88 | } |
| 61 | const toCode = () => { // 跳转到预约码 | 89 | const toCode = () => { // 跳转到预约码 |
| ... | @@ -82,10 +110,26 @@ useShareAppMessage(() => { | ... | @@ -82,10 +110,26 @@ useShareAppMessage(() => { |
| 82 | .index-page { | 110 | .index-page { |
| 83 | position: relative; | 111 | position: relative; |
| 84 | min-height: 100vh; | 112 | min-height: 100vh; |
| 85 | - background-image: url('https://cdn.ipadbiz.cn/xys/booking/bg.jpg?imageMogr2/thumbnail/200x/strip/quality/50'); | 113 | + background-color: #F3EEE3; |
| 114 | + background-image: | ||
| 115 | + linear-gradient(180deg, rgba(166, 121, 57, 0.10) 0%, rgba(255, 255, 255, 0.90) 60%, rgba(243, 238, 227, 1) 100%), | ||
| 116 | + url('https://cdn.ipadbiz.cn/xys/booking/bg.jpg?imageMogr2/thumbnail/200x/strip/quality/50'); | ||
| 86 | background-repeat: no-repeat; | 117 | background-repeat: no-repeat; |
| 87 | background-position: center; | 118 | background-position: center; |
| 88 | background-size: cover; /* 确保背景覆盖 */ | 119 | background-size: cover; /* 确保背景覆盖 */ |
| 120 | + | ||
| 121 | + .offline-banner { | ||
| 122 | + position: absolute; | ||
| 123 | + top: 24rpx; | ||
| 124 | + left: 24rpx; | ||
| 125 | + right: 24rpx; | ||
| 126 | + z-index: 10; | ||
| 127 | + background: rgba(255, 255, 255, 0.88); | ||
| 128 | + color: #A67939; | ||
| 129 | + border: 2rpx solid rgba(166, 121, 57, 0.25); | ||
| 130 | + box-shadow: 0 12rpx 30rpx rgba(166, 121, 57, 0.12); | ||
| 131 | + backdrop-filter: blur(6px); | ||
| 132 | + } | ||
| 89 | .index-content { | 133 | .index-content { |
| 90 | height: calc(100vh - 134rpx); | 134 | height: calc(100vh - 134rpx); |
| 91 | .index-control { | 135 | .index-control { | ... | ... |
-
Please register or login to post a comment