wifiSet.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. }
  128. }
  129. break;
  130. case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
  131. wx.showModal({
  132. title: '收到自定义设备数据',
  133. content: `【${options.data}】`,
  134. showCancel: false,
  135. })
  136. break;
  137. case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_NEAR_ROUTER_LISTS:
  138. wx.hideLoading();
  139. if ('' === options.data.SSID) break;
  140. if(!ssid_arry.includes(options.data.SSID)) ssid_arry.push(options.data.SSID)
  141. that.wifiList = ssid_arry;
  142. that.wifiSSID = that.wifiList[0];
  143. that.wifiPWD = uni.getStorageSync(that.wifiSSID)||'';
  144. that.isInitOK = true
  145. break;
  146. case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT:
  147. wx.hideLoading();
  148. if (options.result) {
  149. xBlufi.notifySendGetNearRouterSsid()
  150. wx.showLoading({
  151. title: '获取周围WiFi列表...',
  152. })
  153. } else {
  154. that.connected = false
  155. wx.showModal({
  156. title: '温馨提示',
  157. content: `设备初始化失败`,
  158. showCancel: false, //是否显示取消按钮
  159. })
  160. }
  161. break;
  162. }
  163. },
  164. changePwd(){
  165. this.isPwd = !this.isPwd;
  166. },
  167. initWiFi(){
  168. // let that = this;
  169. // xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
  170. // xBlufi.notifyInitBleEsp32({
  171. // deviceId: that.connectedDeviceId
  172. // })
  173. },
  174. connectWifi(){
  175. let that = this;
  176. if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
  177. if(!this.wifiPWD) return this.$showToast('请输入Wi-Fi密码')
  178. wx.showLoading({
  179. title: '正在配网...',
  180. mask: true
  181. })
  182. xBlufi.notifySendRouterSsidAndPassword({
  183. ssid: that.wifiSSID,
  184. password: that.wifiPWD
  185. })
  186. },
  187. toSelectWifi(){
  188. this.show = true;
  189. },
  190. selectWifi(item){
  191. this.wifiSSID = item;
  192. this.wifiPWD = uni.getStorageSync(item) || '';
  193. this.show = false;
  194. this.isInitOK = true
  195. }
  196. }
  197. }
  198. </script>
  199. <style scoped lang="less">
  200. .page{
  201. padding: 0 40rpx 250rpx;
  202. box-sizing: border-box;
  203. background: #FFFFFF;
  204. &>.title{
  205. font-family: PingFang-SC, PingFang-SC;
  206. font-weight: bold;
  207. font-size: 36rpx;
  208. color: #111111;
  209. line-height: 36rpx;
  210. margin-top: 64rpx;
  211. }
  212. .items{
  213. margin-top: 188rpx;
  214. .item{
  215. margin-top: 80rpx;
  216. padding-bottom: 30rpx;
  217. border-bottom: 1rpx solid #E2E2E2;
  218. .il{
  219. width: calc(100% - 180rpx);
  220. input{
  221. border: none;
  222. font-family: PingFangSC, PingFang SC;
  223. font-weight: 400;
  224. font-size: 28rpx;
  225. color: #333333;
  226. line-height: 42rpx;
  227. }
  228. }
  229. .ir{
  230. width: 160rpx;
  231. height: 64rpx;
  232. background: #D9F159;
  233. border-radius: 32rpx;
  234. font-family: PingFang-SC, PingFang-SC;
  235. font-weight: bold;
  236. font-size: 26rpx;
  237. color: #252525;
  238. line-height: 64rpx;
  239. text-align: center;
  240. }
  241. .iimgs{
  242. image{
  243. width: 36rpx;
  244. height: 36rpx;
  245. }
  246. }
  247. }
  248. }
  249. .zt_btn{
  250. margin-top: 100rpx;
  251. }
  252. .memo{
  253. margin-top: 100rpx;
  254. .m_title{
  255. font-family: PingFangSC, PingFang SC;
  256. font-weight: 400;
  257. font-size: 26rpx;
  258. color: #111111;
  259. line-height: 40rpx;
  260. }
  261. .m_p{
  262. font-family: PingFangSC, PingFang SC;
  263. font-weight: 400;
  264. font-size: 24rpx;
  265. color: #7C8592;
  266. line-height: 54rpx;
  267. margin-top: 10rpx;
  268. }
  269. }
  270. .ph{
  271. color: #7C8592;
  272. }
  273. .wifis{
  274. width: 670rpx;
  275. max-height: 720rpx;
  276. overflow: hidden;
  277. padding-bottom: 20rpx;
  278. .top{
  279. margin-top: 14rpx;
  280. padding: 40rpx;
  281. border-bottom: 1rpx solid #E2E2E2;
  282. .tl{
  283. font-family: PingFang-SC, PingFang-SC;
  284. font-weight: bold;
  285. font-size: 36rpx;
  286. color: #111111;
  287. line-height: 36rpx;
  288. }
  289. .tr{
  290. image{
  291. width: 36rpx;
  292. height: 36rpx;
  293. }
  294. text{
  295. font-family: PingFangSC, PingFang SC;
  296. font-weight: 400;
  297. font-size: 32rpx;
  298. color: #7C8592;
  299. line-height: 36rpx;
  300. margin-left: 10rpx;
  301. }
  302. }
  303. }
  304. .list{
  305. height: 609rpx;
  306. overflow-y: auto;
  307. padding: 30rpx 40rpx;
  308. box-sizing: border-box;
  309. .item{
  310. width: 100%;
  311. height: 120rpx;
  312. border-radius: 16rpx;
  313. border: 1rpx solid #E2E2E2;
  314. margin-top: 20rpx;
  315. padding: 0 24rpx;
  316. box-sizing: border-box;
  317. &:first-child{
  318. margin-top: 0;
  319. }
  320. .il{
  321. width: calc(100% - 134rpx);
  322. image{
  323. width: 42rpx;
  324. height: 42rpx;
  325. }
  326. text{
  327. font-family: PingFangSC, PingFang SC;
  328. font-weight: 400;
  329. font-size: 30rpx;
  330. color: #252525;
  331. line-height: 30rpx;
  332. margin-left: 20rpx;
  333. width: calc(100% - 62rpx);
  334. overflow: hidden;
  335. text-overflow: ellipsis;
  336. white-space: nowrap;
  337. }
  338. }
  339. .ir{
  340. width: 114rpx;
  341. height: 60rpx;
  342. background: #D9F159;
  343. border-radius: 32rpx;
  344. font-family: PingFangSC, PingFang SC;
  345. font-weight: 400;
  346. font-size: 28rpx;
  347. color: #252525;
  348. line-height: 60rpx;
  349. text-align: center;
  350. }
  351. }
  352. }
  353. }
  354. }
  355. </style>