Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

bluetooth.vue 26KB

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