HW 3 years ago
parent
commit
e939b4c303
6 changed files with 155 additions and 28 deletions
  1. 12 11
      package.json
  2. 12 0
      src/app.config.js
  3. 7 0
      src/index.html
  4. 118 13
      src/pages/index/index.jsx
  5. 1 4
      src/pages/index/index.less
  6. 5 0
      yarn.lock

+ 12 - 11
package.json

@@ -38,27 +38,28 @@
   "dependencies": {
     "@babel/runtime": "^7.7.7",
     "@tarojs/components": "3.1.4",
+    "@tarojs/react": "3.1.4",
     "@tarojs/runtime": "3.1.4",
     "@tarojs/taro": "3.1.4",
-    "redux-logger": "^3.0.6",
-    "redux-thunk": "^2.3.0",
-    "redux": "^4.0.0",
-    "react-redux": "^7.2.0",
+    "dayjs": "^1.10.4",
+    "react": "^17.0.0",
     "react-dom": "^17.0.0",
-    "@tarojs/react": "3.1.4",
-    "react": "^17.0.0"
+    "react-redux": "^7.2.0",
+    "redux": "^4.0.0",
+    "redux-logger": "^3.0.6",
+    "redux-thunk": "^2.3.0"
   },
   "devDependencies": {
-    "@types/webpack-env": "^1.13.6",
-    "@types/react": "^17.0.2",
-    "@tarojs/mini-runner": "3.1.4",
     "@babel/core": "^7.8.0",
+    "@tarojs/mini-runner": "3.1.4",
     "@tarojs/webpack-runner": "3.1.4",
+    "@types/react": "^17.0.2",
+    "@types/webpack-env": "^1.13.6",
     "babel-preset-taro": "3.1.4",
-    "eslint-config-taro": "3.1.4",
     "eslint": "^6.8.0",
-    "eslint-plugin-react": "^7.8.2",
+    "eslint-config-taro": "3.1.4",
     "eslint-plugin-import": "^2.12.0",
+    "eslint-plugin-react": "^7.8.2",
     "eslint-plugin-react-hooks": "^4.2.0",
     "stylelint": "9.3.0"
   }

+ 12 - 0
src/app.config.js

@@ -7,5 +7,17 @@ export default {
     navigationBarBackgroundColor: '#fff',
     navigationBarTitleText: 'WeChat',
     navigationBarTextStyle: 'black'
+  },
+  requiredBackgroundModes:['location'],
+  plugins: {
+    chooseLocation: {
+      version: "1.0.6",
+      provider: "wx76a9a06e5b4e693e"
+    }
+  },
+  permission: {
+    "scope.userLocation": {
+      desc: "你的位置信息将用于小程序定位"
+    }
   }
 }

+ 7 - 0
src/index.html

@@ -9,9 +9,16 @@
   <meta name="apple-mobile-web-app-status-bar-style" content="white">
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
   <title></title>
+  <script type="text/javascript"
+          src="https://api.map.baidu.com/api?v=3.0&ak=iW1tcpzD7GnxvwhDYvtkFAfH65BDNxlA"></script>
+  <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.0&type=webgl&ak=iW1tcpzD7GnxvwhDYvtkFAfH65BDNxlA"></script>
+  <script type="text/javascript" src="http://api.map.baidu.com/library/TrackAnimation/src/TrackAnimation_min.js"></script>
   <script>
     !function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
   </script>
+  <style type="text/css">
+
+  </style>
 </head>
 <body>
   <div id="app"></div>

+ 118 - 13
src/pages/index/index.jsx

@@ -1,6 +1,8 @@
 import { Component } from 'react'
+import Taro from '@tarojs/taro'
 import { connect } from 'react-redux'
-import { View, Button, Text } from '@tarojs/components'
+import {View, Map, Button} from '@tarojs/components'
+import dayjs from 'dayjs';
 
 import { add, minus, asyncAdd } from '../../actions/counter'
 
