wifiSet.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='配置网络'></cus-header>
  4. <div class="title">设置Wi-Fi信息</div>
  5. <div class="items">
  6. <div class="item adfacjb">
  7. <div class="il">
  8. <input type="text" v-model="wifiSSID" placeholder="网络名称" placeholder-class="ph">
  9. </div>
  10. <div class="ir" @tap="toSelectWifi">选择Wi-Fi</div>
  11. </div>
  12. <div class="item adfacjb">
  13. <div class="il">
  14. <input :password="isPwd" v-model="wifiPWD" placeholder="请输入Wi-Fi密码" placeholder-class="ph">
  15. </div>
  16. <div class="iimgs">
  17. <image @tap="changePwd" src="@/static/pwd_hide.png" v-if="isPwd"></image>
  18. <image @tap="changePwd" src="@/static/pwd_show.png" v-else></image>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="zt_btn" @tap="connectWifi">连接</div>
  23. <div class="memo">
  24. <div class="m_title">配网说明</div>
  25. <div class="m_p">
  26. 1、请注意设备仅支持2.4G的WiFi<br>
  27. 2、不支持无密码的WiFi连接<br>
  28. 3、不支持二次授权或者需要网页二次登录的WiFi<br>
  29. 4、如果使用手机热点连接,请确保手机热点正常开启<br>
  30. 5、如果使用iPhone热点,请确保热点开启了最大兼容模式<br>
  31. 6、iPhone热点因为低功耗,一段时间不使用,热点将会自动关闭,如果无法连接,请重新打开热点
  32. </div>
  33. </div>
  34. <u-popup :show="show" :round="56" mode="center" @close="show=false">
  35. <div class="wifis">
  36. <div class="top adfacjb">
  37. <div class="tl">选择WiFi</div>
  38. <div class="tr adfac" @tap="initWiFi">
  39. <!-- <image src="@/static/refreash.png"></image>
  40. <text>刷新</text> -->
  41. </div>
  42. </div>
  43. <div class="list" v-if="wifiList.length">
  44. <div class="item adfacjb" v-for="(item,index) in wifiList" :key="index">
  45. <div class="il adfac">
  46. <image src="@/static/wifi.png"></image>
  47. <text>{{item}}</text>
  48. </div>
  49. <div class="ir" @tap="selectWifi(item)">选择</div>
  50. </div>
  51. </div>
  52. <template v-else>
  53. <page-empty></page-empty>
  54. </template>
  55. </div>
  56. </u-popup>
  57. </view>
  58. </template>
  59. <script>
  60. var xBlufi = require("@/utils/blufi/xBlufi.js");
  61. import pageEmpty from '@/components/pageEmpty/index.vue'
  62. export default {
  63. components:{pageEmpty},
  64. data(){
  65. return {
  66. name: '',
  67. connectedDeviceId: '',
  68. connected: true,
  69. isInitOK: false,
  70. wifiSSID:'',
  71. wifiPWD:'',
  72. isPwd:true,
  73. show:false,
  74. wifiList:[]
  75. }
  76. },
  77. onLoad: function(options) {
  78. var that = this
  79. this.name = options.name;
  80. this.connectedDeviceId = options.deviceId;
  81. xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
  82. xBlufi.notifyInitBleEsp32({
  83. deviceId: options.deviceId,
  84. })
  85. wx.showLoading({
  86. title: '设备初始化中',
  87. })
  88. },
  89. // onUnload: function() {
  90. // let that = this
  91. // xBlufi.notifyConnectBle({
  92. // isStart: false,
  93. // deviceId: that.connectedDeviceId,
  94. // name: that.name,
  95. // });
  96. // xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
  97. // },
  98. methods:{
  99. funListenDeviceMsgEvent: function(options) {
  100. let that = this
  101. let ssid_arry = this.wifiList;
  102. switch (options.type) {
  103. // case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
  104. // that.connected = options.result
  105. // if (!options.result) {
  106. // wx.showModal({
  107. // title: '很抱歉提醒你!',
  108. // content: '小程序与设备异常断开',
  109. // showCancel: false, //是否显示取消按钮
  110. // })
  111. // }
  112. // break;
  113. case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
  114. wx.hideLoading();
  115. if (!options.result)
  116. wx.showModal({
  117. title: '温馨提示',
  118. content: '配网失败,请重试',
  119. showCancel: false,
  120. })
  121. else {
  122. if (options.data.progress == 100) {
  123. uni.setStorageSync(that.wifiSSID,that.wifiPWD)
  124. // uni.navigateTo({
  125. // url:'/pagesMy/wifiSuccess'
  126. // })
  127. let result = {
  128. "macAddress": this.connectedDeviceId||'',
  129. "board": this.name||"cx-mxb-wifi",
  130. "appVersion": "1.8.2" ,
  131. };
  132. uni.navigateTo({
  133. url:'/pagesMy/scanResult?scanParams='+JSON.stringify(result)+'&type=lanya'
  134. })
  135. }
  136. }
  137. break;
  138. // case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
  139. // wx.showModal({
  140. // title: '收到自定义设备数据',
  141. // content: `【${options.data}】`,
  142. // showCancel: false,
  143. // })
  144. // break;
  145. case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_NEAR_ROUTER_LISTS:
  146. wx.hideLoading();
  147. if ('' === options.data.SSID) break;
  148. if(!ssid_arry.includes(options.data.SSID)) ssid_arry.push(options.data.SSID)
  149. that.wifiList = ssid_arry;
  150. that.wifiSSID = that.wifiList[0];
  151. that.wifiPWD = uni.getStorageSync(that.wifiSSID)||'';
  152. that.isInitOK = true
  153. break;
  154. case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
  155. wx.hideLoading();
  156. if (options.result) {
  157. xBlufi.notifySendGetNearRouterSsid()
  158. wx.showLoading({
  159. title: '获取周围WiFi列表...',
  160. })
  161. } else {
  162. that.connected = false
  163. wx.showModal({
  164. title: '温馨提示',
  165. content: `设备初始化失败`,
  166. showCancel: false, //是否显示取消按钮
  167. })
  168. }
  169. break;
  170. }
  171. },
  172. changePwd(){
  173. this.isPwd = !this.isPwd;
  174. },
  175. initWiFi(){
  176. // let that = this;
  177. // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
  178. // xBlufi.notifyInitBleEsp32({
  179. // deviceId: that.connectedDeviceId
  180. // })
  181. },
  182. connectWifi(){
  183. let that = this;
  184. if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
  185. if(!this.wifiPWD) return this.$showToast('请输入Wi-Fi密码')
  186. wx.showLoading({
  187. title: '正在配网...',
  188. mask: true
  189. })
  190. xBlufi.notifySendRouterSsidAndPassword({
  191. ssid: that.wifiSSID,
  192. password: that.wifiPWD
  193. })
  194. },
  195. toSelectWifi(){
  196. this.show = true;
  197. },
  198. selectWifi(item){
  199. this.wifiSSID = item;
  200. this.wifiPWD = uni.getStorageSync(item) || '';
  201. this.show = false;
  202. this.isInitOK = true
  203. }
  204. }
  205. }
  206. </script>
  207. <style scoped lang="less">
  208. .page{
  209. padding: 0 40rpx 250rpx;
  210. box-sizing: border-box;
  211. background: #FFFFFF;
  212. &>.title{
  213. font-family: PingFang-SC, PingFang-SC;
  214. font-weight: bold;
  215. font-size: 36rpx;
  216. color: #111111;
  217. line-height: 36rpx;
  218. margin-top: 64rpx;
  219. }
  220. .items{
  221. margin-top: 188rpx;
  222. .item{
  223. margin-top: 80rpx;
  224. padding-bottom: 30rpx;
  225. border-bottom: 1rpx solid #E2E2E2;
  226. .il{
  227. width: calc(100% - 180rpx);
  228. input{
  229. border: none;
  230. font-family: PingFangSC, PingFang SC;
  231. font-weight: 400;
  232. font-size: 28rpx;
  233. color: #333333;
  234. line-height: 42rpx;
  235. }
  236. }
  237. .ir{
  238. width: 160rpx;
  239. height: 64rpx;
  240. background: #D9F159;
  241. border-radius: 32rpx;
  242. font-family: PingFang-SC, PingFang-SC;
  243. font-weight: bold;
  244. font-size: 26rpx;
  245. color: #252525;
  246. line-height: 64rpx;
  247. text-align: center;
  248. }
  249. .iimgs{
  250. image{
  251. width: 36rpx;
  252. height: 36rpx;
  253. }
  254. }
  255. }
  256. }
  257. .zt_btn{
  258. margin-top: 100rpx;
  259. }
  260. .memo{
  261. margin-top: 100rpx;
  262. .m_title{
  263. font-family: PingFangSC, PingFang SC;
  264. font-weight: 400;
  265. font-size: 26rpx;
  266. color: #111111;
  267. line-height: 40rpx;
  268. }
  269. .m_p{
  270. font-family: PingFangSC, PingFang SC;
  271. font-weight: 400;
  272. font-size: 24rpx;
  273. color: #7C8592;
  274. line-height: 54rpx;
  275. margin-top: 10rpx;
  276. }
  277. }
  278. .ph{
  279. color: #7C8592;
  280. }
  281. .wifis{
  282. width: 670rpx;
  283. max-height: 720rpx;
  284. overflow: hidden;
  285. padding-bottom: 20rpx;
  286. .top{
  287. margin-top: 14rpx;
  288. padding: 40rpx;
  289. border-bottom: 1rpx solid #E2E2E2;
  290. .tl{
  291. font-family: PingFang-SC, PingFang-SC;
  292. font-weight: bold;
  293. font-size: 36rpx;
  294. color: #111111;
  295. line-height: 36rpx;
  296. }
  297. .tr{
  298. image{
  299. width: 36rpx;
  300. height: 36rpx;
  301. }
  302. text{
  303. font-family: PingFangSC, PingFang SC;
  304. font-weight: 400;
  305. font-size: 32rpx;
  306. color: #7C8592;
  307. line-height: 36rpx;
  308. margin-left: 10rpx;
  309. }
  310. }
  311. }
  312. .list{
  313. height: 609rpx;
  314. overflow-y: auto;
  315. padding: 30rpx 40rpx;
  316. box-sizing: border-box;
  317. .item{
  318. width: 100%;
  319. height: 120rpx;
  320. border-radius: 16rpx;
  321. border: 1rpx solid #E2E2E2;
  322. margin-top: 20rpx;
  323. padding: 0 24rpx;
  324. box-sizing: border-box;
  325. &:first-child{
  326. margin-top: 0;
  327. }
  328. .il{
  329. width: calc(100% - 134rpx);
  330. image{
  331. width: 42rpx;
  332. height: 42rpx;
  333. }
  334. text{
  335. font-family: PingFangSC, PingFang SC;
  336. font-weight: 400;
  337. font-size: 30rpx;
  338. color: #252525;
  339. line-height: 30rpx;
  340. margin-left: 20rpx;
  341. width: calc(100% - 62rpx);
  342. overflow: hidden;
  343. text-overflow: ellipsis;
  344. white-space: nowrap;
  345. }
  346. }
  347. .ir{
  348. width: 114rpx;
  349. height: 60rpx;
  350. background: #D9F159;
  351. border-radius: 32rpx;
  352. font-family: PingFangSC, PingFang SC;
  353. font-weight: 400;
  354. font-size: 28rpx;
  355. color: #252525;
  356. line-height: 60rpx;
  357. text-align: center;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. </style>