运维小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/device/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. devicedata:[],
  9. latitude:'',
  10. longitude:'',
  11. accuracy:'',
  12. array:['南山','临平','其他'],
  13. index:0
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady() {
  24. this.getdevice()
  25. },
  26. getdevice(){
  27. let data = {
  28. }
  29. api.request(`/device/selectdevice`, 'POST',data)
  30. .then((res) => {
  31. console.log(res);
  32. if (res.code==200) {
  33. for (let index = 0; index < res.data.length; index++) {
  34. if (res.data[index].devicesLatitudelongitude) {
  35. res.data[index].devicesLatitudelongitude=res.data[index].devicesLatitudelongitude.split(",")
  36. }
  37. }
  38. this.setData({
  39. devicedata : res.data
  40. })
  41. }
  42. })
  43. .catch((err) => {
  44. console.error('请求失败:', err);
  45. // 在这里处理请求失败的情况
  46. });
  47. },
  48. // 设置当前经纬度
  49. // 提取获取位置的具体逻辑
  50. getLocation(e) {
  51. console.log(e.target.dataset.id);
  52. const that = this;
  53. wx.getLocation({
  54. type: 'wgs84',
  55. isHighAccuracy:true,
  56. success: (res) => {
  57. console.log('位置获取成功:', res);
  58. that.setData({
  59. latitude: res.latitude,
  60. longitude: res.longitude,
  61. accuracy:res.accuracy
  62. });
  63. console.log(this.data.latitude);
  64. console.log(this.data.longitude);
  65. that.getpositioning(res.longitude,res.latitude,e.target.dataset.id);
  66. },
  67. fail: (err) => {
  68. console.error('获取位置失败:', err);
  69. wx.showToast({
  70. title: '获取位置失败,请重试',
  71. icon: 'none'
  72. });
  73. }
  74. })},
  75. getpositioning(latitude,longitude,id){
  76. let data = {
  77. deviceId:id,
  78. latitudelongitude:latitude+','+longitude
  79. }
  80. api.request(`/device/updatelatit`, 'POST',data)
  81. .then((res) => {
  82. console.log(res);
  83. if (res.code==200) {
  84. wx.showToast({
  85. title: '位置获取成功',
  86. icon: 'none'
  87. });
  88. this.getdevice()
  89. }
  90. })
  91. .catch((err) => {
  92. console.error('请求失败:', err);
  93. // 在这里处理请求失败的情况
  94. });
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow() {
  100. },
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide() {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload() {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh() {
  115. },
  116. /**
  117. * 页面上拉触底事件的处理函数
  118. */
  119. onReachBottom() {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage() {
  125. }
  126. })