home.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. @markertap="onMarkerTap"
  14. @callouttap="onCalloutTap"
  15. @labeltap="onLabelTap"
  16. :markers="markers"
  17. :include-points="includePoints"
  18. :enable-poi="false"
  19. :enable-traffic="false"
  20. :enable-building="false"
  21. show-location
  22. style="width: 100%; height: 280rpx;"
  23. ></map>
  24. <view class="map-tips" @click="toPage('allGardenMap')">
  25. 飞鸟入驻管理果场详情,点击查看
  26. </view>
  27. </view>
  28. <view class="type-wrap">
  29. <up-scroll-list indicatorColor="#F3C11D33" indicatorActiveColor="#F3C11D" :indicatorWidth="30" :indicatorBarWidth="13">
  30. <view class="item-type">
  31. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  32. <view class="type-text">
  33. 全部
  34. </view>
  35. </view>
  36. <view class="item-type">
  37. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-2.png`" alt="" />
  38. <view class="type-text">
  39. 龙眼
  40. </view>
  41. </view>
  42. <view class="item-type">
  43. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-3.png`" alt="" />
  44. <view class="type-text">
  45. 葡萄
  46. </view>
  47. </view>
  48. <view class="item-type">
  49. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  50. <view class="type-text">
  51. 水蜜桃
  52. </view>
  53. </view>
  54. <view class="item-type">
  55. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-2.png`" alt="" />
  56. <view class="type-text">
  57. 龙眼
  58. </view>
  59. </view>
  60. <view class="item-type">
  61. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-3.png`" alt="" />
  62. <view class="type-text">
  63. 葡萄
  64. </view>
  65. </view>
  66. <view class="item-type">
  67. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-3.png`" alt="" />
  68. <view class="type-text">
  69. 葡萄1
  70. </view>
  71. </view>
  72. <view class="item-type">
  73. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  74. <view class="type-text">
  75. 水蜜桃2
  76. </view>
  77. </view>
  78. <view class="item-type">
  79. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-3.png`" alt="" />
  80. <view class="type-text">
  81. 葡萄
  82. </view>
  83. </view>
  84. <view class="item-type">
  85. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  86. <view class="type-text">
  87. 水蜜桃
  88. </view>
  89. </view>
  90. <view class="item-type">
  91. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon-2.png`" alt="" />
  92. <view class="type-text">
  93. 龙眼
  94. </view>
  95. </view>
  96. </up-scroll-list>
  97. </view>
  98. <!-- 好味热卖 -->
  99. <view class="home-hot">
  100. <hot-component-vue></hot-component-vue>
  101. </view>
  102. <!-- 有味果园 -->
  103. <view class="garden-wrap">
  104. <view class="garden-content">
  105. <view class="hot-title">
  106. <view class="title-l">
  107. 有味果园
  108. </view>
  109. <view class="title-btn">
  110. 查看全部<up-icon size="10" name="arrow-right"></up-icon>
  111. </view>
  112. </view>
  113. <view class="garden-list">
  114. <view class="garden-item" @click="toPage('gardenItem')">
  115. <view class="garden-l">
  116. <image class="garden-img" :src="`${config.BASIC_IMG}home/garden.png`" mode=""></image>
  117. <text class="img-text">无人机实拍视频</text>
  118. </view>
  119. <view class="garden-r">
  120. <view class="garden-title">
  121. 从化荔枝博览园
  122. </view>
  123. <view class="garden-info">
  124. 品种:荔枝(井岗红糯、巨美人)
  125. </view>
  126. <view class="garden-info">
  127. 位置:广州市从化区
  128. </view>
  129. <view class="garden-btn-group">
  130. <view class="btn-second">
  131. 有味指数
  132. <text>4.5分</text>
  133. </view>
  134. <view class="btn-primary">
  135. 溯源报告
  136. </view>
  137. </view>
  138. </view>
  139. </view>
  140. <view class="garden-item">
  141. <view class="garden-l">
  142. <image class="garden-img" :src="`${config.BASIC_IMG}home/garden.png`" mode=""></image>
  143. <text class="img-text">无人机实拍视频</text>
  144. </view>
  145. <view class="garden-r">
  146. <view class="garden-title">
  147. 从化荔枝博览园
  148. </view>
  149. <view class="garden-info">
  150. 品种:荔枝(井岗红糯、巨美人)
  151. </view>
  152. <view class="garden-info">
  153. 位置:广州市从化区
  154. </view>
  155. <view class="garden-btn-group">
  156. <view class="btn-second">
  157. 有味指数
  158. <text>4.5分</text>
  159. </view>
  160. <view class="btn-primary">
  161. 溯源报告
  162. </view>
  163. </view>
  164. </view>
  165. </view>
  166. </view>
  167. </view>
  168. </view>
  169. </view>
  170. </template>
  171. <script setup>
  172. import { ref, onMounted } from 'vue'
  173. import config from "@/api/config.js"
  174. import hotComponentVue from './hotComponent.vue'
  175. const typeSearch = ref(null)
  176. function toPage(path) {
  177. uni.navigateTo({
  178. url: `/pages/tabBar/home/subPages/${path}`
  179. });
  180. }
  181. const latitude = ref(23.099994)
  182. const longitude = ref(113.324520)
  183. const markers = ref([])
  184. const includePoints = ref([])
  185. const mapCtx = ref(null)
  186. const img = ref('../../../static/map/point.png')
  187. onMounted(async () => {
  188. // #ifdef MP-WEIXIN
  189. mapCtx.value = uni.createMapContext('mapId')
  190. mapCtx.value.on('markerClusterClick', res => {
  191. console.log('markerClusterClick', res)
  192. })
  193. bindEvent()
  194. // #endif
  195. })
  196. const bindEvent = () => {
  197. // #ifdef MP-WEIXIN
  198. mapCtx.value.initMarkerCluster({
  199. enableDefaultStyle: false,
  200. zoomOnClick: true,
  201. gridSize: 60,
  202. complete(res) {
  203. console.log('initMarkerCluster', res)
  204. }
  205. })
  206. addMarkers()
  207. mapCtx.value.on('markerClusterCreate', res => {
  208. console.log('clusterCreate', res)
  209. const clusters = res.clusters
  210. const newMarkers = clusters.map(cluster => {
  211. const { center, clusterId, markerIds } = cluster
  212. return {
  213. ...center,
  214. width: 0,
  215. height: 0,
  216. clusterId, // 必须
  217. label: {
  218. content: markerIds.length + '',
  219. fontSize: 20,
  220. width: 30,
  221. height: 30,
  222. bgColor: '#FFCB3C',
  223. borderRadius: 30,
  224. textAlign: 'center',
  225. anchorX: 0,
  226. anchorY: -30,
  227. }
  228. }
  229. })
  230. mapCtx.value.addMarkers({
  231. markers: newMarkers,
  232. clear: false,
  233. complete(res) {
  234. console.log('clusterCreate addMarkers', res)
  235. }
  236. })
  237. })
  238. // #endif
  239. }
  240. const addMarkers = () => {
  241. const marker = {
  242. id: 1,
  243. iconPath: img.value,
  244. width: 30,
  245. height: 30,
  246. joinCluster: true, // 指定了该参数才会参与聚合
  247. label: {
  248. width: 50,
  249. height: 30,
  250. borderWidth: 1,
  251. borderRadius: 4,
  252. bgColor: '#FFCB3C88',
  253. anchorX: -26,
  254. anchorY: -60,
  255. content: ''
  256. }
  257. }
  258. const positions = [
  259. { latitude: 23.099994, longitude: 113.324520 },
  260. { latitude: 23.099994, longitude: 113.322520 },
  261. { latitude: 23.099994, longitude: 113.326520 },
  262. { latitude: 23.096994, longitude: 113.329520 }
  263. ]
  264. const newMarkers = []
  265. positions.forEach((p, i) => {
  266. const newMarker = {...marker, ...p}
  267. newMarker.id = i + 1
  268. newMarker.label.content = `果园 ${i + 1}`
  269. newMarkers.push(newMarker)
  270. })
  271. // #ifdef MP-WEIXIN
  272. mapCtx.value.addMarkers({
  273. markers: newMarkers,
  274. clear: false,
  275. complete(res) {
  276. console.log('addMarkers', res)
  277. }
  278. })
  279. // #else
  280. // 非微信平台直接设置 markers
  281. markers.value = markers.value.concat(newMarkers)
  282. // 更新包含的点
  283. includePoints.value = markers.value.map(marker => ({
  284. latitude: marker.latitude,
  285. longitude: marker.longitude
  286. }))
  287. // #endif
  288. }
  289. const removeMarkers = () => {
  290. // #ifdef MP-WEIXIN
  291. mapCtx.value.addMarkers({
  292. clear: true,
  293. markers: []
  294. })
  295. // #else
  296. markers.value = []
  297. // #endif
  298. }
  299. const onMarkerTap = (e) => {
  300. console.log('@@ markertap', e)
  301. }
  302. const onCalloutTap = (e) => {
  303. console.log('@@ onCalloutTap', e)
  304. }
  305. const onLabelTap = (e) => {
  306. console.log('@@ labletap', e)
  307. }
  308. </script>
  309. <style lang="scss" scoped>
  310. .home-wrap {
  311. background-color: #F2F3F5;
  312. padding: 0;
  313. .home-top {
  314. padding: 20rpx 24rpx;
  315. background: linear-gradient(#FFFFFF, rgba(242, 243, 245, 0));
  316. position: relative;
  317. }
  318. .map-tips {
  319. position: absolute;
  320. bottom: 0%;
  321. left: 24rpx;
  322. height: 70rpx;
  323. width: calc(100% - 48rpx);
  324. background: linear-gradient(rgba(102, 102, 102, 0), rgba(0, 0, 0, 0.55));
  325. display: flex;
  326. align-items: center;
  327. font-size: 24rpx;
  328. color: #FFFFFF;
  329. padding-left: 20rpx;
  330. box-sizing: border-box;
  331. border-radius: 0 0 16rpx 16rpx;
  332. }
  333. .home-search {
  334. display: flex;
  335. align-items: center;
  336. width: 100%;
  337. border: 2rpx solid #FFD95E;
  338. border-radius: 40rpx;
  339. margin-bottom: 40rpx;
  340. .search-wrap {
  341. flex: 1;
  342. // padding-left: 22rpx;
  343. ::v-deep {
  344. .u-search {
  345. .u-search__content {
  346. background-color: transparent !important;
  347. .u-search__content__input {
  348. background-color: transparent !important;
  349. }
  350. }
  351. .u-search__action {
  352. text-align: center;
  353. line-height: 52rpx;
  354. border-radius: 40rpx;
  355. font-size: 28rpx;
  356. background-color: #FFD95E;
  357. margin: 6rpx 8rpx;
  358. width: 112rpx;
  359. height: 52rpx;
  360. }
  361. }
  362. }
  363. }
  364. .search-btn {
  365. text-align: center;
  366. line-height: 52rpx;
  367. border-radius: 40rpx;
  368. font-size: 28rpx;
  369. background-color: #FFD95E;
  370. margin: 6rpx 8rpx;
  371. width: 112rpx;
  372. height: 52rpx;
  373. }
  374. }
  375. .type-wrap {
  376. margin: 20rpx;
  377. padding: 20rpx;
  378. background-color: #fff;
  379. border-radius: 16rpx;
  380. height: 200rpx;
  381. box-sizing: border-box;
  382. .item-type {
  383. text-align: center;
  384. font-size: 24rpx;
  385. .type-img {
  386. width: 92rpx;
  387. height: 92rpx;
  388. }
  389. }
  390. .item-type + .item-type {
  391. padding-left: 22rpx;
  392. }
  393. }
  394. .home-hot {
  395. padding: 0 20rpx 20rpx;
  396. }
  397. .garden-wrap {
  398. margin: 0 20rpx 20rpx;
  399. background: linear-gradient(#FFFFFF, rgba(255, 255, 255, 0));
  400. padding: 2rpx;
  401. border-radius: 16rpx;
  402. .garden-content{
  403. background: linear-gradient(#fff6d8 4%, #FFFFFF 28%);
  404. border-radius: 16rpx;
  405. padding: 20rpx;
  406. box-sizing: border-box;
  407. .garden-list {
  408. .garden-item {
  409. display: flex;
  410. .garden-l {
  411. position: relative;
  412. .garden-img {
  413. width: 254rpx;
  414. height: 200rpx;
  415. object-fit: cover;
  416. border-radius: 10rpx;
  417. }
  418. .img-text {
  419. position: absolute;
  420. left: 0%;
  421. top: 0%;
  422. background: rgba(0, 0, 0, 0.3);
  423. backdrop-filter: 8rpx;
  424. border-radius: 10rpx 0 10rpx 0;
  425. font-size: 20rpx;
  426. color: #FFFFFF;
  427. padding: 6rpx 14rpx;
  428. }
  429. }
  430. .garden-r {
  431. padding-left: 20rpx;
  432. .garden-title {
  433. font-size: 28rpx;
  434. line-height: 42rpx;
  435. color: #000000;
  436. font-weight: 600;
  437. padding-bottom: 10rpx;
  438. }
  439. .garden-info {
  440. color: rgba(0, 0, 0, 0.5);
  441. font-size: 24rpx;
  442. line-height: 36rpx;
  443. }
  444. .garden-btn-group {
  445. padding-top: 20rpx;
  446. display: flex;
  447. align-items: center;
  448. .btn-second {
  449. padding: 0 20rpx;
  450. border-radius: 40rpx;
  451. font-size: 24rpx;
  452. color: #C49600;
  453. background: rgba(255, 217, 94, 0.2);
  454. height: 56rpx;
  455. line-height: 56rpx;
  456. }
  457. .btn-primary {
  458. padding: 0 20rpx;
  459. border-radius: 40rpx;
  460. font-size: 24rpx;
  461. color: #000000;
  462. background: #FFD95E;
  463. font-weight: bold;
  464. height: 56rpx;
  465. line-height: 56rpx;
  466. }
  467. }
  468. }
  469. }
  470. .garden-item + .garden-item {
  471. margin-top: 20rpx;
  472. }
  473. }
  474. }
  475. }
  476. .hot-title {
  477. display: flex;
  478. align-items: center;
  479. justify-content: space-between;
  480. padding-bottom: 20rpx;
  481. .title-l {
  482. font-family: 'PangMenZhengDao';
  483. font-size: 32rpx;
  484. .title-color {
  485. color: #F3C11D ;
  486. }
  487. }
  488. .title-btn {
  489. color: rgba(0, 0, 0, 0.6);
  490. font-size: 24rpx;
  491. display: inline-flex;
  492. align-items: center;
  493. }
  494. }
  495. ::v-deep {
  496. .u-scroll-list__indicator {
  497. margin-top: 20rpx;
  498. }
  499. }
  500. }
  501. </style>