您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

bluetooth.vue 27KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. <!--设备选择 -->
  2. <template>
  3. <view class="devices">
  4. <view class="device" v-for="(item, index) in deviceList" :key="index" @click="connectDevice(item)">
  5. <image :src="`${$imgUrl}bluetooth/card1s.png`" class="head" mode="aspectFill"></image>
  6. <view class="center">
  7. <view class="name">{{ item._name }}</view>
  8. <view class="desc">编号 {{ item.name }}</view>
  9. </view>
  10. <image :src=" item.selected ? selectedUrl : unSelectedUrl" class="icon" mode="aspectFill"></image>
  11. </view>
  12. <view class="hint">
  13. <view class="txt">
  14. <image :src="`${$imgUrl}bluetooth/waring.png`" mode="aspectFill" class="imgs"></image>
  15. <view>温馨提示:</view>
  16. </view>
  17. <view class="grey-txt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  18. 指令执行过程中,请勿关闭蓝牙,勿将手机远离电子标签,以免导致写卡、写签失败。</view>
  19. </view>
  20. <!-- <view class="btn">
  21. <submit-button title="点击重新搜索蓝牙" @submit="load"></submit-button>
  22. </view> -->
  23. <!-- <view class="action">
  24. <button type="default" class="ui-btn" @click="load">
  25. 点击重新搜索蓝牙
  26. </button>
  27. </view> -->
  28. <FixedFooter>
  29. <button type="default" class="ui-btn" @click="load">
  30. 点击重新搜索蓝牙
  31. </button>
  32. </FixedFooter>
  33. </view>
  34. </template>
  35. <script setup lang="ts">
  36. import { ref, reactive } from "vue";
  37. import { onLoad, onReady, onShow,onUnload } from "@dcloudio/uni-app";
  38. import { fileURL } from "@/datas/fileURL.js";
  39. import { startHeartbeat, stopHeartbeat } from "@/pages/bluetooth/heartbeatService"
  40. import FixedFooter from '@/components/common/FixedFooter.vue'
  41. import { objectToQueryString } from '@/utils/utils'
  42. const cmd = require("../../static/etcUtil/cmdConfig.js");
  43. const imgURL = `${fileURL}image/`;
  44. const selectedUrl = imgURL + "bluetooth/select-icons.png";
  45. const unSelectedUrl = imgURL + "bluetooth/unselected_xin.png";
  46. const jyApi = require("../../static/etc/JYAPI/GenvictBleUtil.js");
  47. const jlQZApi = require("../../static/etc/JLQZAPI/JLObuSDK.js");
  48. const atApi = require("../../static/etc/ATAPI/ArtcBleUtil.js");
  49. const wqApi = require("../../static/etc/WQAPI/WCDObuSdk.js");
  50. const cgApi = require("../../static/etc/CGAPI/cguBle.js");
  51. const tools = require("../../static/etcUtil/tools.js");
  52. const datas = require("../../static/etcUtil/datas.js");
  53. const bluetoothUtil = require("../../static/etcUtil/index.js");
  54. // 微信小程序
  55. let jlApi = require("../../static/etc/JLAPI/JLObuSDK.js"); //聚力SDK
  56. let wjApi = require("../../static/etc/WJAPI/wjBleAPI");
  57. let tdApi = require("../../static/etc/TDAPI/TDRObuSDK.js");
  58. let zzApi = require("../../static/etc/WJAPI/wjBleAPI.js");
  59. let jtApi = require("../../static/etc/JTAPI/BleUtil.js");
  60. let kcApi = require("../../static/etc/kcBle/kcBleAPI.js");
  61. let mcApi = require("../../static/etc/MCAPI/MCObuSDK.js"); //5201
  62. // let jyApiEtc = require("../../static/etc/JYAPI-ETC/jy-bluetooth-obu-wechatmp.js"); //前装-金溢
  63. // 9901
  64. let wjApi9901 = require("../../static/etc/WJSDK9901/wjBleAPI.js");
  65. let ArtcBleUtilApi = require("../../static/etc/ArtcBleAPI/ArtcGuiZhouAPI.js");//艾特斯 ETC- 5201
  66. let mcApi9901 = require("../../static/etc/MCSDK9901/BleUtil9901.js"); //9901和国密5201单片
  67. // #ifdef MP-ALIPAY
  68. // 这部分代码将仅在支付宝小程序平台下执行
  69. jlApi = require("../../static/etc/JLObuSDK/JLObuSDK.js");
  70. wjApi = require("../../static/etc/wjBle/WJBleAPI");
  71. zzApi = require("../../static/etc/wjBle/WJBleAPI");
  72. tdApi = require("../../static/etc/TDRAPI/TDRObuSDK.js");
  73. jtApi = require("../../static/etc/JTAPIS/BleUtil.js");
  74. // 执行支付宝小程序的特定功能
  75. // #endif
  76. const state = reactive({
  77. fee: "",
  78. id: "",
  79. cardId: "",
  80. showPopup: false, //显示激活成功提示
  81. curDeviceId: "", //当前选中的设备ID
  82. deviceList: [
  83. //设备列表
  84. {
  85. id: "1",
  86. image: imgURL + "bluetooth/card1.png`",
  87. _name: "聚力",
  88. name: "235564444558855",
  89. },
  90. ],
  91. connectSuccess: 1,
  92. transfer: 0,
  93. rechargeMoney: "",//消费明细圈存传过来的金额
  94. orderNum: 0,//消费明细 传orderNum说明去支付
  95. payMoney: 0,//0 修复 1 支付
  96. accountId: "",//对公账户名称
  97. difference: "",//区分routeType5 1二次激活 2余额补领
  98. vehicleId: "",
  99. refundBalance: "",
  100. vehPosImgUrl: "",
  101. vehNegImgUrl: "",
  102. isAfter: '',
  103. backIndex: "",//1返回首页(卡签信息查询) ""返回订单列表 其他
  104. cardNo: "",
  105. isIOS: false,
  106. pageParams: {
  107. }
  108. });
  109. const deviceList = ref([]);
  110. const connectPrefixName = ref(null);
  111. const routeType = ref(null); //来源 1激活 2圈存 3信息重写 4信息读取 10车辆信息变更预检
  112. interface DeviceType {
  113. name : string; //设备名称
  114. deviceId : string; //uuid
  115. prefixName : string; //前缀名称
  116. selected : boolean; //判断点击次数
  117. _name : string; //中文名称
  118. }
  119. let device : DeviceType = reactive({
  120. name: "", //设备名称
  121. deviceId: "", //uuid
  122. prefixName: "", //前缀名称
  123. selected: false, //判断点击次数
  124. _name: "", //中文名称
  125. });
  126. onReady(() => {
  127. load();
  128. });
  129. onShow(() => {
  130. uni.getSystemInfo({
  131. success: function (res) {
  132. console.log(res)
  133. if (res.platform == "ios") {
  134. state.isIOS = true
  135. } else {
  136. state.isIOS = false
  137. }
  138. }
  139. });
  140. })
  141. onLoad((option) => {
  142. routeType.value = option.routeType ? option.routeType : "1";
  143. state.cardId = option.cardId;
  144. if (option) {
  145. state.pageParams = option
  146. }
  147. if (option.fee) {
  148. state.fee = option.fee;
  149. }
  150. if (option.id) {
  151. state.id = option.id;
  152. }
  153. if (option.transfer) {
  154. state.transfer = option.transfer;
  155. }
  156. if (option.rechargeMoney) {
  157. state.rechargeMoney = option.rechargeMoney
  158. }
  159. if (option.orderNum) {
  160. state.orderNum = option.orderNum
  161. }
  162. if (option.payMoney) {
  163. state.payMoney = option.payMoney
  164. }
  165. if (option.accountId) {
  166. state.accountId = option.accountId
  167. }
  168. if (option.difference) {
  169. state.difference = option.difference;
  170. }
  171. if (option.vehicleId) {
  172. state.vehicleId = option.vehicleId;
  173. }
  174. if (option.refundBalance) {
  175. state.refundBalance = option.refundBalance;
  176. }
  177. if (option.vehPosImgUrl) {
  178. state.vehPosImgUrl = option.vehPosImgUrl;
  179. }
  180. if (option.vehNegImgUrl) {
  181. state.vehNegImgUrl = option.vehNegImgUrl;
  182. }
  183. if (option.isAfter) {
  184. state.isAfter = option.isAfter;
  185. }
  186. if (option.backIndex) {
  187. state.backIndex = option.backIndex;
  188. }
  189. console.log("传过来的参数", option)
  190. });
  191. /*
  192. * 蓝牙初始化
  193. */
  194. const load = () => {
  195. deviceList.value = [];
  196. console.log("****************蓝牙getsetting******************");
  197. uni.getSetting({
  198. success(res) {
  199. console.log("****************成功******************");
  200. console.log("scopebluetooth:" + res.authSetting["scope.bluetooth"]);
  201. console.log("成功结果:" + JSON.stringify(res));
  202. if (res.authSetting["scope.bluetooth"] == undefined) {
  203. //没有授权使用蓝牙功能,提示用户授权使用
  204. // #ifdef MP-WEIXIN
  205. uni.authorize({
  206. scope: "scope.bluetooth",
  207. success() {
  208. openBluetooth();
  209. },
  210. fail(err) {
  211. console.log('蓝牙授权失败', err)
  212. uni.showToast({
  213. title: "蓝牙授权失败",
  214. icon: "error",
  215. duration: 1500,
  216. });
  217. }
  218. });
  219. // #endif
  220. // #ifdef MP-ALIPAY
  221. openBluetooth();
  222. // #endif
  223. } else if (!res.authSetting["scope.bluetooth"]) {
  224. //false
  225. uni.showModal({
  226. title: "是否授权读取蓝牙",
  227. content: "需要获取你的蓝牙,请确认授权,否则无法获取蓝牙",
  228. success: function (mres) {
  229. if (mres.confirm) {
  230. uni.openSetting({
  231. success(authData) {
  232. if (authData.authSetting["scope.bluetooth"] == true) {
  233. tools.showLoadingAlert("扫描蓝牙中");
  234. openBluetooth();
  235. } else {
  236. uni.closeBluetoothAdapter();
  237. uni.showToast({
  238. title: "蓝牙授权失败",
  239. icon: "error",
  240. duration: 1500,
  241. });
  242. }
  243. },
  244. });
  245. } else if (mres.cancel) {
  246. uni.showToast({
  247. title: "蓝牙授权失败",
  248. icon: "error",
  249. duration: 1000,
  250. });
  251. }
  252. },
  253. });
  254. } else {
  255. tools.showLoadingAlert("扫描蓝牙中");
  256. openBluetooth();
  257. }
  258. },
  259. fail(res) {
  260. console.log("****************失败******************");
  261. console.log("失败结果:" + JSON.stringify(res));
  262. },
  263. });
  264. };
  265. /*
  266. * 打开蓝牙
  267. */
  268. const openBluetooth = () => {
  269. tools.hideLoadingAlert();
  270. let foundDevices = []; //扫描到的蓝牙列表
  271. uni.closeBluetoothAdapter(); //先关闭蓝牙
  272. console.log('执行断开蓝牙方法')
  273. //打开蓝牙
  274. uni.openBluetoothAdapter({
  275. success: function (item : any) {
  276. console.log('初始化蓝牙模块', item)
  277. tools.showLoadingAlert("扫描蓝牙中...");
  278. //开始搜索附近的蓝牙设备
  279. uni.startBluetoothDevicesDiscovery({
  280. success: function (res) {
  281. console.log('开始搜寻附近的蓝牙外围设备', res);
  282. //监听搜索到新设备的事件
  283. uni.onBluetoothDeviceFound(function (res) {
  284. console.log('监听寻找到新设备的事件', res, res.devices);
  285. for (let i = 0; i < res.devices.length; i++) {
  286. var name = '';
  287. if (state.isIOS) {
  288. name = res.devices[i]['localName'];
  289. } else {
  290. name = res.devices[i]['name'];
  291. }
  292. let prefixName = "";
  293. let deviceId = res.devices[i]["deviceId"];
  294. console.log("res.devices[i]", res.devices[i]["name"]);
  295. if (name != "" && name != undefined && name != "undefined") {
  296. if (name.indexOf("G-WJ") != -1 || name.indexOf("ETC") != -1 || name.indexOf("G-JL") != -1) {
  297. //前装设备
  298. prefixName = "ETC";
  299. } else {
  300. //聚力临时设备
  301. if (name.indexOf("5201121") != -1) {
  302. prefixName = "JL";
  303. } else {
  304. prefixName = name.substring(0, 2);
  305. }
  306. }
  307. prefixName = prefixName.toUpperCase();
  308. console.log("prefixName====", prefixName, name)
  309. if (
  310. prefixName == "WJ" ||
  311. prefixName == "JL" ||
  312. prefixName == "BY" ||
  313. prefixName == "JY" ||
  314. prefixName == "AT" ||
  315. prefixName == "JT" ||
  316. prefixName == "WQ" ||
  317. prefixName == "CG" ||
  318. prefixName == "TD" ||
  319. prefixName == "ZZ" ||
  320. prefixName == "MC" ||
  321. prefixName == "ETC"
  322. ) {
  323. // //隐藏加载框
  324. tools.hideLoadingAlert();
  325. device.name = name;
  326. datas.setData("deviceName", device.name);
  327. device.deviceId = deviceId;
  328. device.prefixName = prefixName;
  329. device.selected = false; //防止重复点击
  330. let _name = "";
  331. switch (prefixName) {
  332. case "ETC":
  333. if (name.split("-")[1] == "KC" || name.split("-")[1].indexOf('C') > 0 || name.split("-")[1].indexOf('K') > 0) {
  334. _name = "科畅";
  335. console.log("前装-科畅")
  336. } else if (name.split("-")[1] == "JL") {
  337. _name = "聚利"; //共用
  338. } else if (name.split("-")[1] == "WJ") {
  339. _name = "万集"; //共用
  340. } else if (name.split("-")[1] == "JY") {
  341. _name = "金溢";
  342. } else if (name.split("-")[1] == "ATS") {
  343. _name = "埃特斯";
  344. } else if (name.split("-")[1] == "MC") {
  345. _name = "铭创";
  346. }else if (name.split("-")[1] == "WQ") {
  347. _name = "握奇";
  348. }
  349. break;
  350. case "WJ":
  351. _name = "万集";
  352. break;
  353. case "JL":
  354. _name = "聚利";
  355. break;
  356. case "BY":
  357. _name = "宝溢";
  358. break;
  359. case "JY":
  360. _name = "金溢";
  361. break;
  362. case "AT":
  363. _name = "埃特斯";
  364. break;
  365. case "JT":
  366. _name = "建投";
  367. break;
  368. case "WQ":
  369. _name = "握奇";
  370. break;
  371. case "CG":
  372. _name = "成谷";
  373. break;
  374. case "TD":
  375. _name = "天地融";
  376. break;
  377. case "ZZ":
  378. _name = "智载";
  379. break;
  380. case "MC":
  381. _name = "铭创";
  382. break;
  383. default:
  384. _name = "未知";
  385. break;
  386. }
  387. device._name = _name;
  388. if (deviceList.value.length == 0) {
  389. // #ifdef MP-ALIPAY
  390. if (device._name == '聚利' || device._name == '万集' || device._name == '天地融' || device._name == '建投') {
  391. foundDevices.push(device);
  392. }
  393. // #endif
  394. // #ifdef MP-WEIXIN
  395. foundDevices.push(device);
  396. // #endif
  397. } else {
  398. let isHave = false;
  399. for (let j = 0; j < foundDevices.length; j++) {
  400. if (name == foundDevices[j].deviceId) {
  401. isHave = true;
  402. break;
  403. }
  404. }
  405. if (!isHave) {
  406. foundDevices.push(device);
  407. }
  408. }
  409. datas.setData("deviceNameZW", device._name);
  410. deviceList.value = foundDevices;
  411. foundDevices = [];
  412. console.log("deviceList.value", deviceList.value);
  413. }
  414. }
  415. }
  416. });
  417. },
  418. fail: function (res) {
  419. console.log(res);
  420. tools.hideLoadingAlert();
  421. },
  422. });
  423. },
  424. fail: function (res) {
  425. console.log(res);
  426. alertF("手机蓝牙未打开或不支持蓝牙");
  427. },
  428. });
  429. };
  430. /**
  431. * 连接蓝牙
  432. */
  433. const connectDevice = (e) => {
  434. console.log(e);
  435. let item = e;
  436. //停止扫描蓝牙
  437. console.info("停止搜寻附近的蓝牙外围设备");
  438. uni.stopBluetoothDevicesDiscovery({
  439. success: function (res) {
  440. console.log(device);
  441. if (item.selected == false) {
  442. console.log("第一次点击了");
  443. item.selected = true;
  444. setTimeout(function () {
  445. if (device.selected == undefined) {
  446. console.info("selected is undefined");
  447. linkFail(); //未找到设备, 请重新搜索
  448. return;
  449. }
  450. item.selected = false;
  451. }, 4000);
  452. } else {
  453. console.log("第二次点击了");
  454. return;
  455. }
  456. if (
  457. item.prefixName == undefined ||
  458. item.prefixName == "undefined" ||
  459. item.prefixName == ""
  460. ) {
  461. console.info("device.prefixName is undefined");
  462. linkFail(); //未找到设备, 请重新搜索
  463. return;
  464. }
  465. let prefixName = item.prefixName;
  466. connectPrefixName.value = item.prefixName;
  467. console.log(item);
  468. // datas.setData("connectPrefixName", connectPrefixName.value);
  469. // //断开蓝牙
  470. // bluetoothUtil.disconnectDevice();
  471. tools.showLoadingAlert("蓝牙连接中");
  472. console.info("连接的是" + prefixName, device);
  473. switch (prefixName) {
  474. case "ETC":
  475. console.log("device.name=====", device.name, device.name.includes("KC"), device.name.includes("JY"), device.name.includes("KC") || device.name.includes("K") || device.name.includes("C"))
  476. let obj = ""
  477. if (device.name.includes("KC") || device.name.includes("K")) {
  478. obj = kcApi
  479. } else if (device.name.includes("JL")) {
  480. obj = jlQZApi
  481. } else if (device.name.includes("WJ")) {
  482. obj = wjApi9901
  483. } else if (device.name.includes("ATS")) {
  484. obj = ArtcBleUtilApi
  485. } else if (device.name.includes("MC")) {
  486. obj = mcApi9901
  487. } else if (device.name.includes("WQ")) {
  488. obj = wqApi
  489. }
  490. console.log("新")
  491. obj.connectDevice(
  492. device,
  493. function (res) {
  494. preDevice(res);
  495. },
  496. function (res) {
  497. listenStatus(res);
  498. }
  499. );
  500. // else if (device.name.includes("JY")) {
  501. // console.log("进来了JY",device.name.includes("JY"))
  502. // jyApiEtc.connectDevice(
  503. // device,
  504. // function (res) {
  505. // preDevice(res);
  506. // },
  507. // function (res) {
  508. // listenStatus(res);
  509. // }
  510. // );
  511. // }
  512. break;
  513. case "WJ":
  514. console.log("旧")
  515. wjApi.connectDevice(
  516. device,
  517. function (res) {
  518. connectSuccess(res);
  519. },
  520. function (res) {
  521. listenStatus(res);
  522. }
  523. );
  524. break;
  525. case "JL":
  526. jlApi.connectDevice(
  527. device,
  528. function (res) {
  529. console.log('设备链接1', res)
  530. connectSuccess(res);
  531. },
  532. function (res) {
  533. console.log('设备链接2', res)
  534. listenStatus(res);
  535. }
  536. );
  537. break;
  538. case "BY":
  539. // 宝溢用金溢sdk
  540. jyApi.connectDevice(
  541. device,
  542. function (res) {
  543. console.log('设备链接1', res)
  544. connectSuccess(res);
  545. },
  546. function (res) {
  547. console.log('设备链接2', res)
  548. listenStatus(res);
  549. }
  550. );
  551. break;
  552. case "JY":
  553. jyApi.connectDevice(
  554. device,
  555. function (res) {
  556. connectSuccess(res);
  557. },
  558. function (res) {
  559. listenStatus(res);
  560. }
  561. );
  562. break;
  563. case "AT":
  564. atApi.connectDevice(
  565. device,
  566. function (res) {
  567. connectSuccess(res);
  568. },
  569. function (res) {
  570. listenStatus(res);
  571. }
  572. );
  573. break;
  574. case "JT":
  575. console.info("连接的是=====123" + prefixName, device);
  576. jtApi.connectDevice(
  577. device,
  578. function (res) {
  579. console.log('设备链接1', res)
  580. connectSuccess(res);
  581. },
  582. function (res) {
  583. console.log('设备链接2', res)
  584. listenStatus(res);
  585. }
  586. );
  587. break;
  588. case "WQ":
  589. console.log("wqApi",wqApi)
  590. wqApi.connectDevice(
  591. device,
  592. function (res) {
  593. connectSuccess(res);
  594. },
  595. function (res) {
  596. listenStatus(res);
  597. }
  598. );
  599. break;
  600. case "CG":
  601. cgApi.connectDevice(
  602. device,
  603. function (res) {
  604. connectSuccess(res);
  605. },
  606. function (res) {
  607. listenStatus(res);
  608. }
  609. );
  610. break;
  611. case "TD":
  612. tdApi.connectDevice(
  613. device,
  614. function (res) {
  615. connectSuccess(res)
  616. }, function (res) {
  617. listenStatus(res);
  618. }
  619. );
  620. break;
  621. case "ZZ":
  622. zzApi.connectDevice(
  623. device,
  624. function (res) {
  625. connectSuccess(res);
  626. },
  627. function (res) {
  628. listenStatus(res);
  629. }
  630. );
  631. break;
  632. case "MC":
  633. mcApi.connectDevice(
  634. device,
  635. function (res) {
  636. connectSuccess(res);
  637. },
  638. function (res) {
  639. listenStatus(res);
  640. }
  641. );
  642. break;
  643. default: //未找到设备, 请重新搜索
  644. linkFail();
  645. break;
  646. }
  647. },
  648. fail: function (res) {
  649. console.log(res);
  650. linkFail(); //未找到设备, 请重新搜索
  651. },
  652. });
  653. };
  654. /**
  655. * 未找到设备, 请重新搜索
  656. */
  657. const linkFail = () => {
  658. datas.setData("bluLinkStatus", false);
  659. datas.setData("connectPrefixName", "");
  660. tools.showModalAlert("未找到设备, 请重新搜索", function successFunc() {
  661. load();
  662. });
  663. };
  664. /**
  665. * 连接成功
  666. */
  667. const connectSuccess = (res) => {
  668. console.log("连接回调函数func1");
  669. console.log(res);
  670. if (res.code == 0) {
  671. console.log("连接成功");
  672. tools.hideLoadingAlert(); //关闭加载框
  673. datas.setData("bluLinkStatus", true);
  674. datas.setData("connectPrefixName", connectPrefixName.value);
  675. // startHeartbeat() //执行心跳
  676. oks();
  677. } else {
  678. alertF(res.msg);
  679. }
  680. };
  681. // ====================== 页面卸载时清理资源 ======================
  682. onUnload(() => {
  683. // stopHeartbeat();
  684. // 实际项目中需调用 uni.closeBLEConnection 断开连接
  685. console.log('页面卸载,清理资源');
  686. });
  687. function oks() {
  688. //routeType
  689. // 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.ping码解锁 4.信息读取
  690. // 5从哪里来回哪里去监听bluetoothLink 7消费明细去圈存 8单位账户圈存 9对公账户修复 11 卡签续约
  691. // 12: 解除挂失 13:设备注销
  692. console.log(routeType.value)
  693. if (routeType.value == "1") {
  694. if (state.isAfter == '1') {
  695. uni.navigateTo({
  696. url: `/subpackage/after-sale/activation/activate-SH`,
  697. });
  698. } else {
  699. uni.navigateTo({
  700. url: `/subpackage/after-sale/activation/activate?transfer=${state.transfer}`,
  701. });
  702. }
  703. } else if (routeType.value == "2") {
  704. uni.navigateTo({
  705. url: `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=${state.connectSuccess}`,
  706. });
  707. } else if (routeType.value == "3") {
  708. uni.navigateTo({
  709. url: "/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?state=true&vehicleId=" + state.vehicleId,
  710. });
  711. } else if (routeType.value == "4") {
  712. uni.navigateTo({
  713. url: `/subpackage/after-sale/deviceInfo/deviceInfo?backIndex=${state.backIndex}`,
  714. });
  715. } else if (routeType.value == "5") {
  716. // #ifdef MP-ALIPAY
  717. uni.navigateTo({
  718. url: "/subpackage/after-sale/activation-once-again/activation-once-again-ali?state=true&id=" + state.id,
  719. });
  720. // #endif
  721. // #ifdef MP-WEIXIN
  722. if (state.difference == "1") {
  723. uni.navigateTo({
  724. url: `/subpackage/after-sale/activation-once-again/activation-once-again?status=true&state=true&vehicleId=${state.vehicleId}&vehPosImgUrl=${state.vehPosImgUrl}&vehNegImgUrl=${state.vehNegImgUrl}`,
  725. });
  726. } else if (state.difference == "2") {
  727. uni.navigateTo({
  728. url: `/subpackage/after-sale/refund-order-balance/refund-order-balance?status=true&state=true&vehicleId=${state.vehicleId}&&id=${state.id}&&refundBalance=${state.refundBalance}`,
  729. });
  730. } else {
  731. uni.$emit('bluetoothLink', { status: true })
  732. uni.navigateBack({
  733. delta: 1
  734. })
  735. }
  736. // #endif
  737. } else if (routeType.value == "6") {
  738. uni.navigateTo({
  739. url: "/subpackage/after-sale/activation-once-again/activation-once-again?state=true&id=" + state.id
  740. });
  741. } else if (routeType.value == "7") {
  742. uni.navigateTo({
  743. url: `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}`,
  744. });
  745. } else if (routeType.value == "8") {
  746. uni.navigateTo({
  747. url: `/subpackage/after-sale/account-recharge/recharge-weixin?accountId=${state.accountId}`,
  748. });
  749. } else if (routeType.value == "9") {
  750. uni.navigateTo({
  751. url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&accountId=${state.accountId}`,
  752. });
  753. } else if (routeType.value == "10") {
  754. uni.navigateTo({
  755. url: `/subpackage/personal-center/vehicle-change/vehicle-change-choiceType?vehicleId=${state.vehicleId}`,
  756. });
  757. } else if (routeType.value == "11") {
  758. uni.navigateTo({
  759. url: `/subpackage/after-sale/renewalContral/result?vehicleId=${state.vehicleId}&transWay=blu`,
  760. });
  761. } else if (routeType.value == "12") {
  762. uni.navigateTo({
  763. url: `/subpackage/after-sale/releaseSuspension/cardloss?${objectToQueryString(state.pageParams)}`
  764. })
  765. } else if (routeType.value == "13") {
  766. uni.navigateTo({
  767. url: `/subpackage/after-sale/ETC-log-off/log-off-connect-etc?${objectToQueryString(state.pageParams)}`
  768. })
  769. } else {
  770. return;
  771. }
  772. }
  773. /**
  774. * 前装设备
  775. */
  776. const preDevice = (res) => {
  777. console.log("连接成功1111=====", res);
  778. if (res.code == 0 || res.serviceCode == 0) {
  779. console.log("连接成功=====");
  780. datas.setData("bluLinkStatus", true);
  781. datas.setData("connectPrefixName", connectPrefixName.value);
  782. getCardId((cardNo) => {
  783. console.log("cardNo", cardNo);
  784. if (cardNo.includes('5201')) {
  785. // 正常激活 前装 5201
  786. oks()
  787. } else {
  788. // 前装9901
  789. etcOks()
  790. }
  791. })
  792. } else {
  793. alertF(res.msg);
  794. console.log(res.msg);
  795. }
  796. };
  797. function getCardId(fun) {
  798. //执行0015文件
  799. // tools.showLoadingAlert("执行指令");
  800. let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY];
  801. console.log(cmdArr);
  802. console.log(bluetoothUtil);
  803. bluetoothUtil.transCmd(cmdArr, '10', function (res) { //10:写卡 20:写OBU
  804. console.log("res====", res)
  805. var cardStr = res[2];
  806. if (cardStr == undefined || cardStr == "undefined" || cardStr == "") {
  807. tools.alertF("卡指令不符" + cardStr);
  808. return;
  809. }
  810. if (cardStr.length < 40) {
  811. tools.alertF("卡指令长度不符" + cardStr);
  812. return;
  813. }
  814. tools.hideLoadingAlert();
  815. fun(cardStr.substring(20, 40));
  816. })
  817. }
  818. function etcOks() {
  819. if (routeType.value == "4") {
  820. uni.navigateTo({
  821. url: "/subpackage/carPark/etc/etcDeviceInfo",
  822. });
  823. }
  824. }
  825. /**
  826. * 监听蓝牙状态
  827. */
  828. const listenStatus = (res) => {
  829. console.log("时时监听蓝牙状态func2", connectPrefixName.value, res.code);
  830. console.log(res);
  831. if (res.code == 0) {
  832. datas.setData("bluLinkStatus", true);
  833. datas.setData("connectPrefixName", connectPrefixName.value);
  834. // oks();
  835. } else {
  836. //断开蓝牙
  837. bluetoothUtil.disconnectDevice();
  838. datas.setData("bluLinkStatus", false);
  839. datas.setData("connectPrefixName", "");
  840. tools.showToastAlert("蓝牙已断开");
  841. // #ifdef MP-ALIPAY
  842. my.closeBluetoothAdapter({
  843. success(res) {
  844. // 关闭蓝牙适配器成功
  845. },
  846. fail(err) {
  847. // 处理关闭蓝牙适配器失败的情况
  848. }
  849. })
  850. // #endif
  851. }
  852. };
  853. /**
  854. * 提示加关蓝牙
  855. */
  856. const alertF = (msg : string) => {
  857. //隐藏加载框
  858. tools.hideLoadingAlert();
  859. //断开蓝牙
  860. bluetoothUtil.disconnectDevice();
  861. //提示对话框
  862. tools.showModalAlert(msg);
  863. };
  864. </script>
  865. <style>
  866. page {
  867. background-color: #f3f3f3;
  868. }
  869. :deep(.u-mode-center-box) {
  870. border-radius: 20rpx;
  871. }
  872. </style>
  873. <style lang="scss" scoped>
  874. .devices {
  875. min-height: 100vh;
  876. box-sizing: border-box;
  877. padding-bottom: 160rpx;
  878. position: relative;
  879. padding-top: 30rpx;
  880. background: #E9EDF0;
  881. .action {
  882. position: absolute;
  883. bottom: 0rpx;
  884. left: 0;
  885. height: 128rpx;
  886. background-color: #fff;
  887. border-radius: 30rpx 30rpx 0 0;
  888. width: 100vw;
  889. display: flex;
  890. align-items: center;
  891. justify-content: center;
  892. flex-direction: column;
  893. }
  894. .device {
  895. margin: 0 auto;
  896. width: 701rpx;
  897. display: flex;
  898. flex-direction: row;
  899. align-items: center;
  900. background: white;
  901. padding: 25rpx 20rpx;
  902. box-sizing: border-box;
  903. background: #FFFFFF;
  904. box-shadow: 2rpx 6rpx 6rpx 6rpx #DFDFDF;
  905. border-radius: 12rpx;
  906. .head {
  907. width: 120rpx;
  908. height: 120rpx;
  909. border-radius: 10rpx;
  910. background-color: #f3f3f3;
  911. }
  912. .center {
  913. flex: 1;
  914. margin-left: 30rpx;
  915. margin-right: 30rpx;
  916. .name {
  917. font-size: 30rpx;
  918. color: #333333;
  919. }
  920. .desc {
  921. font-size: 26rpx;
  922. color: #666666;
  923. margin-top: 25rpx;
  924. }
  925. }
  926. .icon {
  927. width: 38rpx;
  928. height: 38rpx;
  929. margin-right: 12rpx;
  930. }
  931. }
  932. .hint {
  933. margin: 60rpx 30rpx 0px;
  934. .txt {
  935. font-family: MicrosoftYaHei;
  936. font-size: 28rpx;
  937. color: #111111;
  938. line-height: 40rpx;
  939. display: flex;
  940. align-items: center;
  941. .imgs {
  942. width: 30rpx;
  943. height: 30rpx;
  944. margin-right: 10rpx;
  945. }
  946. }
  947. .grey-txt {
  948. font-size: 28rpx;
  949. color: #999;
  950. line-height: 40rpx;
  951. margin-top: 16rpx;
  952. }
  953. }
  954. .btn {
  955. margin: 70rpx 40rpx;
  956. }
  957. }
  958. </style>