| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- // pages/device/index.js
- const api = require('../../api/index.js');
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- devicedata:[],
- latitude:'',
- longitude:'',
- accuracy:'',
- array:['南山','临平','其他'],
- index:0
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
-
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- this.getdevice()
- },
- getdevice(){
- let data = {
- }
- api.request(`/device/selectdevice`, 'POST',data)
- .then((res) => {
- console.log(res);
- if (res.code==200) {
-
- for (let index = 0; index < res.data.length; index++) {
- if (res.data[index].devicesLatitudelongitude) {
-
- res.data[index].devicesLatitudelongitude=res.data[index].devicesLatitudelongitude.split(",")
- }
- }
- this.setData({
- devicedata : res.data
- })
- }
-
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 设置当前经纬度
- // 提取获取位置的具体逻辑
- getLocation(e) {
- console.log(e.target.dataset.id);
- const that = this;
- wx.getLocation({
- type: 'wgs84',
- isHighAccuracy:true,
- success: (res) => {
- console.log('位置获取成功:', res);
- that.setData({
- latitude: res.latitude,
- longitude: res.longitude,
- accuracy:res.accuracy
- });
- console.log(this.data.latitude);
- console.log(this.data.longitude);
- that.getpositioning(res.longitude,res.latitude,e.target.dataset.id);
- },
- fail: (err) => {
- console.error('获取位置失败:', err);
- wx.showToast({
- title: '获取位置失败,请重试',
- icon: 'none'
- });
- }
- })},
- getpositioning(latitude,longitude,id){
- let data = {
- deviceId:id,
- latitudelongitude:latitude+','+longitude
- }
- api.request(`/device/updatelatit`, 'POST',data)
- .then((res) => {
- console.log(res);
- if (res.code==200) {
- wx.showToast({
- title: '位置获取成功',
- icon: 'none'
- });
- this.getdevice()
-
- }
-
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|