home.vue 13 KB

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