@@ -21,24 +23,127 @@ import './index.less'
   }
 }))
 class Index extends Component {
-  componentWillReceiveProps (nextProps) {
-    console.log(this.props, nextProps)
+  constructor(props) {
+    super(props);
+    this.state={
+      data:[],
+      newArrder:{},
+      newList:[
+        {
+          longitude: 112.9513,
+          latitude: 28.23529,
+          title:'营销员1',
+          label:{
+            content:'营销员1'
+          }
+        },
+        {
+          longitude: 112.9613,
+          latitude: 28.23529,
+          title:'营销员2',
+        },
+        {
+          longitude: 112.9713,
+          latitude: 28.23529,
+          title:'营销员3',
+        }
+      ],
+    }
   }
 
-  componentWillUnmount () { }
-
-  componentDidShow () { }
+  componentDidShow () {
+    const chooseLocation = requirePlugin('chooseLocation');
+    const location = chooseLocation.getLocation();
+    console.log(location);
+  }
 
-  componentDidHide () { }
+  componentDidMount() {
+    Taro.getLocation({
+      type: 'gcj02',
+      isHighAccuracy:true,
+      success: (res)=> {
+        const latitude = res.latitude
+        const longitude = res.longitude
+        console.log(latitude,longitude)
+        this.setState({
+          newArrder:{
+            latitude,
+            longitude
+          },
+        })
+      }
+    })
+    Taro.startLocationUpdateBackground({
+      success:()=>{
+        Taro.onLocationChange((data) => {
+          let arr = this.state.data
+          arr.push({
+            long:data.longitude,
+            latitude:data.latitude
+          })
+          console.log(arr,'arr')
+          this.setState({
+            data:this.state.data
+          })
+        });
+      }
+    })
+  }
 
   render () {
     return (
-      <View className='index'>
-        <Button className='add_btn' onClick={this.props.add}>+</Button>
-        <Button className='dec_btn' onClick={this.props.dec}>-</Button>
-        <Button className='dec_btn' onClick={this.props.asyncAdd}>async</Button>
-        <View><Text>{this.props.counter.num}</Text></View>
-        <View><Text>Hello, World</Text></View>
+      <View>
+        <Map
+          id="allmap"
+          {...this.state.newArrder}
+          markers={this.state.newList}
+          polyline={[{
+            points: [{
+              longitude: 112.9513,
+              latitude: 28.23529
+            }, {
+              longitude: 112.9713,
+              latitude: 28.23529
+            }, {
+              longitude: 112.9913,
+              latitude: 28.23529
+            }, {
+              longitude: 112.9313,
+              latitude: 28.23529
+            },{
+              longitude: 112.9313,
+              latitude: 28.23529
+            },{
+              longitude: 112.9313,
+              latitude: 28.23529
+            }],
+            color: "#33c9FFDD",
+            width: 3,
+            dottedLine: true
+          }]}
+          circles={[
+            {
+              longitude: 112.9513,
+              latitude: 28.23529,
+              color:'#DC3E28',
+              fillColor:'#DC3E28',
+              radius:50
+            }
+          ]}
+        />
+        <Button onClick={()=>{
+          const key = 'BP4BZ-JQJED-5DG4N-H6JND-KC5PK-D2BDL'; //使用在腾讯位置服务申请的key
+          const referer = '科德高企培育'; //调用插件的app的名称
+          const location = JSON.stringify({
+            latitude: 39.89631551,
+            longitude: 116.323459711
+          });
+          const category = '生活服务,娱乐休闲';
+
+          Taro.navigateTo({
+            url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&location=' + location + '&category=' + category
+          });
+        }}>选址</Button>
       </View>
     )
   }

+ 1 - 4
src/pages/index/index.less

@@ -1,4 +1 @@
-.index {
-  flex-direction: column;
-  width: 100%;
-}
+#allmap{height:90vh;width:100vw}

+ 5 - 0
yarn.lock

@@ -3408,6 +3408,11 @@ data-urls@^1.1.0:
     whatwg-mimetype "^2.2.0"
     whatwg-url "^7.0.0"
 
+dayjs@^1.10.4:
+  version "1.10.4"
+  resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
+  integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
+
 debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
   version "2.6.9"
   resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"