|
@@ -1,3 +1,6 @@ |
|
|
|
|
|
import request from '../../utils/request'; |
|
|
|
|
|
import { fenApi } from '../../api/core'; |
|
|
|
|
|
import { getBaseUrl } from '../../utils/utilsServes'; |
|
|
// pages/home/home.js |
|
|
// pages/home/home.js |
|
|
Page({ |
|
|
Page({ |
|
|
|
|
|
|
|
@@ -5,10 +8,13 @@ Page({ |
|
|
* 页面的初始数据 |
|
|
* 页面的初始数据 |
|
|
*/ |
|
|
*/ |
|
|
data: { |
|
|
data: { |
|
|
wlanList: [ |
|
|
|
|
|
], //当前wlan列表 |
|
|
|
|
|
|
|
|
wlanList: [], //当前wlan列表 |
|
|
isConnectWlan: null, //是否已经连接上WLAN |
|
|
isConnectWlan: null, //是否已经连接上WLAN |
|
|
connectWlanBssid: '', //当前连接WLAN的SSID |
|
|
|
|
|
|
|
|
connectWlanBssid: '', //当前连接WLAN的BSSID |
|
|
|
|
|
imei: '', //设备imei |
|
|
|
|
|
fenceId: '', //围栏id |
|
|
|
|
|
appType: '', //应用类型 |
|
|
|
|
|
env: '', //运行环境 |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -16,14 +22,64 @@ Page({ |
|
|
*/ |
|
|
*/ |
|
|
onLoad: function (options) { |
|
|
onLoad: function (options) { |
|
|
this.onStartWifi(); |
|
|
this.onStartWifi(); |
|
|
|
|
|
this.checkOptions(options); |
|
|
|
|
|
this.getAuth(); |
|
|
|
|
|
}, |
|
|
|
|
|
onHide() { |
|
|
|
|
|
// 点击小程序右上角的关闭按钮时清空authToken |
|
|
|
|
|
wx.removeStorage({ |
|
|
|
|
|
key: 'authToken', |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
// 获取token |
|
|
|
|
|
getAuth() { |
|
|
|
|
|
// 获取token时有token清空token,防止获取token接口的时候带上token |
|
|
|
|
|
if(wx.getStorageSync('authToken')) { |
|
|
|
|
|
wx.removeStorage({ |
|
|
|
|
|
key: 'authToken' |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
const manufactorId = "2cae99d6-0475-42fe-9fa7-ca27e03077de"; |
|
|
|
|
|
const baseUrl = getBaseUrl(this.data.env); |
|
|
|
|
|
const requestUrl = baseUrl + fenApi.getAuth; |
|
|
|
|
|
request.post(requestUrl, { |
|
|
|
|
|
manufactorId: manufactorId |
|
|
|
|
|
}).then(res => { |
|
|
|
|
|
if( res.code === 0 ) { |
|
|
|
|
|
// 先清除原来token,再把新token存在来 |
|
|
|
|
|
if(wx.getStorageSync('authToken')) { |
|
|
|
|
|
wx.removeStorage('authToken'); |
|
|
|
|
|
} |
|
|
|
|
|
wx.setStorage({ |
|
|
|
|
|
key: "authToken", |
|
|
|
|
|
data: res.data, |
|
|
|
|
|
}) |
|
|
|
|
|
}; |
|
|
|
|
|
}).catch(error => { |
|
|
|
|
|
console.log("error", error); |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
// 检查并获取从微信公众号传过来的参数 |
|
|
|
|
|
checkOptions(options) { |
|
|
// todo 获取从微信公众号跳转的参数 |
|
|
// todo 获取从微信公众号跳转的参数 |
|
|
|
|
|
if(JSON.stringify(options) === '{}') { |
|
|
|
|
|
console.log("当前页面无携带参数"); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("存在参数", options); |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
imei: options.imei, |
|
|
|
|
|
fenceId: options.fenceId, |
|
|
|
|
|
appType: options.appType, |
|
|
|
|
|
env: options.env |
|
|
|
|
|
}); |
|
|
|
|
|
}; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
*/ |
|
|
*/ |
|
|
onReady: function () { |
|
|
onReady: function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -33,13 +89,6 @@ Page({ |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 生命周期函数--监听页面隐藏 |
|
|
|
|
|
*/ |
|
|
|
|
|
onHide: function () { |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 生命周期函数--监听页面卸载 |
|
|
* 生命周期函数--监听页面卸载 |
|
|
*/ |
|
|
*/ |
|
@@ -81,8 +130,7 @@ Page({ |
|
|
onStartWifi() { |
|
|
onStartWifi() { |
|
|
let that = this; |
|
|
let that = this; |
|
|
wx.startWifi({ |
|
|
wx.startWifi({ |
|
|
success(res) { |
|
|
|
|
|
console.log("成功", res.errMsg); |
|
|
|
|
|
|
|
|
success() { |
|
|
that.getWifiList(); |
|
|
that.getWifiList(); |
|
|
}, |
|
|
}, |
|
|
fail(res) { |
|
|
fail(res) { |
|
@@ -91,13 +139,6 @@ Page({ |
|
|
title: '温馨提示', |
|
|
title: '温馨提示', |
|
|
content: `当前用户未打开WIFI和GPS`, |
|
|
content: `当前用户未打开WIFI和GPS`, |
|
|
showCancel: false, |
|
|
showCancel: false, |
|
|
success(res) { |
|
|
|
|
|
if (res.confirm) { |
|
|
|
|
|
console.log('用户点击确定'); |
|
|
|
|
|
} else if (res.cancel) { |
|
|
|
|
|
console.log('用户点击取消'); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@@ -107,7 +148,6 @@ Page({ |
|
|
let that = this; |
|
|
let that = this; |
|
|
wx.getConnectedWifi({ |
|
|
wx.getConnectedWifi({ |
|
|
success(res) { |
|
|
success(res) { |
|
|
console.log(res); |
|
|
|
|
|
if(res) { |
|
|
if(res) { |
|
|
// 如果已经连接上WLAN |
|
|
// 如果已经连接上WLAN |
|
|
that.setData({ |
|
|
that.setData({ |
|
@@ -127,6 +167,8 @@ Page({ |
|
|
// 刷新 |
|
|
// 刷新 |
|
|
onRefresh() { |
|
|
onRefresh() { |
|
|
this.getWifiList(); |
|
|
this.getWifiList(); |
|
|
|
|
|
this.getAuth(); |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
// 搜索不到WLAN |
|
|
// 搜索不到WLAN |
|
|
onHelp() { |
|
|
onHelp() { |
|
@@ -139,23 +181,50 @@ Page({ |
|
|
// 保存WLAN信息 |
|
|
// 保存WLAN信息 |
|
|
onSave(value) { |
|
|
onSave(value) { |
|
|
const currentWlanInfo = value.currentTarget.dataset.name; |
|
|
const currentWlanInfo = value.currentTarget.dataset.name; |
|
|
console.log("当前点击的WLAN信息", currentWlanInfo); |
|
|
|
|
|
|
|
|
let that = this; |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
title: '温馨提示', |
|
|
title: '温馨提示', |
|
|
content: `当前选中WLANBSSID是: |
|
|
|
|
|
${currentWlanInfo.BSSID} |
|
|
|
|
|
|
|
|
content: `当前选中WLAN是: |
|
|
|
|
|
${currentWlanInfo.SSID} |
|
|
`, |
|
|
`, |
|
|
cancelText: '关闭', |
|
|
cancelText: '关闭', |
|
|
confirmText: '复制', |
|
|
|
|
|
|
|
|
confirmText: that.data.fenceId ? `选择` : `复制`, |
|
|
success: (res) => { |
|
|
success: (res) => { |
|
|
if (res.confirm) { |
|
|
|
|
|
|
|
|
if (res.confirm && that.data.fenceId) { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '设置中', |
|
|
|
|
|
icon: 'loading' |
|
|
|
|
|
}) |
|
|
|
|
|
let reqBody = { |
|
|
|
|
|
imei: this.data.imei, |
|
|
|
|
|
fenceId: this.data.fenceId, |
|
|
|
|
|
wifiInfo: currentWlanInfo.BSSID |
|
|
|
|
|
}; |
|
|
|
|
|
// 请求url分为:基础url + 接口Url |
|
|
|
|
|
const baseUrl = getBaseUrl(this.data.env); |
|
|
|
|
|
const requestUrl = baseUrl + fenApi.bindFenceWifi; |
|
|
|
|
|
request.post(requestUrl, { |
|
|
|
|
|
...reqBody, |
|
|
|
|
|
}).then(() => { |
|
|
|
|
|
wx.showToast({ |
|
|
|
|
|
title: '设置成功', |
|
|
|
|
|
icon: 'success' |
|
|
|
|
|
}) |
|
|
|
|
|
}).catch(() => { |
|
|
|
|
|
wx.hideToast(); |
|
|
|
|
|
wx.showModal({ |
|
|
|
|
|
title: '温馨提示', |
|
|
|
|
|
content: '出错了,请您点击刷新按钮重新刷新页面后再重新设置', |
|
|
|
|
|
showCancel: false |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
wx.setClipboardData({ |
|
|
wx.setClipboardData({ |
|
|
data: `${currentWlanInfo.BSSID}`, |
|
|
data: `${currentWlanInfo.BSSID}`, |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
// todo 调取接口 |
|
|
|
|
|
}, |
|
|
}, |
|
|
// 获取当前连接的周边的wifi列表 |
|
|
// 获取当前连接的周边的wifi列表 |
|
|
getWifiList() { |
|
|
getWifiList() { |
|
@@ -167,7 +236,6 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
wx.getWifiList({ |
|
|
wx.getWifiList({ |
|
|
success(res) { |
|
|
success(res) { |
|
|
console.log("getWifiList", res); |
|
|
|
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
title: '获取成功', |
|
|
title: '获取成功', |
|
@@ -198,7 +266,6 @@ Page({ |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
fail(res) { |
|
|
fail(res) { |
|
|
console.log(res.errMsg); |
|
|
|
|
|
wx.hideLoading(); |
|
|
wx.hideLoading(); |
|
|
wx.showModal({ |
|
|
wx.showModal({ |
|
|
title: '温馨提示', |
|
|
title: '温馨提示', |
|
|