machinecat520 преди 2 години
родител
ревизия
3af1d40d5b
променени са 6 файла, в които са добавени 100 реда и са изтрити 70 реда
  1. 21 4
      pages/index/index.js
  2. 5 10
      pages/index/index.wxml
  3. 48 56
      pages/map/map.js
  4. 3 0
      pages/map/map.wxml
  5. 4 0
      utils/config.js
  6. 19 0
      utils/request.js

+ 21 - 4
pages/index/index.js

@@ -1,4 +1,5 @@
 // pages/index/index.js
+import request from '../../utils/request'
 
 const htmlSnip = `<div class="textContainer">
     <h1 class="titleHead">景区介绍<h1>
@@ -14,16 +15,32 @@ Page({
      */
     data: {
         htmlSnip,
-        imgList:['../../images/1.jpg','../../images/2.jpg']
-
+        imgList:['../../images/1.jpg','../../images/2.jpg'],
+        bannersList:[]
 
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
-
+    onLoad:async function(options) {
+        let result = await request('/files/1')
+        let that = this
+        console.log(result);
+        let bannersList = this.data.bannersList
+        for(let i = 0;i < result.length;i++){
+            // console.log(result[i].iconPath);
+            let iconPath = result[i].iconPath
+            console.log(iconPath);
+            let imgPath = iconPath.replace('localhost','192.168.0.177')
+            console.log(imgPath);
+            bannersList[i] = imgPath
+        }
+        this.setData({
+            bannersList
+        })
+        // console.log(bannersList);
+        
     },
 
     /**

+ 5 - 10
pages/index/index.wxml

@@ -1,18 +1,13 @@
 <view class="indexContainer">
+<!-- 轮播图区域 -->
     <swiper class="banners" autoplay circular interval="2000" indicator-dots="true" indicator-color="ivory" indicator-active-color="#d43c33" next-margin="0rpx" previous-margin="0rpx">
-        <swiper-item>
-            <image src="../../images/1.jpg"></image>
-        </swiper-item>
-        <swiper-item bindtap="toIndex">
-            <image src="../../images/2.jpg"></image>
-        </swiper-item>
-        <swiper-item bindtap="toIndex">
-            <image src="../../images/3.jpg"></image>
+        <swiper-item wx:for="{{bannersList}}" wx:key="key">
+            <image src="{{item}}"></image>
         </swiper-item>
     </swiper>
-
+    <!-- 景区介绍的正文 -->
     <view>
         <rich-text nodes="{{htmlSnip}}"></rich-text>
     </view>
-    
+
 </view>

+ 48 - 56
pages/map/map.js

@@ -1,4 +1,5 @@
 // pages/map/map.js
+import request from '../../utils/request'
 Page({
 
     /**
@@ -9,55 +10,10 @@ Page({
         showlocation: "true", //显示带有方向的当前定位点
         showcompass: "true", //显示指南针
         enabletraffic: "false", //是否开启实时路况
-        longitude: "103.69618", //中心经度
-        latitude: "30.61249", //中心纬度
+        longitude: "103.70618", //地图中心经度
+        latitude: "30.51249", //地图中心纬度
         //标记点位
-        marks: [{
-                id: 1,
-                latitude: 30.61249,
-                longitude: 103.69618,
-                title: "崇州万达广场",
-                iconPath: "../../images/location.png",
-                width: 30,
-                height: 30,
-                callout: {
-                    content: '崇州万达广场',
-                    bgColor: '#fff',
-                    fontSize: '32rpx',
-                    display: 'ALWAYS'
-                }
-            },
-            {
-                id: 2,
-                latitude: 30.62249,
-                longitude: 103.59618,
-                title: "崇州市牛叉村委会",
-                iconPath: "../../images/location.png",
-                width: 30,
-                height: 30,
-                callout: {
-                    content: '崇州市牛叉村委会',
-                    bgColor: '#fff',
-                    fontSize: '32rpx',
-                    display: 'ALWAYS'
-                }
-            },
-            {
-                id: 3,
-                latitude: 30.62649,
-                longitude: 103.63618,
-                title: "崇州市牛叉不得了村",
-                iconPath: "../../images/location.png",
-                width: 30,
-                height: 30,
-                callout: {
-                    content: '崇州市牛叉不得了村',
-                    bgColor: '#fff',
-                    fontSize: '32rpx',
-                    display: 'ALWAYS'
-                }
-            }
-        ],
+        marks: [],
         //搜索点位
         searchmarks: [{
             latitude: 30.61249,
@@ -75,8 +31,34 @@ Page({
     /**
      * 生命周期函数--监听页面加载
      */
-    onLoad(options) {
+    onLoad: async function (options) {
+
+        let result = await request('/merchant/merchantAndCallout')
+        // console.log("结果数据:", result);
+        var marker = [];
+        for (let i = 0; i < result.length; i++) {
+            //console.log(result[i].status);
+            if (result[i].status == 1) {
+                marker[i] = {
+                    id: result[i].id,
+                    latitude: result[i].latitude,
+                    longitude: result[i].longitude,
+                    title: result[i].title,
+                    iconPath: "../../images/location.png",
+                    width: result[i].width,
+                    height: result[i].height,
+                    callout: result[i].callout
+                }               
+            }
+        }
+        // console.log(marker);
+        this.setData({
+            marks:marker,
+            longitude:marker[0].longitude,
+            latitude:marker[0].latitude
+        })
         let marks = this.data.marks
+        // console.log(marks);
         var arr = new Array(marks.length)
         for (let i = 0; i < marks.length; i++) {
             let latitude = marks[i].latitude
@@ -175,12 +157,22 @@ Page({
     //点击标记点的事件
     bmakt(e) {
         // console.log(e.markerId);
-        var index = e.markerId - 1;
+        var id = e.markerId;
         let marks = this.data.marks
-        //拉起外部地图,并传递经纬度和名称
+        var index
+        for(let i = 0;i < marks.length;i++){
+            if(id == marks[i].id){
+                index = i
+            }
+        }
+        let lati = Number(marks[index].latitude)
+        let longti = Number(marks[index].longitude)
+        console.log(lati,longti);
+        // console.log(typeof(lati));
+        // //拉起外部地图,并传递经纬度和名称
         wx.openLocation({
-            latitude: marks[index].latitude,
-            longitude: marks[index].longitude,
+            latitude: lati,
+            longitude: longti,
             name: marks[index].title
         })
     },
@@ -192,12 +184,12 @@ Page({
     },
 
     //返回按钮点击事件
-    returnBack(){
+    returnBack() {
         let points = this.data.points
         const map = wx.createMapContext('map');
         map.includePoints({
-            points:points,
-            padding:[40,40,40,40]
+            points: points,
+            padding: [40, 40, 40, 40]
         });
     },
 

+ 3 - 0
pages/map/map.wxml

@@ -19,11 +19,13 @@
     include-points="{{points}}"
     bindmarkertap="bmakt">
     </map>
+    <!-- 我的位置和返回位置两个按键 -->
     <view class="locat">
         <image class="iconBtn" src="../../images/myLocal.png" bindtap="myLocate"></image>
         <image class="iconBtn2" src="../../images/return.png" bindtap="returnBack"></image>
     </view>
 </view>
+<!-- 没有输入搜索内容时的搜索内容区 -->
 <view wx:if="{{showSearch}}" class="searchContain">
     <view class="mask" bindtap="shut"></view>
     <view class="searchContent">
@@ -31,6 +33,7 @@
     </view>
     </view>
 </view>
+<!-- 输入了搜索内容后的搜索内容区 -->
 <view wx:if="{{searchContent && showSearch}}" class="searchContain">
     <view class="mask" bindtap="shut"></view>
     <view class="searchContent">

+ 4 - 0
utils/config.js

@@ -0,0 +1,4 @@
+//配置服务器相关信息
+export default{
+    host:'http://192.168.0.177:9090'
+}

+ 19 - 0
utils/request.js

@@ -0,0 +1,19 @@
+//发送ajax请求
+import config from './config'
+export default (url, data = {}, method = 'GET') => {
+    return new Promise((resolve,reject) => {
+        wx.request({
+            url: config.host + url,
+            data,
+            method,
+            success(res) {
+                // console.log("请求成功:", res);
+                resolve(res.data)
+            },
+            fail(err) {
+                console.log("请求失败:", err);
+                reject(err)
+            }
+        })
+    })
+}