@@ -1,3 +0,0 @@ | |||
{ | |||
"editor.emptySelectionClipboard": false | |||
} |
@@ -1,12 +1,12 @@ | |||
# 云开发 quickstart | |||
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力: | |||
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库 | |||
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理 | |||
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码 | |||
## 参考文档 | |||
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html) | |||
# 项目背景 | |||
- 该微信小程序主要用来获取用户wifi的BSSID信息,通过wifi的BSSID配合公众号号的围栏功能,使围栏告警更加准确。 | |||
- 主要流程:公众号/h5携带围栏信息-》跳转到此小程序-》小程序获取用户相关wifi信息-》保存wifi信息。 | |||
- 因功能单一,现主要采用小程序原生开发,后续有需要再使用其它框架迭代 | |||
# 版本管理 | |||
## 2.0.0 | |||
`2022.11.16` | |||
- 重构小程序 | |||
- 重构内容 | |||
1. A增加 获取用户wifi信息功能 | |||
2. A 增加 版本控制 | |||
@@ -1,19 +1,2 @@ | |||
//app.js | |||
App({ | |||
onLaunch: function () { | |||
if (!wx.cloud) { | |||
console.error('请使用 2.2.3 或以上的基础库以使用云能力') | |||
} else { | |||
wx.cloud.init({ | |||
// env 参数说明: | |||
// env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 | |||
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看 | |||
// 如不填则使用默认环境(第一个创建的环境) | |||
env: 'cloud1-7g8hw3qu242eeb5f', | |||
traceUser: true, //将用户访问记录到用户管理中 | |||
}) | |||
} | |||
this.globalData = {} | |||
} | |||
}) | |||
App({}) |
@@ -1,8 +1,6 @@ | |||
{ | |||
"pages": [ | |||
"pages/home/home", | |||
"pages/list/list", | |||
"pages/partner/partner", | |||
"pages/more/more" | |||
], | |||
"permission": { | |||
@@ -13,7 +11,7 @@ | |||
"window": { | |||
"backgroundTextStyle": "dark", | |||
"navigationBarBackgroundColor": "#1772cb", | |||
"navigationBarTitleText": "发不好看", | |||
"navigationBarTitleText": "随手精灵", | |||
"navigationBarTextStyle": "white" | |||
}, | |||
"tabBar": { | |||
@@ -28,10 +26,10 @@ | |||
"text": "首页" | |||
}, | |||
{ | |||
"pagePath": "pages/list/list", | |||
"iconPath": "images/icon/icon_list.png", | |||
"selectedIconPath": "images/icon/icon_list_active.png", | |||
"text": "列表" | |||
"pagePath": "pages/more/more", | |||
"iconPath": "images/icon/icon_more.png", | |||
"selectedIconPath": "images/icon/icon_more_active.png", | |||
"text": "更多" | |||
} | |||
] | |||
}, | |||
@@ -40,8 +38,5 @@ | |||
"downloadFile": 10000 | |||
}, | |||
"debug": true, | |||
"navigateToMiniProgramAppIdList": [ | |||
"wx64cc3af90544c0cd" | |||
], | |||
"sitemapLocation": "sitemap45.json" | |||
"sitemapLocation": "sitemap.json" | |||
} |
@@ -0,0 +1 @@ | |||
export const VersionModel = '2.0.0F'; |
@@ -5,36 +5,18 @@ Page({ | |||
* 页面的初始数据 | |||
*/ | |||
data: { | |||
wifiList: [ | |||
/* {SSID: '114141111', BSSID: '141142424151215'}, | |||
{SSID: '11414111', BSSID: '1441421411215'} */ | |||
], //当前wifi列表 | |||
wlanList: [ | |||
], //当前wlan列表 | |||
isConnectWlan: null, //是否已经连接上WLAN | |||
connectWlanBssid: '', //当前连接WLAN的SSID | |||
}, | |||
/** | |||
* 生命周期函数--监听页面加载 | |||
*/ | |||
onLoad: function (options) { | |||
// 加载wifi模板 | |||
wx.startWifi({ | |||
success(res) { | |||
console.log("成功", res.errMsg); | |||
}, | |||
fail(res) { | |||
console.log("失败", res.errMsg); | |||
wx.showModal({ | |||
title: '温馨提示', | |||
content: '请打开WIFI和GPS再操作', | |||
success(res) { | |||
if (res.confirm) { | |||
console.log('用户点击确定'); | |||
} else if (res.cancel) { | |||
console.log('用户点击取消'); | |||
} | |||
} | |||
}) | |||
} | |||
}); | |||
this.onStartWifi(); | |||
// todo 获取从微信公众号跳转的参数 | |||
}, | |||
/** | |||
@@ -95,42 +77,20 @@ Page({ | |||
url: "/pages/list/list", | |||
}) | |||
}, | |||
redirectTo() { | |||
wx.redirectTo({ | |||
url: '/pages/home/imgshow/imgshow' | |||
}) | |||
}, | |||
// 复制周边wifi的bsid | |||
copyWifiBsid(value) { | |||
const wifiBsid = value.currentTarget.dataset.name; | |||
console.log("复制的值::", wifiBsid); | |||
wx.setClipboardData({data: wifiBsid}) | |||
}, | |||
// 获取当前链接的wifi信息 | |||
getConnectedWifi: function () { | |||
wx.getConnectedWifi({ | |||
// 加载wifi模板 | |||
onStartWifi() { | |||
let that = this; | |||
wx.startWifi({ | |||
success(res) { | |||
console.log(res); | |||
const wifiBssid = res.wifi.BSSID; | |||
wx.showModal({ | |||
title: '当前wifiBSSID是', | |||
content: wifiBssid, | |||
confirmText: '复制', | |||
cancelText: '关闭', | |||
success(res) { | |||
if (res.confirm) { | |||
console.log("wifiBssid", wifiBssid); | |||
console.log("复制"); | |||
wx.setClipboardData({data: wifiBssid}) | |||
} | |||
} | |||
}) | |||
console.log("成功", res.errMsg); | |||
that.getWifiList(); | |||
}, | |||
fail(res) { | |||
console.log(res.errMsg); | |||
console.log("失败", res.errMsg); | |||
wx.showModal({ | |||
title: '温馨提示', | |||
content: '请打开WIFI和GPS再操作', | |||
content: `当前用户未打开WIFI和GPS`, | |||
showCancel: false, | |||
success(res) { | |||
if (res.confirm) { | |||
console.log('用户点击确定'); | |||
@@ -140,13 +100,56 @@ Page({ | |||
} | |||
}) | |||
} | |||
}); | |||
}, | |||
// 获取当前链接的wifi信息 | |||
getConnectedWifi: function () { | |||
let that = this; | |||
wx.getConnectedWifi({ | |||
success(res) { | |||
console.log(res); | |||
if(res) { | |||
// 如果已经连接上WLAN | |||
that.setData({ | |||
isConnectWlan: true, | |||
connectWlanBssid: res.wifi.BSSID, | |||
}) | |||
} | |||
}, | |||
fail(res) { | |||
console.log(res.errMsg); | |||
that.setData({ | |||
isConnectWlan: false | |||
}) | |||
} | |||
}) | |||
}, | |||
// 获取周边的wifi列表 | |||
// 刷新 | |||
onRefresh() { | |||
this.getWifiList(); | |||
}, | |||
// 搜索不到WLAN | |||
onHelp() { | |||
wx.showModal({ | |||
title: '温馨提示', | |||
content: `请您前往手机-设置-WLAN,打开WLAN开关并且打开手机的GPS`, | |||
showCancel: false, | |||
}) | |||
}, | |||
// 保存WLAN信息 | |||
onSave(value) { | |||
let that = this; | |||
const currentWlanInfo = value.currentTarget.dataset.name; | |||
console.log("当前点击的WLAN信息", currentWlanInfo); | |||
// todo 调取接口 | |||
}, | |||
// 获取当前连接的周边的wifi列表 | |||
getWifiList() { | |||
let that = this; | |||
// 先获取当前连接的wifi信息 | |||
that.getConnectedWifi(); | |||
wx.showLoading({ | |||
title: '获取中...' | |||
title: '获取中WLAN...' | |||
}); | |||
wx.getWifiList({ | |||
success(res) { | |||
@@ -157,25 +160,36 @@ Page({ | |||
icon: 'success' | |||
}); | |||
wx.onGetWifiList((result) => { | |||
that.setData({ | |||
wifiList: result.wifiList | |||
}) | |||
console.log(result); | |||
}) | |||
// 筛选wifi名称为空的数据 | |||
let wifiList = result.wifiList.filter(item => { | |||
return item.SSID !== ''; | |||
}); | |||
// ,如果有已连接的wifi则将已连接的wifi移动到第一位,否则不做任何操作 | |||
if(that.data.connectWlanBssid !== '') { | |||
//let newWifiList = that.data.wlanList; | |||
// 找到与当前已连接wifi相同bssid数据的下标 | |||
const index = wifiList.findIndex(v => v.BSSID === that.data.connectWlanBssid); | |||
//根据该对象在数组的下标从数组中移出 | |||
const moveObj = wifiList.splice(index, 1); | |||
//把当前数据插入到数据首位 | |||
wifiList.splice(0, 0, ...moveObj); | |||
that.setData({ | |||
wlanList: wifiList | |||
}) | |||
} else { | |||
that.setData({ | |||
wlanList: wifiList | |||
}) | |||
} | |||
}); | |||
}, | |||
fail(res) { | |||
console.log(res.errMsg); | |||
wx.hideLoading(); | |||
wx.showModal({ | |||
title: '温馨提示', | |||
content: '请打开WIFI和GPS再操作', | |||
success(res) { | |||
if (res.confirm) { | |||
console.log('用户点击确定'); | |||
} else if (res.cancel) { | |||
console.log('用户点击取消'); | |||
} | |||
} | |||
content: '当前用户未打开WIFI和GPS', | |||
showCancel: false, | |||
}) | |||
}, | |||
}); | |||
@@ -0,0 +1,3 @@ | |||
{ | |||
"navigationBarTitleText": "首页" | |||
} |
@@ -1,23 +1,31 @@ | |||
<view class="home-container"> | |||
<view class="wifi-list"> | |||
<text class="wifi-title">周边WIFI列表</text> | |||
<view class="wifi-container"> | |||
<view wx:for="{{wifiList}}" wx:key="index"> | |||
<text> WIFI名称:{{wifiList[index].SSID}}</text> | |||
<view> | |||
<text>BSSID:{{wifiList[index].BSSID}}</text> | |||
</view> | |||
<view> | |||
<button size="mini" type="primary" bindtap="copyWifiBsid" data-name="{{wifiList[index].BSSID}}">复制</button> | |||
<!--header --> | |||
<view class="header"> | |||
<text>设备不支持5G类型以及机场,酒店等热点WLAN。如未获取到,请打开WIFI和GPS后刷新页面。点击WLAN名称可查看WLAN信息。</text> | |||
</view> | |||
<!-- list --> | |||
<view class="disable-wlan"> | |||
<text>可用WLAN列表</text> | |||
<button class="disable-wlan-btn" type="primary" size="mini" bindtap="onRefresh" wx:if="{{wlanList.length > 0}}">刷新</button> | |||
</view> | |||
<!-- body --> | |||
<view class="body"> | |||
<view class="wlan-list" wx:if="{{wlanList.length > 0}}"> | |||
<view class="wlan-item" wx:for="{{wlanList}}" wx:key="index"> | |||
<view bindtap="onSave" data-name="{{wlanList[index]}}" class="{{index === 0 && isConnectWlan ? 'isConnect' : ''}}"> | |||
<text class="wlan-item-text" wx:if="{{index === 0 && isConnectWlan}}">(当前手机连接网络)</text> | |||
{{wlanList[index].SSID}} | |||
</view> | |||
</view> | |||
<text wx:if="{{wifiList.length === 0}}"> | |||
无 | |||
</text> | |||
</view> | |||
<view class="wlan-list-empty" wx:else="{{wlanList.length === 0}}"> | |||
<image class="no_wifi" src="../../images/icon/no_wifi.png"></image> | |||
<text bindtap="onHelp">找不到WLAN?</text> | |||
<button type="primary" bindtap="onRefresh">刷新</button> | |||
</view> | |||
</view> | |||
<view class="btn-container"> | |||
<button bindtap="getConnectedWifi" size="mini" class="btn">获取当前链接wifi的信息</button> | |||
<button bindtap="getWifiList" size="mini" class="btn">获取当前周边wifi的信息</button> | |||
<!-- footer --> | |||
<view class="footer"> | |||
<image class="help" src="../../images/icon/help.png"></image><text bindtap="onHelp">搜索不到WLAN</text> | |||
</view> | |||
</view> |
@@ -1,42 +1,96 @@ | |||
/* pages/home/home.wxss.wxss */ | |||
.home-container { | |||
height: 100%; | |||
position: relative; | |||
height: 100vh; | |||
overflow: hidden; | |||
background-color: #f2f4f5; | |||
} | |||
.header { | |||
height: 80px; | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
flex-direction: column; | |||
padding: 0 20px; | |||
background-color: #fff; | |||
font-size: 14px; | |||
color: gray; | |||
} | |||
.picker { | |||
margin: 30px 0; | |||
.disable-wlan { | |||
height: 50px; | |||
line-height: 50px; | |||
margin-top: 15px; | |||
padding: 0 20px; | |||
display: flex; | |||
justify-content: space-between; | |||
align-items: center; | |||
background-color: white; | |||
} | |||
.wifi-list { | |||
.disable-wlan-btn { | |||
width: 120px; | |||
display: flex; | |||
justify-content: space-between; | |||
align-items: center; | |||
} | |||
.refresh-img { | |||
height: 25px; | |||
width: 25px; | |||
} | |||
.body { | |||
height: calc(100vh - 205px); | |||
overflow: auto; | |||
background-color: #f2f4f5; | |||
} | |||
.wlan-list { | |||
flex: 1; | |||
background-color: #f2f4f5; | |||
overflow: auto; | |||
} | |||
.wlan-list-empty { | |||
height: 100%; | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
flex-direction: column; | |||
border: 1px solid; | |||
margin-bottom: 40px; | |||
} | |||
.wifi-title { | |||
width: 100%; | |||
background-color: rgb(245, 238, 238); | |||
text-align: center; | |||
line-height: 40px; | |||
} | |||
.wifi-container { | |||
max-height: 200px; | |||
width: 300px; | |||
text-align: center; | |||
overflow: scroll; | |||
} | |||
.btn-container { | |||
width: 300px; | |||
} | |||
.no_wifi { | |||
height: 80px; | |||
width: 80px; | |||
margin-bottom: 10px; | |||
opacity: .6; | |||
} | |||
button { | |||
width: 120px; | |||
margin: 10px 0; | |||
} | |||
.wlan-item { | |||
height: 65px; | |||
line-height: 65px; | |||
padding-left: 20px; | |||
margin: 5px 0; | |||
background-color: #fff; | |||
white-space: nowrap; | |||
overflow-y: hidden; | |||
} | |||
.wlan-item-text { | |||
font-size: 14px; | |||
} | |||
.isConnect { | |||
color: #2599ff; | |||
} | |||
.footer { | |||
height: 55px; | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
flex-direction: column; | |||
color: #2599ff; | |||
background-color: #fff; | |||
position: absolute; | |||
bottom: 5px; | |||
left: 0; | |||
right: 0; | |||
} | |||
.btn { | |||
height: 40px; | |||
width: 100%; | |||
.help { | |||
height: 25px; | |||
width: 25px; | |||
margin-right: 5px; | |||
} |
@@ -1,114 +0,0 @@ | |||
// pages/list/list.js | |||
Page({ | |||
/** | |||
* 页面的初始数据 | |||
*/ | |||
data: { | |||
dataArr: [ | |||
{name: '1冥', age: 16, className: '阿瑟斯s1'}, | |||
{name: '2冥', age: 26, className: '阿瑟斯s2'}, | |||
{name: '3冥', age: 36, className: '阿瑟斯s3'}, | |||
{name: '4冥', age: 46, className: '阿瑟斯s4'}, | |||
], | |||
isShow: true, | |||
imgUrls: [ | |||
'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640', | |||
'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640', | |||
'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640' | |||
], | |||
interval: 5000, | |||
duration: 1000, | |||
indicatorDots: true, | |||
indicatorColor: "#ffffff", | |||
activecolor:"#2971f6", | |||
autoplay: true, | |||
count: 'count', | |||
nowTime: new Date().toLocaleDateString(), | |||
url: '', | |||
}, | |||
/** | |||
* 生命周期函数--监听页面加载 | |||
*/ | |||
onLoad: function (options) { | |||
wx.startWifi({ | |||
success (res) { | |||
console.log("成功", res.errMsg); | |||
}, | |||
fail(res) { | |||
console.log("失败", res.errMsg); | |||
} | |||
}); | |||
}, | |||
/** | |||
* 生命周期函数--监听页面初次渲染完成 | |||
*/ | |||
onReady: function () { | |||
}, | |||
/** | |||
* 生命周期函数--监听页面显示 | |||
*/ | |||
onShow: function () { | |||
}, | |||
/** | |||
* 生命周期函数--监听页面隐藏 | |||
*/ | |||
onHide: function () { | |||
}, | |||
// 跳转h5测试 | |||
jumph5() { | |||
let id = 'test';//需要发送到H5页面的参数 | |||
wx.navigateTo({ | |||
//测试时可以用本地IP地址进行跳转(上线时换为线上的真实IP地址) | |||
url:`https://id.ssjlai.com/parentweb/#/index?id=${id}`, | |||
}) | |||
}, | |||
/** | |||
* 生命周期函数--监听页面卸载 | |||
*/ | |||
onUnload: function () { | |||
}, | |||
/** | |||
* 页面相关事件处理函数--监听用户下拉动作 | |||
*/ | |||
onPullDownRefresh: function () { | |||
}, | |||
/** | |||
* 页面上拉触底事件的处理函数 | |||
*/ | |||
onReachBottom: function () { | |||
}, | |||
/** | |||
* 用户点击右上角分享 | |||
*/ | |||
onShareAppMessage: function () { | |||
}, | |||
/* | |||
注册点击事件 | |||
*/ | |||
onClickCount: function() { | |||
wx.getConnectedWifi({ | |||
success (res) { | |||
console.log(res); | |||
}, | |||
fail(res) { | |||
console.log(res.errMsg); | |||
} | |||
}) | |||
} | |||
}) |
@@ -1,9 +0,0 @@ | |||
<view class="list-container"> | |||
<text> | |||
现在是: {{nowTime}} | |||
</text> | |||
<view> | |||
<web-view src="{{ url }}"></web-view> | |||
</view> | |||
<button bindtap="jumph5" size="mini" class="btn">跳转h5测试</button> | |||
</view> |
@@ -1,11 +1,12 @@ | |||
// pages/more/more.js | |||
import { VersionModel } from '../../model/index' | |||
Page({ | |||
/** | |||
* 页面的初始数据 | |||
*/ | |||
data: { | |||
version: VersionModel, //版本号 | |||
}, | |||
/** | |||
@@ -0,0 +1,3 @@ | |||
{ | |||
"navigationBarTitleText": "更多" | |||
} |
@@ -1,2 +1,4 @@ | |||
<!--pages/more/more.wxml--> | |||
<text>更多</text> | |||
<view class="more-container"> | |||
<text>当前小程序版本号:{{version}}</text> | |||
</view> |
@@ -1,8 +1,7 @@ | |||
.list-container { | |||
.more-container { | |||
height: 100%; | |||
padding: 10px; | |||
width: 100%; | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
flex-direction: column; | |||
} |
@@ -1,91 +0,0 @@ | |||
Page({ | |||
data: { | |||
userInfo: {}, | |||
hasUserInfo: false, | |||
canIUseGetUserProfile: false, | |||
array: ['美国', '中国', '巴西', '日本'], | |||
index: 0 | |||
}, | |||
onLoad() { | |||
if (wx.getUserProfile) { | |||
this.setData({ | |||
canIUseGetUserProfile: true | |||
}) | |||
} | |||
}, | |||
getUserProfile(e) { | |||
// 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 | |||
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 | |||
wx.getUserProfile({ | |||
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 | |||
success: (res) => { | |||
this.setData({ | |||
userInfo: res.userInfo, | |||
hasUserInfo: true | |||
}) | |||
} | |||
}) | |||
}, | |||
getUserInfo(e) { | |||
// 不推荐使用 getUserInfo 获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息 | |||
this.setData({ | |||
userInfo: e.detail.userInfo, | |||
hasUserInfo: true | |||
}) | |||
}, | |||
onStore() { | |||
wx.setStorage({ | |||
key: "test", | |||
data: "testStore" | |||
}) | |||
}, | |||
onGetStore() { | |||
wx.showLoading({ | |||
title: '加载中', | |||
}) | |||
setTimeout(function () { | |||
wx.hideLoading() | |||
wx.showToast({ | |||
title: '成功', | |||
icon: 'success', | |||
duration: 2000, | |||
mask: true | |||
}); | |||
}, 2000) | |||
/* wx.showToast({ | |||
title: '成功', | |||
icon: 'success', | |||
duration: 2000 | |||
}); */ | |||
wx.getStorage({ | |||
key: 'test', | |||
success(res) { | |||
console.log(res.data) | |||
} | |||
}) | |||
}, | |||
onGetDialop() { | |||
wx.showModal({ | |||
title: '温馨提示', | |||
content: '这是一个模态弹窗', | |||
success(res) { | |||
if (res.confirm) { | |||
console.log('用户点击确定'); | |||
} else if (res.cancel) { | |||
console.log('用户点击取消'); | |||
} | |||
} | |||
}) | |||
}, | |||
onGetPay() { | |||
wx.showActionSheet({ | |||
itemList: ['A', 'B', 'C'], | |||
success (res) { | |||
console.log(res.tapIndex) | |||
}, | |||
fail (res) { | |||
console.log(res.errMsg) | |||
} | |||
}) | |||
} | |||
}) |
@@ -1 +0,0 @@ | |||
<view>伙伴</view> |
@@ -1,6 +0,0 @@ | |||
/* pages/partner/partner.wxss.wxss */ | |||
map { | |||
height: 100vh; | |||
width: 100%; | |||
background-color: red; | |||
} |
@@ -1,7 +0,0 @@ | |||
{ | |||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", | |||
"rules": [{ | |||
"action": "allow", | |||
"page": "*" | |||
}] | |||
} |
@@ -0,0 +1,12 @@ | |||
{ | |||
"dependencies": {}, | |||
"name": "miniprogram-4", | |||
"description": "这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:", | |||
"version": "1.0.0", | |||
"main": "index.js", | |||
"scripts": { | |||
"test": "echo \"Error: no test specified\" && exit 1" | |||
}, | |||
"author": "", | |||
"license": "ISC" | |||
} |