home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <view class="home-wrap base-container">
  3. <view class="home-top">
  4. <view class="home-search">
  5. <view class="search-wrap">
  6. <up-search placeholder="搜索品种" v-model="typeSearch"></up-search>
  7. </view>
  8. </view>
  9. <!-- <map
  10. id="mapId"
  11. :latitude="latitude"
  12. :longitude="longitude"
  13. :scale="scale"
  14. @markertap="onMarkerTap"
  15. @callouttap="onCalloutTap"
  16. @labeltap="onLabelTap"
  17. :markers="markers"
  18. :include-points="includePoints"
  19. :enable-poi="false"
  20. :enable-traffic="false"
  21. :enable-satellite="true"
  22. :enable-building="false"
  23. show-location
  24. style="width: 100%; height: 280rpx;clip-path: inset(0rpx round 16rpx);"
  25. ></map> -->
  26. <video src="https://birdseye-img.sysuimars.com/temp/5-25lby.mp4" object-fit="cover" :show-fullscreen-btn="false"
  27. :autoplay="true" class="map-video" loop muted :show-progress="false" :show-play-btn="false">
  28. </video>
  29. <view class="map-tips" @click="toPage('allGardenMap')">
  30. 飞鸟入驻管理果场详情,点击查看
  31. </view>
  32. </view>
  33. <view class="type-wrap">
  34. <up-scroll-list indicatorColor="#F3C11D33" indicatorActiveColor="#F3C11D" :indicatorWidth="30" :indicatorBarWidth="13">
  35. <view class="item-type">
  36. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  37. <view class="type-text">
  38. 全部
  39. </view>
  40. </view>
  41. <view class="item-type" v-for="(item, index) in typeList" :key="index">
  42. <image class="type-img" :src="item.image" alt="" />
  43. <view class="type-text">
  44. {{item.name}}
  45. </view>
  46. </view>
  47. </up-scroll-list>
  48. </view>
  49. <!-- 好味热卖 -->
  50. <view class="home-hot">
  51. <hot-component-vue :farmId="766"></hot-component-vue>
  52. </view>
  53. <!-- 有味果园 -->
  54. <view class="garden-wrap">
  55. <view class="garden-content">
  56. <view class="hot-title">
  57. <view class="title-l">
  58. 有味果园
  59. </view>
  60. <view class="title-btn" @click="toPage('gardenList')">
  61. 查看全部<up-icon size="10" name="arrow-right"></up-icon>
  62. </view>
  63. </view>
  64. <view class="garden-list">
  65. <view
  66. class="garden-item"
  67. v-for="farm in gardenList"
  68. :key="farm.farmId || farm.id"
  69. @click="goGardenItem(farm)"
  70. >
  71. <view class="garden-l" v-if="farm.coverVideo">
  72. <video :src="farm.coverVideo" :show-progress="false" :show-play-btn="false"
  73. :show-center-play-btn="false" object-fit="cover" :show-fullscreen-btn="false"
  74. disablePictureInPicture :autoplay="true" class="video-dom"
  75. loop muted>
  76. </video>
  77. </view>
  78. <view class="garden-l" v-else>
  79. <image class="garden-img" :src="`${config.BASIC_IMG}home/garden.png`" mode=""></image>
  80. <text class="img-text">无人机实拍视频</text>
  81. </view>
  82. <view class="garden-r">
  83. <view class="garden-title">
  84. {{ farm.name }}
  85. </view>
  86. <view class="garden-info">
  87. 品种:荔枝({{ farm.pz }})
  88. </view>
  89. <view class="garden-info">
  90. 位置:{{ (farm.cityName + farm.countyName) || '—' }}
  91. </view>
  92. <view class="garden-btn-group">
  93. <view class="btn-second">
  94. 有味指数
  95. <text>{{ farm.envScore || '—' }}分</text>
  96. </view>
  97. <view class="btn-primary" @click.stop="goSourceReport(farm)">
  98. 溯源报告
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script setup>
  109. import { ref, onMounted } from 'vue'
  110. import config from "@/api/config.js"
  111. import HOME from '@/api/home'
  112. import hotComponentVue from './hotComponent.vue'
  113. import { onLoad } from "@dcloudio/uni-app"
  114. const typeSearch = ref(null)
  115. function toPage(path) {
  116. uni.navigateTo({
  117. url: `/pages/tabBar/home/subPages/${path}`
  118. });
  119. }
  120. function goGardenItem(farm) {
  121. const id = farm?.farmId
  122. uni.navigateTo({
  123. url: `/pages/tabBar/home/subPages/gardenItem?id=${id}`
  124. });
  125. }
  126. function goSourceReport(farm) {
  127. const id = farm?.farmId
  128. uni.navigateTo({
  129. url: `/pages/tabBar/home/subPages/sourceReport?id=${id}`
  130. });
  131. }
  132. const latitude = ref(23.099994)
  133. const longitude = ref(113.324520)
  134. const markers = ref([])
  135. const includePoints = ref([])
  136. const mapCtx = ref(null)
  137. const mapPoint = '../../../static/map/point.png'
  138. const farmList = ref([]) // 新增果园列表数据
  139. const scale = ref(10)
  140. const gardenList = ref([])
  141. onLoad(async () => {
  142. // #ifdef MP-WEIXIN
  143. // mapCtx.value = uni.createMapContext('mapId')
  144. // mapCtx.value.on('markerClusterClick', res => {
  145. // console.log('markerClusterClick', res)
  146. // })
  147. getTypeList()
  148. getFarmData()
  149. // bindEvent()
  150. // #endif
  151. })
  152. const typeList = ref([])
  153. function getTypeList() {
  154. HOME.fetchTypeList().then(({data}) => {
  155. typeList.value = data
  156. })
  157. }
  158. function getFarmData() {
  159. HOME.getAllFarm().then(({data}) => {
  160. gardenList.value = data.filter(item => item.recommend !== null)
  161. // farmList.value = (data || []).sort((a, b) => {
  162. // // 优先排序:lighten为true的排前面,然后按recommend排序
  163. // if (a.lighten !== b.lighten) return b.lighten ? 1 : -1
  164. // return (b.recommend || 0) - (a.recommend || 0)
  165. // })
  166. // if(farmList.value.length > 0) {
  167. // // 设置地图中心点为第一个果园的位置
  168. // const firstPoint = parsePoint(farmList.value[0].point)
  169. // latitude.value = firstPoint.latitude
  170. // longitude.value = firstPoint.longitude
  171. // // 生成标记点
  172. // generateMarkers(farmList.value)
  173. // }
  174. })
  175. }
  176. // 解析POINT字符串为经纬度对象
  177. function parsePoint(pointStr) {
  178. if(!pointStr) return {longitude: 113.324520, latitude: 23.099994}
  179. const regex = /POINT\(([^ ]+) ([^ ]+)\)/
  180. const match = pointStr.match(regex)
  181. if(match) {
  182. return {
  183. longitude: parseFloat(match[1]),
  184. latitude: parseFloat(match[2])
  185. }
  186. }
  187. return {longitude: 113.324520, latitude: 23.099994} // 默认值
  188. }
  189. // 生成标记点数据
  190. function generateMarkers(farms) {
  191. const newMarkers = farms.map((farm, index) => {
  192. const point = parsePoint(farm.point)
  193. return {
  194. id: farm.farmId || index + 1, // 使用farmId作为唯一标识
  195. latitude: point.latitude,
  196. longitude: point.longitude,
  197. iconPath: mapPoint, // 使用果园图标
  198. width: 20,
  199. height: 20,
  200. joinCluster: true,
  201. // callout: { // 添加气泡标签
  202. // content: farm.name,
  203. // color: '#000',
  204. // fontSize: 14,
  205. // borderRadius: 4,
  206. // bgColor: '#FFCB3C',
  207. // padding: 8,
  208. // display: 'ALWAYS'
  209. // },
  210. label: {
  211. content: farm.name, // 显示果园名称
  212. color: '#000',
  213. fontSize: 12,
  214. bgColor: '#FFCB3C',
  215. borderRadius: 8,
  216. padding: 5,
  217. anchorX: 0,
  218. anchorY: -50,
  219. borderWidth: 1,
  220. borderColor: '#FFCB3C',
  221. textAlign: 'center'
  222. },
  223. customData: farm // 存储原始数据用于点击事件
  224. }
  225. })
  226. // 更新包含的点位范围
  227. includePoints.value = newMarkers.map(marker => ({
  228. latitude: marker.latitude,
  229. longitude: marker.longitude
  230. }))
  231. // #ifdef MP-WEIXIN
  232. mapCtx.value.addMarkers({
  233. markers: newMarkers,
  234. clear: true,
  235. complete(res) {
  236. console.log('添加标记点完成', res)
  237. }
  238. })
  239. // #else
  240. markers.value = newMarkers
  241. // #endif
  242. }
  243. const bindEvent = () => {
  244. // #ifdef MP-WEIXIN
  245. mapCtx.value.initMarkerCluster({
  246. enableDefaultStyle: false,
  247. zoomOnClick: true,
  248. gridSize: 40,
  249. complete(res) {
  250. console.log('initMarkerCluster', res)
  251. }
  252. })
  253. mapCtx.value.on('markerClusterCreate', res => {
  254. console.log('clusterCreate', res)
  255. const clusters = res.clusters
  256. const clusterMarkers = clusters.map(cluster => {
  257. // 获取聚合中的第一个果园
  258. const firstMarker = farmList.value.find(m => m.farmId === cluster.markerIds[0])
  259. return {
  260. ...cluster.center,
  261. width: 20,
  262. height: 20,
  263. clusterId: cluster.clusterId,
  264. iconPath: mapPoint, // 使用果园图标
  265. label: {
  266. content: firstMarker?.name, // 显示果园名称
  267. color: '#000',
  268. fontSize: 12,
  269. bgColor: '#FFCB3C',
  270. borderRadius: 8,
  271. padding: 5,
  272. anchorX: 0,
  273. anchorY: -50,
  274. borderWidth: 1,
  275. borderColor: '#FFCB3C',
  276. textAlign: 'center'
  277. },
  278. customData: {
  279. isCluster: true,
  280. markerIds: cluster.markerIds,
  281. firstMarkerData: firstMarker?.customData
  282. }
  283. }
  284. })
  285. mapCtx.value.addMarkers({
  286. markers: clusterMarkers,
  287. clear: false,
  288. complete(res) {
  289. }
  290. })
  291. })
  292. // #endif
  293. }
  294. const onMarkerTap = (e) => {
  295. const markerId = e.detail.markerId
  296. const marker = markers.value.find(m => m.id === markerId)
  297. if(marker && marker.customData) {
  298. console.log('点击了果园:', marker.customData.name)
  299. // 可以在这里跳转到果园详情页
  300. uni.navigateTo({
  301. url: `/pages/tabBar/home/subPages/gardenItem?id=${marker.customData.farmId}`
  302. })
  303. }
  304. }
  305. const onCalloutTap = (e) => {
  306. console.log('点击了气泡:', e)
  307. onMarkerTap(e) // 调用相同的处理逻辑
  308. }
  309. const onLabelTap = (e) => {
  310. console.log('点击了标签:', e)
  311. onMarkerTap(e) // 调用相同的处理逻辑
  312. }
  313. const removeMarkers = () => {
  314. // #ifdef MP-WEIXIN
  315. mapCtx.value.addMarkers({
  316. clear: true,
  317. markers: []
  318. })
  319. // #else
  320. markers.value = []
  321. // #endif
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. .home-wrap {
  326. background-color: #F2F3F5;
  327. padding: 0 0 16rpx 0;
  328. .home-top {
  329. padding: 20rpx 24rpx 0 24rpx;
  330. background: linear-gradient(#FFFFFF, rgba(242, 243, 245, 0));
  331. position: relative;
  332. }
  333. .map-video {
  334. width: 100%;
  335. height: 280rpx;
  336. border-radius: 16rpx;
  337. }
  338. .map-tips {
  339. position: absolute;
  340. bottom: 6rpx;
  341. left: 24rpx;
  342. height: 70rpx;
  343. width: calc(100% - 48rpx);
  344. background: linear-gradient(rgba(102, 102, 102, 0), rgba(0, 0, 0, 0.55));
  345. display: flex;
  346. align-items: center;
  347. font-size: 24rpx;
  348. color: #FFFFFF;
  349. padding-left: 20rpx;
  350. box-sizing: border-box;
  351. border-radius: 0 0 16rpx 16rpx;
  352. }
  353. .home-search {
  354. display: flex;
  355. align-items: center;
  356. width: 100%;
  357. border: 2rpx solid #FFD95E;
  358. border-radius: 40rpx;
  359. margin-bottom: 40rpx;
  360. .search-wrap {
  361. flex: 1;
  362. // padding-left: 22rpx;
  363. ::v-deep {
  364. .u-search {
  365. .u-search__content {
  366. background-color: transparent !important;
  367. .u-search__content__input {
  368. background-color: transparent !important;
  369. }
  370. }
  371. .u-search__action {
  372. text-align: center;
  373. line-height: 52rpx;
  374. border-radius: 40rpx;
  375. font-size: 28rpx;
  376. background-color: #FFD95E;
  377. margin: 6rpx 8rpx;
  378. width: 112rpx;
  379. height: 52rpx;
  380. }
  381. }
  382. }
  383. }
  384. .search-btn {
  385. text-align: center;
  386. line-height: 52rpx;
  387. border-radius: 40rpx;
  388. font-size: 28rpx;
  389. background-color: #FFD95E;
  390. margin: 6rpx 8rpx;
  391. width: 112rpx;
  392. height: 52rpx;
  393. }
  394. }
  395. .type-wrap {
  396. margin: 20rpx;
  397. padding: 20rpx;
  398. background-color: #fff;
  399. border-radius: 16rpx;
  400. height: 200rpx;
  401. box-sizing: border-box;
  402. .item-type {
  403. text-align: center;
  404. font-size: 24rpx;
  405. .type-img {
  406. width: 92rpx;
  407. height: 92rpx;
  408. }
  409. }
  410. .item-type + .item-type {
  411. padding-left: 22rpx;
  412. }
  413. }
  414. .home-hot {
  415. padding: 0 20rpx 20rpx;
  416. }
  417. .garden-wrap {
  418. margin: 0 20rpx 20rpx;
  419. background: linear-gradient(#FFFFFF, rgba(255, 255, 255, 0));
  420. padding: 2rpx;
  421. border-radius: 16rpx;
  422. .garden-content{
  423. background: linear-gradient(#fff6d8 30rpx, #FFFFFF 120rpx);
  424. border-radius: 16rpx;
  425. padding: 20rpx;
  426. box-sizing: border-box;
  427. .garden-list {
  428. .garden-item {
  429. display: flex;
  430. .garden-l {
  431. position: relative;
  432. .video-dom {
  433. width: 234rpx;
  434. height: 200rpx;
  435. object-fit: cover;
  436. border-radius: 10rpx;
  437. }
  438. .garden-img {
  439. width: 254rpx;
  440. height: 200rpx;
  441. object-fit: cover;
  442. border-radius: 10rpx;
  443. }
  444. .img-text {
  445. position: absolute;
  446. left: 0%;
  447. top: 0%;
  448. background: rgba(0, 0, 0, 0.3);
  449. backdrop-filter: 8rpx;
  450. border-radius: 10rpx 0 10rpx 0;
  451. font-size: 20rpx;
  452. color: #FFFFFF;
  453. padding: 6rpx 14rpx;
  454. }
  455. }
  456. .garden-r {
  457. padding-left: 20rpx;
  458. .garden-title {
  459. font-size: 28rpx;
  460. line-height: 42rpx;
  461. color: #000000;
  462. font-weight: 600;
  463. padding-bottom: 10rpx;
  464. }
  465. .garden-info {
  466. color: rgba(0, 0, 0, 0.5);
  467. font-size: 24rpx;
  468. line-height: 36rpx;
  469. }
  470. .garden-btn-group {
  471. padding-top: 20rpx;
  472. display: flex;
  473. align-items: center;
  474. .btn-second {
  475. padding: 0 20rpx;
  476. border-radius: 40rpx;
  477. font-size: 24rpx;
  478. color: #C49600;
  479. background: rgba(255, 217, 94, 0.2);
  480. height: 56rpx;
  481. line-height: 56rpx;
  482. }
  483. .btn-primary {
  484. padding: 0 20rpx;
  485. border-radius: 40rpx;
  486. font-size: 24rpx;
  487. color: #000000;
  488. background: #FFD95E;
  489. font-weight: bold;
  490. height: 56rpx;
  491. line-height: 56rpx;
  492. }
  493. }
  494. }
  495. }
  496. .garden-item + .garden-item {
  497. margin-top: 20rpx;
  498. }
  499. }
  500. }
  501. }
  502. .hot-title {
  503. display: flex;
  504. align-items: center;
  505. justify-content: space-between;
  506. padding-bottom: 20rpx;
  507. .title-l {
  508. font-family: 'PangMenZhengDao';
  509. font-size: 32rpx;
  510. .title-color {
  511. color: #F3C11D ;
  512. }
  513. }
  514. .title-btn {
  515. color: rgba(0, 0, 0, 0.6);
  516. font-size: 24rpx;
  517. display: inline-flex;
  518. align-items: center;
  519. }
  520. }
  521. ::v-deep {
  522. .u-scroll-list__indicator {
  523. margin-top: 20rpx;
  524. }
  525. }
  526. }
  527. </style>