index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="home-page">
  3. <!-- 搜索栏 -->
  4. <view class="search-wrapper">
  5. <!-- <view class="location-box" @click="onLocationClick">
  6. <text class="location-text">昆明市</text>
  7. <uni-icons type="bottom" size="10" color="#fff"></uni-icons>
  8. </view> -->
  9. <view class="search-bar" @click="onSearchClick">
  10. <uni-icons type="search" size="16" color="#999"></uni-icons>
  11. <text class="search-placeholder">搜索宠物名/主人</text>
  12. </view>
  13. </view>
  14. <!-- 轮播图 -->
  15. <view class="banner-swipe-wrapper">
  16. <swiper class="my-swipe" :autoplay="true" :interval="3000" :circular="true" indicator-dots
  17. indicator-active-color="#ffffff" indicator-color="rgba(255,255,255,0.5)">
  18. <swiper-item v-for="(image, index) in bannerImages" :key="index">
  19. <image :src="image" class="swipe-img" mode="aspectFill"></image>
  20. </swiper-item>
  21. </swiper>
  22. </view>
  23. <!-- 系统通知栏 -->
  24. <view class="notice-section">
  25. <view class="notice-bar">
  26. <uni-icons type="sound" size="14" color="#ed6a0c"></uni-icons>
  27. <scroll-view scroll-x class="notice-scroll" :show-scrollbar="false">
  28. <text class="notice-text">【重要通知】尊敬的用户,由于近期接送需求激增,请各位宠主尽量提前24小时进行服务预约,感谢您的理解与配合!</text>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. <!-- 重构后的对称服务栅格布局 -->
  33. <view class="new-service-grid" v-if="services.length >= 3">
  34. <!-- 顶部主打服务 (Hero Card) -->
  35. <view class="hero-card" @click="goToDetail(services[0])">
  36. <view class="card-content">
  37. <text class="card-title">{{ services[0].name }}</text>
  38. <text class="card-desc">{{ services[0].remark }}</text>
  39. </view>
  40. <image :src="services[0].iconUrl" class="hero-icon" mode="aspectFit"></image>
  41. </view>
  42. <!-- 底部双列服务 (Secondary Cards) -->
  43. <view class="card-row">
  44. <view class="sub-card" v-for="(item, index) in services.slice(1, 3)" :key="index"
  45. @click="goToDetail(item)">
  46. <view class="card-content">
  47. <text class="sub-title">{{ item.name }}</text>
  48. <text class="sub-desc">{{ item.remark }}</text>
  49. </view>
  50. <image :src="item.iconUrl" class="sub-icon" mode="aspectFit"></image>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- 全部服务列表 -->
  55. <view class="section-header">
  56. <text class="section-title">全部服务</text>
  57. <view class="more-link" @click="goToServices">
  58. <text>查看全部</text>
  59. <uni-icons type="right" size="12" color="#999"></uni-icons>
  60. </view>
  61. </view>
  62. <view class="recommend-list">
  63. <view class="recommend-card" v-for="(item, index) in services.slice(3, 8)" :key="index"
  64. @click="goToDetail(item)">
  65. <image :src="item.iconUrl" class="item-img" mode="aspectFill"></image>
  66. <view class="item-info">
  67. <view class="item-header">
  68. <text class="item-title">{{ item.name }}</text>
  69. </view>
  70. <text class="item-desc">{{ item.remark }}</text>
  71. <view class="item-bottom">
  72. <text class="tag" v-if="serviceModeEnum[item.mode]">{{ serviceModeEnum[item.mode] }}</text>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <custom-tabbar></custom-tabbar>
  78. </view>
  79. </template>
  80. <script setup>
  81. import { ref } from 'vue'
  82. import { onShow } from '@dcloudio/uni-app'
  83. import customTabbar from '@/components/custom-tabbar/index.vue'
  84. import { listAllService } from '@/api/service/list'
  85. import { getAppSetting } from '@/api/system/appSetting'
  86. import serviceModeEnum from '@/json/serviceMode.json'
  87. const bannerImages = ref([])
  88. const services = ref([])
  89. const fetchServices = async () => {
  90. try {
  91. // @Author: Antigravity
  92. const res = await listAllService()
  93. // 兼容直接返回数组或返回包装对象的情况
  94. services.value = res.rows || res || []
  95. } catch (error) {
  96. console.error("Failed to fetch services", error)
  97. }
  98. }
  99. // 获取首页轮播图配置 @Author: Antigravity
  100. const fetchBanners = async () => {
  101. try {
  102. // 获取“好萌友”端配置 (ID 2) @Author: Antigravity
  103. const res = await getAppSetting(2)
  104. const data = res.data || res
  105. if (data && data.homeBannerUrls) {
  106. bannerImages.value = data.homeBannerUrls.split(',').filter(Boolean)
  107. }
  108. } catch (error) {
  109. console.error('Failed to fetch banners', error)
  110. }
  111. }
  112. onShow(() => {
  113. fetchServices()
  114. fetchBanners()
  115. })
  116. const onLocationClick = () => {
  117. uni.showToast({ title: '城市选择功能即将上线', icon: 'none' })
  118. }
  119. const onSearchClick = () => {
  120. // 跳转搜索页(预留)
  121. }
  122. const goToServices = () => {
  123. uni.reLaunch({ url: '/pages/service/all/index' })
  124. }
  125. const goToDetail = (item) => {
  126. // @Author: Antigravity
  127. // 存储完整的服务数据,供详情页读取
  128. uni.setStorageSync('currentService', item)
  129. if (item.name === '托运') {
  130. uni.reLaunch({ url: '/pages/service/all/index' })
  131. return
  132. }
  133. uni.navigateTo({
  134. url: `/pages/service/detail/index?service=${item.name}`
  135. })
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .home-page {
  140. background-image: linear-gradient(to bottom, #FFD93D 0%, #FFD93D 440rpx, #f2f2f2 440rpx, #f2f2f2 100%);
  141. min-height: 100vh;
  142. padding-bottom: 120rpx;
  143. }
  144. .search-wrapper {
  145. padding: 24rpx 32rpx;
  146. padding-top: calc(var(--status-bar-height, 44px) + 20rpx);
  147. display: flex;
  148. align-items: center;
  149. gap: 16rpx;
  150. }
  151. .location-box {
  152. display: flex;
  153. align-items: center;
  154. gap: 6rpx;
  155. flex-shrink: 0;
  156. }
  157. .location-text {
  158. font-size: 28rpx;
  159. color: #fff;
  160. font-weight: bold;
  161. }
  162. .search-bar {
  163. flex: 1;
  164. display: flex;
  165. align-items: center;
  166. background: rgba(255, 255, 255, 0.85);
  167. border-radius: 40rpx;
  168. padding: 16rpx 24rpx;
  169. gap: 12rpx;
  170. }
  171. .search-placeholder {
  172. font-size: 26rpx;
  173. color: #999;
  174. }
  175. .banner-swipe-wrapper {
  176. padding: 0 32rpx 24rpx;
  177. }
  178. .my-swipe {
  179. border-radius: 32rpx;
  180. overflow: hidden;
  181. height: 320rpx;
  182. }
  183. .swipe-img {
  184. width: 100%;
  185. height: 320rpx;
  186. }
  187. .notice-section {
  188. padding: 0 32rpx 24rpx;
  189. }
  190. .notice-bar {
  191. display: flex;
  192. align-items: center;
  193. background: #fffbe8;
  194. border-radius: 16rpx;
  195. padding: 12rpx 20rpx;
  196. gap: 12rpx;
  197. height: 64rpx;
  198. overflow: hidden;
  199. }
  200. .notice-scroll {
  201. flex: 1;
  202. white-space: nowrap;
  203. }
  204. .notice-text {
  205. font-size: 24rpx;
  206. color: #ed6a0c;
  207. }
  208. .new-service-grid {
  209. padding: 0 32rpx;
  210. display: flex;
  211. flex-direction: column;
  212. gap: 24rpx;
  213. margin-bottom: 24rpx;
  214. }
  215. .hero-card {
  216. height: 260rpx;
  217. background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%);
  218. border-radius: 32rpx;
  219. padding: 40rpx;
  220. position: relative;
  221. overflow: hidden;
  222. display: flex;
  223. align-items: center;
  224. box-shadow: 0 12rpx 32rpx rgba(37, 99, 235, 0.18);
  225. }
  226. .card-content {
  227. z-index: 1;
  228. display: flex;
  229. flex-direction: column;
  230. }
  231. .card-title {
  232. font-size: 38rpx;
  233. color: #fff;
  234. font-weight: 800;
  235. letter-spacing: 2rpx;
  236. }
  237. .card-desc {
  238. font-size: 24rpx;
  239. color: rgba(255, 255, 255, 0.9);
  240. margin-top: 12rpx;
  241. }
  242. .hero-icon {
  243. position: absolute;
  244. right: 20rpx;
  245. bottom: -10rpx;
  246. width: 240rpx;
  247. height: 240rpx;
  248. opacity: 0.85;
  249. }
  250. .card-row {
  251. display: flex;
  252. gap: 24rpx;
  253. }
  254. .sub-card {
  255. flex: 1;
  256. height: 200rpx;
  257. border-radius: 32rpx;
  258. padding: 30rpx;
  259. position: relative;
  260. overflow: hidden;
  261. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
  262. }
  263. .sub-card:nth-child(1) {
  264. background: linear-gradient(135deg, #34d399 0%, #059669 100%);
  265. }
  266. .sub-card:nth-child(2) {
  267. background: linear-gradient(135deg, #fb923c 0%, #ea580c 100%);
  268. }
  269. .sub-title {
  270. font-size: 30rpx;
  271. color: #fff;
  272. font-weight: bold;
  273. display: block;
  274. }
  275. .sub-desc {
  276. font-size: 20rpx;
  277. color: rgba(255, 255, 255, 0.85);
  278. margin-top: 8rpx;
  279. display: block;
  280. }
  281. .sub-icon {
  282. position: absolute;
  283. right: 4rpx;
  284. bottom: 4rpx;
  285. width: 100rpx;
  286. height: 100rpx;
  287. opacity: 0.8;
  288. }
  289. .section-header {
  290. padding: 50rpx 32rpx 20rpx;
  291. display: flex;
  292. justify-content: space-between;
  293. align-items: center;
  294. }
  295. .section-title {
  296. font-size: 36rpx;
  297. font-weight: bold;
  298. color: #333;
  299. }
  300. .more-link {
  301. display: flex;
  302. align-items: center;
  303. gap: 4rpx;
  304. font-size: 26rpx;
  305. color: #999;
  306. }
  307. .recommend-list {
  308. padding: 20rpx 32rpx 40rpx;
  309. }
  310. .recommend-card {
  311. background: #fff;
  312. border-radius: 24rpx;
  313. padding: 24rpx;
  314. display: flex;
  315. gap: 24rpx;
  316. margin-bottom: 24rpx;
  317. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  318. }
  319. .item-img {
  320. width: 180rpx;
  321. height: 180rpx;
  322. border-radius: 16rpx;
  323. }
  324. .item-info {
  325. flex: 1;
  326. display: flex;
  327. flex-direction: column;
  328. justify-content: space-between;
  329. }
  330. .item-header {
  331. display: flex;
  332. justify-content: space-between;
  333. align-items: center;
  334. }
  335. .item-title {
  336. font-size: 32rpx;
  337. color: #333;
  338. font-weight: bold;
  339. }
  340. .booked {
  341. font-size: 24rpx;
  342. color: #999;
  343. }
  344. .item-desc {
  345. font-size: 26rpx;
  346. color: #666;
  347. margin: 12rpx 0;
  348. }
  349. .item-bottom {
  350. display: flex;
  351. align-items: center;
  352. }
  353. .tag {
  354. background-color: #e3f2fd;
  355. color: #2196f3;
  356. font-size: 22rpx;
  357. padding: 6rpx 16rpx;
  358. border-radius: 8rpx;
  359. }
  360. </style>