AI销管
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

545 lignes
12 KiB

  1. <template>
  2. <view class="wifi">
  3. <!-- 可用的WIFI -->
  4. <view @click="refreshList" class="wi-label">
  5. 附近可用的WIFI <text>刷新</text>
  6. </view>
  7. <scroll-view scroll-y style="height: 500rpx;" class="wi-lic">
  8. <view v-for="(item,index) in wifiList" :key="index" @click="tanShow(item)" class="wi-lic-li line">
  9. <image class="wi-wifi" src="/static/images/bluetooth-wifi.png" />
  10. <view class="wi-lic-1">{{item.ssid}}</view>
  11. <image class="wi-ri" src="/static/images/jiantop.png" />
  12. </view>
  13. </scroll-view>
  14. <!-- 可用的WIFI -->
  15. <view style="margin-top: 40rpx;" class="wi-label">
  16. 手动设定WIFI
  17. </view>
  18. <view class="wi-lic" @click="tanShow({ssid : '', key : ''})" style="margin-bottom: 60rpx;">
  19. <view class="wi-lic-li">
  20. <view class="wi-lic-1">自定义</view>
  21. <image class="wi-ri" src="/static/images/jiantop.png" />
  22. </view>
  23. </view>
  24. <view style="margin-top: 40rpx;" class="wi-label">
  25. 主wifi配置
  26. </view>
  27. <view class="wi-lic" @click="tanShow({ssid : setInfo.wifi.ssid,key : setInfo.wifi.key})">
  28. <view class="wi-lic-li line">
  29. <view class="wi-lic-1">wifi名称:{{setInfo.wifi.ssid}}</view>
  30. </view>
  31. <view class="wi-lic-li">
  32. <view class="wi-lic-1">wifi密码:{{setInfo.wifi.key}}</view>
  33. </view>
  34. </view>
  35. <view style="margin-top: 40rpx;" class="wi-label">
  36. 副wifi配置
  37. </view>
  38. <view class="wi-lic" style="margin-bottom: 80rpx;">
  39. <view v-for="(item,index) in setInfo.wifi.aps" @click="tanShow(item)" class="wi-lic-li line">
  40. <view class="wi-lic-1">wifi名称:{{item.ssid}}</view>
  41. <image class="wi-ri" @click.stop="apsDel(index)" mode="widthFix" style="width: 36rpx;" src="/static/images/bluetooth-del.png" />
  42. </view>
  43. </view>
  44. <uni-popup ref="tan">
  45. <view class="tan">
  46. <view class="tan-t1">配置WIFI</view>
  47. <view class="tan-c1">
  48. <view class="tan-inp">
  49. <view class="tan-inp-t1"><text>*</text>WIFI名称</view>
  50. <input placeholder="请输入wifi名称" v-model="form.ssid" />
  51. </view>
  52. <view class="tan-inp">
  53. <view class="tan-inp-t1">WIFI密码</view>
  54. <input placeholder="请输入wifi密码" v-model="form.key" />
  55. </view>
  56. <view class="tan-btn">
  57. <view @click="tanHide()" class="tan-w">取消</view>
  58. <view @click="tanSub()" class="tan-b">确定</view>
  59. </view>
  60. </view>
  61. </view>
  62. </uni-popup>
  63. </view>
  64. </template>
  65. <script>
  66. import { connectBlue,sendData,setNotification,ab2hex,strToHex,closeBlue,changeIsModalShown } from "@/utils/blue.js";
  67. import { mapState, mapMutations } from 'vuex';
  68. export default {
  69. data() {
  70. return {
  71. type : 1,
  72. setInfo : "",
  73. setNum : 0,
  74. setZl : [] ,
  75. info : "",
  76. form : {
  77. ssid : '',
  78. key : ''
  79. },
  80. strJson : "",
  81. initWifiXl : [["0xA0","0x82","0x00"],["0xA0","0x87","0x00"]], //指令合集
  82. wifiList : "",
  83. isConnectTimer : ""
  84. }
  85. },
  86. computed: {
  87. ...mapState(['connectDev','connectState']),
  88. },
  89. onShow() {
  90. var that = this
  91. this.info = uni.getStorageSync("lyDetail")
  92. if (that.connectDev) {
  93. that.init();
  94. that.notifiInit();
  95. } else {
  96. uni.showModal({
  97. title: '提示',
  98. content: '蓝牙连接失败',
  99. cancelText: '取消',
  100. confirmText: '重新连接',
  101. success(res) {
  102. if (res.confirm) that.connectTO();
  103. }
  104. })
  105. }
  106. },
  107. onHide() {
  108. if (this.isConnectTimer) clearInterval(this.isConnectTimer);
  109. },
  110. onUnload() {
  111. if (this.isConnectTimer) clearInterval(this.isConnectTimer);
  112. },
  113. methods: {
  114. init() {
  115. uni.showLoading({
  116. title:"获取中...",
  117. icon: "none"
  118. })
  119. sendData(this.initWifiXl[0])
  120. },
  121. //刷新wifi
  122. refreshList() {
  123. uni.showLoading({
  124. title:"获取中...",
  125. icon: "none"
  126. })
  127. this.wifiList = [];
  128. sendData(this.initWifiXl[1])
  129. },
  130. tanSub() {
  131. if (!this.connectState || !this.connectDev) {
  132. uni.showToast({
  133. title: "请先连接设备",
  134. icon: "none"
  135. })
  136. return ;
  137. }
  138. uni.showLoading({
  139. title:"更新中...",
  140. icon: "none"
  141. })
  142. var that = this
  143. this.tanHide();
  144. //判断主wifi是否存在如果是主wifi进行更新
  145. if (!this.setInfo.wifi.ssid || this.setInfo.wifi.ssid == this.form.ssid) {
  146. this.setInfo.wifi.ssid = this.form.ssid
  147. this.setInfo.wifi.key = this.form.key
  148. } else {
  149. //判断副wifi
  150. let isHav = false;
  151. this.setInfo.wifi.aps = this.setInfo.wifi.aps.filter(v => {
  152. if (v.ssid == this.form.ssid) {
  153. v.ssid = this.form.ssid
  154. v.key = this.form.key
  155. isHav = true
  156. }
  157. return v;
  158. })
  159. if (!isHav) {
  160. if (this.setInfo.wifi.aps.length > 3) {
  161. uni.hideLoading();
  162. uni.showToast({
  163. title: "副wifi最多添加4个",
  164. icon: "none"
  165. })
  166. return ;
  167. }
  168. this.setInfo.wifi.aps.push(this.form);
  169. }
  170. }
  171. //分割
  172. this.syncSet();
  173. },
  174. tanShow(item) {
  175. this.form = {...item};
  176. try {
  177. if (this.setInfo.wifi.ssid == item.ssid) {
  178. this.form.ssid = item.ssid
  179. this.form.key = this.setInfo.wifi.key
  180. }
  181. this.setInfo.wifi.aps.filter(v => {
  182. if (v.ssid == item.ssid) {
  183. this.form.ssid = item.ssid
  184. this.form.key = v.key
  185. }
  186. })
  187. this.$refs.tan.open();
  188. } catch (e) {
  189. uni.showModal({
  190. title: '提示',
  191. content: '数据解析错误'+JSON.stringify(this.setInfo),
  192. showCancel: false,
  193. })
  194. }
  195. },
  196. tanHide() {
  197. this.$refs.tan.close();
  198. },
  199. //副wifi删除
  200. apsDel(index) {
  201. var that = this;
  202. uni.showModal({
  203. title: '提示',
  204. content: '确定删除此wifi吗?',
  205. cancelText: '取消',
  206. confirmText: '确定',
  207. success(res) {
  208. if (res.confirm) {
  209. uni.showLoading({
  210. title:"更新中...",
  211. icon: "none"
  212. })
  213. that.setInfo.wifi.aps.splice(index,1)
  214. that.syncSet();
  215. };
  216. }
  217. })
  218. },
  219. //同步数据
  220. syncSet() {
  221. var that = this
  222. let strArray = strToHex(JSON.stringify(this.setInfo));
  223. let setZl = Array.from(
  224. { length: Math.ceil(strArray.length / 100) },
  225. (_, index) => strArray.slice(index * 100, (index + 1) * 100)
  226. );
  227. uni.showLoading({
  228. title:"更新中...",
  229. mask: true,
  230. icon: "none"
  231. })
  232. this.lxSendData(setZl,0);
  233. },
  234. //循环发送
  235. lxSendData(setZl,i) {
  236. var that = this
  237. let v = setZl[i]
  238. const hexNumber = (v.length + 1).toString(16).toUpperCase();
  239. let end = "0x00";
  240. if (i + 1 == setZl.length) end = "0x01";
  241. sendData([...["0xA0","0x83","0x"+hexNumber,end],...v]).then(() => {
  242. if (i + 1 < setZl.length) {
  243. that.lxSendData(setZl, i + 1);
  244. }
  245. })
  246. },
  247. //连接设备
  248. connectTO() {
  249. var that = this;
  250. connectBlue(this.info).then(() => {
  251. //设置设置通知
  252. setTimeout(() => {
  253. setNotification().then(() => {
  254. that.init();
  255. that.notifiInit();
  256. })
  257. },1000)
  258. });
  259. },
  260. notifiInit() {
  261. var that = this
  262. uni.onBLECharacteristicValueChange((res) => {
  263. let data = ab2hex(res.value,3);
  264. //基本设置信息
  265. if (data.pre[1] == "82") {
  266. that.strJson += data.value
  267. if (data.pre[3] == "01") {
  268. uni.hideLoading();
  269. that.setInfo = JSON.parse(that.strJson)
  270. that.strJson = "";
  271. //发送第二条数据
  272. sendData(that.initWifiXl[1])
  273. uni.showLoading({
  274. title:"扫描wifi中...",
  275. icon: "none"
  276. })
  277. }
  278. }
  279. //wifi扫描信息
  280. if (data.pre[1] == "87") {
  281. if (data.pre[3] == "00") {
  282. that.strJson += data.value
  283. }
  284. if (data.pre[3] == "01") {
  285. uni.hideLoading();
  286. that.strJson += data.value
  287. console.log("当前返回所有wifi列表",that.strJson);
  288. let rdd = JSON.parse(that.strJson);
  289. that.wifiList = rdd.Results;
  290. that.strJson = "";
  291. }
  292. }
  293. //命令重启
  294. if (data.pre[1] == "88") {
  295. if (data.pre[3] == "01") {
  296. uni.showModal({
  297. title: '提示',
  298. content: '重启失败,请手动重启设备并前往蓝牙页面重新连接',
  299. showCancel:false,
  300. confirmText: '确定',
  301. success(res) {
  302. if (res.confirm) {
  303. uni.redirectTo({
  304. url: "/pages/bluetooth/connect"
  305. })
  306. }
  307. }
  308. })
  309. }
  310. //禁止弹窗
  311. changeIsModalShown();
  312. //循环判断是否链接成功
  313. uni.showLoading({
  314. title:"正在连接设备",
  315. mask: true,
  316. icon: "none"
  317. })
  318. if (that.isConnectTimer) clearInterval(that.isConnectTimer);
  319. let num = 0
  320. closeBlue().then(() => {
  321. that.connectTO();
  322. that.isConnectTimer = setInterval(() => {
  323. console.log("循环判断是否链接成功",that.connectDev,1222);
  324. if (that.connectDev) {
  325. clearInterval(that.isConnectTimer);
  326. } else {
  327. num++;
  328. if (num <= 5) {
  329. uni.hideLoading();
  330. uni.showLoading({
  331. title:"正在连接设备",
  332. mask: true,
  333. icon: "none"
  334. })
  335. } else {
  336. uni.showModal({
  337. title: '提示',
  338. content: '蓝牙连接失败,前往手动连接',
  339. showCancel: false,
  340. confirmText: '前往',
  341. success(res) {
  342. uni.redirectTo({
  343. url: "/pages/bluetooth/detail"
  344. })
  345. }
  346. })
  347. clearInterval(that.isConnectTimer);
  348. }
  349. }
  350. },2000)
  351. })
  352. }
  353. //配置修改
  354. if (data.pre[1] == "83") {
  355. if (data.pre[3] == "00") {
  356. uni.hideLoading();
  357. uni.showLoading({
  358. title:"更新成功,工牌重启中",
  359. mask: true,
  360. icon: "none"
  361. })
  362. sendData([0xA0,0x88,0x00])
  363. }
  364. }
  365. console.log('特性值改变:',data); // 打印接收到的数据
  366. });
  367. }
  368. }
  369. }
  370. </script>
  371. <style scoped lang="scss">
  372. .wifi {
  373. background-color: #F1F2F4;
  374. min-height: 100vh;
  375. width: 100%;
  376. box-sizing: border-box;
  377. padding: 40rpx 28rpx 0;
  378. .wi-label {
  379. width: 100%;
  380. display: flex;
  381. align-items: center;
  382. justify-content: space-between;
  383. font-weight: 400;
  384. font-size: 26rpx;
  385. color: #666666;
  386. text {
  387. font-weight: 400;
  388. font-size: 28rpx;
  389. color: #2671E2;
  390. margin-left: auto;
  391. }
  392. }
  393. .wi-lic {
  394. box-sizing: border-box;
  395. padding: 0 28rpx;
  396. background: #FFFFFF;
  397. border-radius: 12rpx;
  398. margin-top: 20rpx;
  399. .wi-lic-li {
  400. height: 84rpx;
  401. display: flex;
  402. align-items: center;
  403. justify-content: space-between;
  404. .wi-lic-1 {
  405. font-weight: 400;
  406. font-size: 28rpx;
  407. color: #333333;
  408. }
  409. image {
  410. width: 28rpx;
  411. height: 28rpx;
  412. }
  413. .wi-wifi {
  414. margin-right: 14rpx;
  415. }
  416. .wi-ri {
  417. margin-left: auto;
  418. width: 14rpx;
  419. }
  420. }
  421. .line {
  422. border-bottom: 1rpx dashed #f5f5f5;
  423. }
  424. }
  425. }
  426. .tan {
  427. width: 86vw;
  428. background: #FFFFFF;
  429. border-radius: 24rpx;
  430. }
  431. .tan-t1 {
  432. font-weight: 500;
  433. font-size: 32rpx;
  434. color: #333333;
  435. height: 116rpx;
  436. display: flex;
  437. align-items: center;
  438. justify-content: center;
  439. border-bottom: 1rpx dashed #f5f5f5;
  440. }
  441. .tan-c1 {
  442. box-sizing: border-box;
  443. padding: 48rpx 28rpx;
  444. .tan-inp {
  445. display: flex;
  446. align-items: center;
  447. margin-bottom: 45rpx;
  448. .tan-inp-t1 {
  449. flex-shrink: 0;
  450. width: 136rpx;
  451. font-weight: 400;
  452. font-size: 30rpx;
  453. color: #333333;
  454. text-align: right;
  455. margin-right: 48rpx;
  456. text {
  457. color: #C83429;
  458. }
  459. }
  460. input {
  461. width: 100%;
  462. font-weight: 400;
  463. font-size: 28rpx;
  464. color: #333333;
  465. }
  466. }
  467. }
  468. .tan-btn {
  469. display: flex;
  470. justify-content: center;
  471. margin-top: 70rpx;
  472. .tan-w {
  473. width: 191rpx;
  474. height: 72rpx;
  475. background: #FFFFFF;
  476. border-radius: 38rpx;
  477. border: 1rpx solid #333333;
  478. display: flex;
  479. align-items: center;
  480. justify-content: center;
  481. font-size: 30rpx;
  482. color: #333333;
  483. margin-right: 24rpx;
  484. }
  485. .tan-b {
  486. width: 191rpx;
  487. height: 72rpx;
  488. background: #2671E2;
  489. border-radius: 38rpx;
  490. font-weight: 400;
  491. display: flex;
  492. align-items: center;
  493. justify-content: center;
  494. font-size: 30rpx;
  495. color: #FFFFFF;
  496. margin-left: 24rpx;
  497. }
  498. }
  499. </style>