home.vue 12 KB

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