diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 4fdff43..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.emptySelectionClipboard": false -} \ No newline at end of file diff --git a/README.md b/README.md index e097b0c..e7f5d12 100644 --- a/README.md +++ b/README.md @@ -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 增加 版本控制 diff --git a/miniprogram/app.js b/miniprogram/app.js index e0b83de..01f6d94 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -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({}) diff --git a/miniprogram/app.json b/miniprogram/app.json index 0797487..95c8b76 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -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" } \ No newline at end of file diff --git a/miniprogram/images/icon/help.png b/miniprogram/images/icon/help.png new file mode 100644 index 0000000..44fc126 Binary files /dev/null and b/miniprogram/images/icon/help.png differ diff --git a/miniprogram/images/icon/icon_home.png b/miniprogram/images/icon/icon_home.png index fee8b20..2977599 100644 Binary files a/miniprogram/images/icon/icon_home.png and b/miniprogram/images/icon/icon_home.png differ diff --git a/miniprogram/images/icon/icon_home_active.png b/miniprogram/images/icon/icon_home_active.png index c442026..4fd3a9c 100644 Binary files a/miniprogram/images/icon/icon_home_active.png and b/miniprogram/images/icon/icon_home_active.png differ diff --git a/miniprogram/images/icon/no_wifi.png b/miniprogram/images/icon/no_wifi.png new file mode 100644 index 0000000..78933f0 Binary files /dev/null and b/miniprogram/images/icon/no_wifi.png differ diff --git a/miniprogram/model/index.js b/miniprogram/model/index.js new file mode 100644 index 0000000..12b546d --- /dev/null +++ b/miniprogram/model/index.js @@ -0,0 +1 @@ +export const VersionModel = '2.0.0F'; \ No newline at end of file diff --git a/miniprogram/pages/home/home.js b/miniprogram/pages/home/home.js index 95dcdf8..93ed90b 100644 --- a/miniprogram/pages/home/home.js +++ b/miniprogram/pages/home/home.js @@ -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, }) }, }); diff --git a/miniprogram/pages/home/home.json b/miniprogram/pages/home/home.json new file mode 100644 index 0000000..eea7301 --- /dev/null +++ b/miniprogram/pages/home/home.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "首页" + } \ No newline at end of file diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml index 152bd28..62fe8ce 100644 --- a/miniprogram/pages/home/home.wxml +++ b/miniprogram/pages/home/home.wxml @@ -1,23 +1,31 @@ - - 周边WIFI列表 - - - WIFI名称:{{wifiList[index].SSID}} - - BSSID:{{wifiList[index].BSSID}} - - - + + + 设备不支持5G类型以及机场,酒店等热点WLAN。如未获取到,请打开WIFI和GPS后刷新页面。点击WLAN名称可查看WLAN信息。 + + + + 可用WLAN列表 + + + + + + + + (当前手机连接网络) + {{wlanList[index].SSID}} - - 无 - + + + + 找不到WLAN? + - - - + + + 搜索不到WLAN \ No newline at end of file diff --git a/miniprogram/pages/home/home.wxss b/miniprogram/pages/home/home.wxss index 6cfd905..e3f3fce 100644 --- a/miniprogram/pages/home/home.wxss +++ b/miniprogram/pages/home/home.wxss @@ -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; } \ No newline at end of file diff --git a/miniprogram/pages/list/list.js b/miniprogram/pages/list/list.js deleted file mode 100644 index be9aec2..0000000 --- a/miniprogram/pages/list/list.js +++ /dev/null @@ -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); - } - }) - } -}) \ No newline at end of file diff --git a/miniprogram/pages/list/list.wxml b/miniprogram/pages/list/list.wxml deleted file mode 100644 index 9dce75a..0000000 --- a/miniprogram/pages/list/list.wxml +++ /dev/null @@ -1,9 +0,0 @@ - - -现在是: {{nowTime}} - - - - - - \ No newline at end of file diff --git a/miniprogram/pages/more/more.js b/miniprogram/pages/more/more.js index 2df501d..14870a3 100644 --- a/miniprogram/pages/more/more.js +++ b/miniprogram/pages/more/more.js @@ -1,11 +1,12 @@ // pages/more/more.js +import { VersionModel } from '../../model/index' Page({ /** * 页面的初始数据 */ data: { - + version: VersionModel, //版本号 }, /** diff --git a/miniprogram/pages/more/more.json b/miniprogram/pages/more/more.json new file mode 100644 index 0000000..c0c9438 --- /dev/null +++ b/miniprogram/pages/more/more.json @@ -0,0 +1,3 @@ +{ + "navigationBarTitleText": "更多" + } \ No newline at end of file diff --git a/miniprogram/pages/more/more.wxml b/miniprogram/pages/more/more.wxml index 2b01eb5..6f5be68 100644 --- a/miniprogram/pages/more/more.wxml +++ b/miniprogram/pages/more/more.wxml @@ -1,2 +1,4 @@ -更多 + + 当前小程序版本号:{{version}} + \ No newline at end of file diff --git a/miniprogram/pages/list/list.wxss b/miniprogram/pages/more/more.wxss similarity index 57% rename from miniprogram/pages/list/list.wxss rename to miniprogram/pages/more/more.wxss index 546ceea..96ba6f2 100644 --- a/miniprogram/pages/list/list.wxss +++ b/miniprogram/pages/more/more.wxss @@ -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; } \ No newline at end of file diff --git a/miniprogram/pages/partner/partner.js b/miniprogram/pages/partner/partner.js deleted file mode 100644 index ad2786a..0000000 --- a/miniprogram/pages/partner/partner.js +++ /dev/null @@ -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) - } - }) - } -}) \ No newline at end of file diff --git a/miniprogram/pages/partner/partner.wxml b/miniprogram/pages/partner/partner.wxml deleted file mode 100644 index 1738cf4..0000000 --- a/miniprogram/pages/partner/partner.wxml +++ /dev/null @@ -1 +0,0 @@ -伙伴 \ No newline at end of file diff --git a/miniprogram/pages/partner/partner.wxss b/miniprogram/pages/partner/partner.wxss deleted file mode 100644 index 30e255a..0000000 --- a/miniprogram/pages/partner/partner.wxss +++ /dev/null @@ -1,6 +0,0 @@ -/* pages/partner/partner.wxss.wxss */ -map { - height: 100vh; - width: 100%; - background-color: red; -} \ No newline at end of file diff --git a/miniprogram/sitemap45.json b/miniprogram/sitemap45.json deleted file mode 100644 index ca02add..0000000 --- a/miniprogram/sitemap45.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", - "rules": [{ - "action": "allow", - "page": "*" - }] -} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..a55592b --- /dev/null +++ b/package.json @@ -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" +}