浏览代码

新增获取经纬度按钮及赋值显示

ming 4 年之前
父节点
当前提交
68bf2ac27d

+ 8 - 1
main.js

@@ -17,8 +17,15 @@ App.mpType = 'app'
 
 const app = new Vue({
     ...App
-})
+})
+
 app.$mount()
 
 
+const BASE_URL="https://iot.usky.cn/USKYOF/USKYOF.php/Home/";
+
+// export default {  
+//  BASE_URL
+// }
+
 

+ 22 - 19
pages/index/index.vue

@@ -357,6 +357,7 @@
 						url: 'Com/getPageAuthorization',
 						data: params
 					})
+					
 					
 					if (res.data.flag == 3000) {
 
@@ -391,25 +392,27 @@
 			// end
 
 			//首页初始化授权
-			async getPageAuthorization(ming = {}) {
-				const res = await this.$myRequest({
-					url: 'Com/getPageAuthorization',
-					data: ming
-				})
-
-				if (res.data.flag == 3000) {
-					uni.navigateTo({
-						url: '/pages/login/login',
-					});
-				}
-				if (res.data.flag == 3002) {
-					uni.navigateTo({
-						url: 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4eab2e3b5531d58b&redirect_uri=' + res.data
-							.tourl + '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect',
-					});
-				}
-
-			},
+			// async getPageAuthorization(ming = {}) {
+			// 	const res = await this.$myRequest({
+			// 		url: 'Com/getPageAuthorization',
+			// 		data: ming
+			// 	})
+			// 	alert('res.data.flag')
+			// 	alert(res.data.flag)
+
+			// 	if (res.data.flag == 3000) {
+			// 		uni.navigateTo({
+			// 			url: '/pages/login/login',
+			// 		});
+			// 	}
+			// 	if (res.data.flag == 3002) {
+			// 		uni.navigateTo({
+			// 			url: 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4eab2e3b5531d58b&redirect_uri=' + res.data
+			// 				.tourl + '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect',
+			// 		});
+			// 	}
+
+			// },
 
 			async getData() {
 				const res = await this.$myRequest({

+ 68 - 44
pages/siteAdd/siteAdd.vue

@@ -8,29 +8,36 @@
 					<text class="necessary">*</text>
 					站点名称:
 				</view>
-				<input name="userName" v-model="formMess.siteName"></input>
+				<input name="userName" v-model="siteName"></input>
 			</view>
 			<view class="form-item">
 				<view class="title"><text class="necessary">*</text>地址:</view>
-				<input name="input" v-model="formMess.address"></input>
+				<input name="input" v-model="address"></input>
 			</view>
 			<view class="form-item">
 				<view class="title"><text class="necessary">*</text>经度:</view>
-				<input name="input" v-model="formMess.longitude"></input>
+				<input name="input" v-model="longitude"></input>
 			</view>
 			<view class="form-item">
-				<view class="title"><text class="necessary">*</text>维度:</view>
-				<input name="input" v-model="formMess.latitude"></input>
+				<view class="title"><text class="necessary">*</text>纬度:</view>
+				<input name="input" v-model="latitude"></input>
+			</view>
+			<view class="form-item">
+				<view class="title"></view>
+				<button class=" cu-btn " style="padding:10rpx 20rpx"  @click="getLocation()">
+					<image src="../../static/nav-icon.png" style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
+					获取当前经纬度
+				</button>
 			</view>
 			<view class="form-item">
 				<view class="title"><text class="necessary">*</text>联系人:</view>
-				<input name="input" v-model="formMess.userName"></input>
+				<input name="input" v-model="userName"></input>
 			</view>
 			<view class="form-item">
 				<view class="title"><text class="necessary">*</text>手机号码:</view>
-				<input name="input" v-model="formMess.phone"></input>
-			</view>
-
+				<input name="input" v-model="phone"></input>
+			</view>
+			
 
 			<view class="btn-area submitBottomBtn padding-lr-sm">
 				<button class="bg-blue round  margin-top" @click="addSubmit">提 交 </button>
@@ -56,9 +63,16 @@
 				<input name="input" v-model="siteMessage.longitude"></input>
 			</view>
 			<view class="form-item">
-				<view class="title">度:</view>
+				<view class="title">度:</view>
 				<input name="input" v-model="siteMessage.latitude"></input>
 			</view>
+			<!-- <view class="form-item">
+				<view class="title"></view>
+				<button class=" cu-btn " style="padding:10rpx 20rpx"  @click="getLocation2()">
+					<image src="../../static/nav-icon.png" style="width:25rpx;height:25rpx;margin-right:26rpx"></image>
+					获取当前经纬度
+				</button>
+			</view> -->
 			<view class="form-item">
 				<view class="title">联系人:</view>
 				<input name="input" v-model="siteMessage.userName"></input>
@@ -77,20 +91,21 @@
 	</view>
 </template>
 
-<script>
+<script>
+	//引入js sdk的封装
+	import * as jwx from '../../util/jssdk.js'
+	
 	export default {
 		data() {
 			return {
 				
-				id: 0,
-				formMess: {
-					"siteName": "",
-					"userName": "",
-					"phone": "",
-					"address": "",
-					"longitude": "",
-					"latitude": "",
-				},
+				id: 0,
+				latitude: "",
+				siteName: "",
+				userName: "",
+				phone: "",
+				address: "",
+				longitude: "",
 				siteMessage:{}
 			}
 		},
@@ -107,69 +122,78 @@
 					title: '站点新增'
 				});
 			}
-			 // this.getLocation()
+			 
 		},
 
 		methods: {
 			
 			getLocation(){
-				alert(1)
-				uni.getLocation({
-					
-				    type: 'wgs84',
-				    success: function (res) {
-						alert(2)
-				        console.log('当前位置的经度:' + res.longitude);
-				        console.log('当前位置的纬度:' + res.latitude);
-				    }
+				// 将this赋值给that
+				let that = this
+				// 微信公众号获取位置
+				jwx.configWeiXin(jweixin => {
+					wx.getLocation({
+					  type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
+					  success: function (res) {
+					    // var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
+					    // var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
+					    // var speed = res.speed; // 速度,以米/每秒计
+					    // var accuracy = res.accuracy; // 位置精度
+						
+						that.longitude=res.longitude
+						that.latitude=res.latitude
+					  }
+					});
 				});
-			},
+			},
+			
+			
 
 			//新增验证并提交
 			addSubmit() {
-				if (!this.formMess.siteName) {
+				if (!this.siteName) {
 					uni.showToast({
 						title: "请输入站点名称...",
 						icon: "none"
 					});
 					return
 				}
-				if (!this.formMess.address) {
+				if (!this.address) {
 					uni.showToast({
 						title: "请输入地址...",
 						icon: "none"
 					});
 					return
 				}
-				if (!this.formMess.longitude) {
+				if (!this.longitude) {
 					uni.showToast({
 						title: "请输入经度...",
 						icon: "none"
 					});
 					return
 				}
-				if (!this.formMess.latitude) {
+				if (!this.latitude) {
 					uni.showToast({
 						title: "请输入纬度...",
 						icon: "none"
 					});
 					return
 				}
-				if (!this.formMess.userName) {
+				if (!this.userName) {
 					uni.showToast({
 						title: "请输入联系人...",
 						icon: "none"
 					});
 					return
 				}
-				if (!this.formMess.phone) {
+				if (!this.phone) {
 					uni.showToast({
 						title: "请输入手机号码...",
 						icon: "none"
 					});
 					return
 				}
-				if (!/^1[345678]\d{9}$/.test(this.formMess.phone)){
+				if (!/^1[345678]\d{9}$/.test(this.phone)){
 					uni.showToast({
 						title: "请输入正确的手机号码...",
 						icon:"none"
@@ -177,12 +201,12 @@
 					return
 				 }
 				this.getAddSite({
-					"siteName": this.formMess.siteName,
-					"userName": this.formMess.userName,
-					"phone": this.formMess.phone,
-					"address": this.formMess.address,
-					"longitude": this.formMess.longitude,
-					"latitude": this.formMess.latitude
+					"siteName": this.siteName,
+					"userName": this.userName,
+					"phone": this.phone,
+					"address": this.address,
+					"longitude": this.longitude,
+					"latitude": this.latitude
 				})
 			},
 			

文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/app-plus/app-config-service.js


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/app-plus/app-service.js


文件差异内容过多而无法显示
+ 52 - 52
unpackage/dist/dev/app-plus/app-view.js


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/app-plus/manifest.json


+ 9 - 3
util/api.js

@@ -1,7 +1,7 @@
-// const BASE_URL = 'https://iot.usky.cn/USKYOF/USKYOF.php/Home/'   //(测试域名)
-const BASE_URL='https://qhome.usky.cn/USKYOF/USKYOF.php/Home/'
+const BASE_URL = 'https://iot.usky.cn/USKYOF/USKYOF.php/Home/'   //(测试域名)
+// const BASE_URL='https://qhome.usky.cn/USKYOF/USKYOF.php/Home/'
 // 同时发送异步代码的次数,防止一次点击中有多次请求,用于处理
-let ajaxTimes = 0;
+let ajaxTimes = 0;
 
 export const myRequest = (options) => {
 
@@ -63,4 +63,10 @@ export const myRequest = (options) => {
 }
 
 
+export default {
+	    BASE_URL
+						
+}
+
+
 

+ 11 - 2
util/jssdk.js

@@ -1,12 +1,20 @@
+import BASE_URL from './api.js';
+
 // jwx.js
 //#ifdef H5
 const jweixin = require('jweixin-module')
 //#endif
 export function configWeiXin(callback) {
 	const url = window.location.href.split('#')[0];
+	console.log(111)
+	console.log(BASE_URL.BASE_URL)
 	// start
 	uni.request({
-		url:"https://qhome.usky.cn/sign.php",		
+		url:"https://qhome.usky.cn/sign.php",	
+		// url:"http://s.yxin.tech/sign.php",
+		
+		
+		// url:`${BASE_URL.BASE_URL}sign.php`,		
 		header: {
 			'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
 		},
@@ -17,7 +25,8 @@ export function configWeiXin(callback) {
 			console.log(res)
 
 			let apiList = [ // 可能需要用到的能力 需要啥就写啥。多写也没有坏处
-				'openLocation'
+				'openLocation',
+				'getLocation'
 			];
 			let info = {
 				debug: false, // 调试,发布的时候改为false

部分文件因为文件数量过多而无法显示