Bläddra i källkod

## 功能更新

- 更新内容
        - A 增加获取授权和保存WIFIBSSID信息接口
feat
JinxChen 1 år sedan
förälder
incheckning
c3cedf6110
8 ändrade filer med 182 tillägg och 33 borttagningar
  1. +8
    -0
      miniprogram/api/core.js
  2. +2
    -1
      miniprogram/app.json
  3. +1
    -1
      miniprogram/model/index.js
  4. +96
    -29
      miniprogram/pages/home/home.js
  5. +16
    -2
      miniprogram/project.private.config.json
  6. +13
    -0
      miniprogram/readme.md
  7. +39
    -0
      miniprogram/utils/request.js
  8. +7
    -0
      miniprogram/utils/utilsServes.js

+ 8
- 0
miniprogram/api/core.js Visa fil

@@ -0,0 +1,8 @@

const fenApi = {
getAuth: '/gateway/core/api/v1/Ability/study_ai/terminal/auth', //获取token
bindFenceWifi: '/gateway/core/api/v1/OpenFence/BindFenceWifi', //获取WIFI的BSSID并保存
}
module.exports = {
fenApi
}

+ 2
- 1
miniprogram/app.json Visa fil

@@ -38,5 +38,6 @@
"downloadFile": 10000
},
"debug": true,
"sitemapLocation": "sitemap.json"
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
}

+ 1
- 1
miniprogram/model/index.js Visa fil

@@ -1 +1 @@
export const VersionModel = '2.0.0F';
export const VersionModel = '2.0.1F';

+ 96
- 29
miniprogram/pages/home/home.js Visa fil

@@ -1,3 +1,6 @@
import request from '../../utils/request';
import { fenApi } from '../../api/core';
import { getBaseUrl } from '../../utils/utilsServes';
// pages/home/home.js
Page({

@@ -5,10 +8,13 @@ Page({
* 页面的初始数据
*/
data: {
wlanList: [
], //当前wlan列表
wlanList: [], //当前wlan列表
isConnectWlan: null, //是否已经连接上WLAN
connectWlanBssid: '', //当前连接WLAN的SSID
connectWlanBssid: '', //当前连接WLAN的BSSID
imei: '', //设备imei
fenceId: '', //围栏id
appType: '', //应用类型
env: '', //运行环境
},

/**
@@ -16,14 +22,64 @@ Page({
*/
onLoad: function (options) {
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 获取从微信公众号跳转的参数
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 () {

},

/**
@@ -33,13 +89,6 @@ Page({

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
@@ -81,8 +130,7 @@ Page({
onStartWifi() {
let that = this;
wx.startWifi({
success(res) {
console.log("成功", res.errMsg);
success() {
that.getWifiList();
},
fail(res) {
@@ -91,13 +139,6 @@ Page({
title: '温馨提示',
content: `当前用户未打开WIFI和GPS`,
showCancel: false,
success(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
});
@@ -107,7 +148,6 @@ Page({
let that = this;
wx.getConnectedWifi({
success(res) {
console.log(res);
if(res) {
// 如果已经连接上WLAN
that.setData({
@@ -127,6 +167,8 @@ Page({
// 刷新
onRefresh() {
this.getWifiList();
this.getAuth();

},
// 搜索不到WLAN
onHelp() {
@@ -139,23 +181,50 @@ Page({
// 保存WLAN信息
onSave(value) {
const currentWlanInfo = value.currentTarget.dataset.name;
console.log("当前点击的WLAN信息", currentWlanInfo);
let that = this;
wx.showModal({
title: '温馨提示',
content: `当前选中WLANBSSID是:
${currentWlanInfo.BSSID}
content: `当前选中WLAN是:
${currentWlanInfo.SSID}
`,
cancelText: '关闭',
confirmText: '复制',
confirmText: that.data.fenceId ? `选择` : `复制`,
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({
data: `${currentWlanInfo.BSSID}`,
})
}
}
})
// todo 调取接口
},
// 获取当前连接的周边的wifi列表
getWifiList() {
@@ -167,7 +236,6 @@ Page({
});
wx.getWifiList({
success(res) {
console.log("getWifiList", res);
wx.hideLoading();
wx.showToast({
title: '获取成功',
@@ -198,7 +266,6 @@ Page({
});
},
fail(res) {
console.log(res.errMsg);
wx.hideLoading();
wx.showModal({
title: '温馨提示',


+ 16
- 2
miniprogram/project.private.config.json Visa fil

@@ -1,7 +1,21 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "miniprogramParentWeb",
"projectname": "miniprogram",
"setting": {
"compileHotReLoad": true
"compileHotReLoad": true,
"urlCheck": false
},
"condition": {
"miniprogram": {
"list": [
{
"name": "",
"pathName": "pages/home/home",
"query": "imei=861281060007642&fenceId=a29c0f2d-9943-4e70-9a0e-efc00dc87d07&appType=0&env=test",
"launchMode": "default",
"scene": null
}
]
}
}
}

+ 13
- 0
miniprogram/readme.md Visa fil

@@ -0,0 +1,13 @@
- 2.0.0
- 2022.11.16
## 重构小程序
- 重构内容
- A 增加 获取用户wifi信息功能
- A 增加 版本控制

- 2.0.1
- 2022.12.16
## 功能更新
- 更新内容
- A 增加获取授权和保存WIFIBSSID信息接口


+ 39
- 0
miniprogram/utils/request.js Visa fil

@@ -0,0 +1,39 @@
const app = getApp()

// 封装wx.request请求
const request = (url, options) => {
return new Promise((resolve, reject) => {
wx.request({
url: `${url}`,
method: options.method,
data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
header: {
'AccessToken': wx.getStorageSync('authToken')
},
// AccessToken
success(request) {
if (request.data.code === 0) {
resolve(request.data)
} else {
reject(request.data)
}
},
fail(error) {
reject(error.data)
}
})
})
}

const get = (url, options = {}) => {
return request(url, { method: 'GET', data: options })
}

const post = (url, options) => {
return request(url, { method: 'POST', data: options })
}

module.exports = {
get,
post,
}

+ 7
- 0
miniprogram/utils/utilsServes.js Visa fil

@@ -0,0 +1,7 @@

//根据传入的参数返回不同环境的baseUrl
function getBaseUrl(str) {
return str === 'test' ? 'https://id.ssjlai.com' : 'https://ai.ssjlai.com';
}

module.exports.getBaseUrl = getBaseUrl;

Laddar…
Avbryt
Spara