You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bluetooth.vue 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  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. }else if (name.split("-")[1] == "WQ") {
  335. _name = "握奇";
  336. }
  337. break;
  338. case "WJ":
  339. _name = "万集";
  340. break;
  341. case "JL":
  342. _name = "聚利";
  343. break;
  344. case "BY":
  345. _name = "宝溢";
  346. case "JY":
  347. _name = "金溢";
  348. break;
  349. case "AT":
  350. _name = "埃特斯";
  351. break;
  352. case "JT":
  353. _name = "建投";
  354. break;
  355. case "WQ":
  356. _name = "握奇";
  357. break;
  358. case "CG":
  359. _name = "成谷";
  360. break;
  361. case "TD":
  362. _name = "天地融";
  363. break;
  364. case "ZZ":
  365. _name = "智载";
  366. break;
  367. case "MC":
  368. _name = "铭创";
  369. break;
  370. default:
  371. _name = "未知";
  372. break;
  373. }
  374. device._name = _name;
  375. if (deviceList.value.length == 0) {
  376. // #ifdef MP-ALIPAY
  377. if (device._name == '聚利' || device._name == '万集' || device._name == '天地融' || device._name == '建投') {
  378. foundDevices.push(device);
  379. }
  380. // #endif
  381. // #ifdef MP-WEIXIN
  382. foundDevices.push(device);
  383. // #endif
  384. } else {
  385. let isHave = false;
  386. for (let j = 0; j < foundDevices.length; j++) {
  387. if (name == foundDevices[j].deviceId) {
  388. isHave = true;
  389. break;
  390. }
  391. }
  392. if (!isHave) {
  393. foundDevices.push(device);
  394. }
  395. }
  396. datas.setData("deviceNameZW", device._name);
  397. deviceList.value = foundDevices;
  398. foundDevices = [];
  399. console.log("deviceList.value", deviceList.value);
  400. }
  401. }
  402. }
  403. });
  404. },
  405. fail: function (res) {
  406. console.log(res);
  407. tools.hideLoadingAlert();
  408. },
  409. });
  410. },
  411. fail: function (res) {
  412. console.log(res);
  413. alertF("手机蓝牙未打开或不支持蓝牙");
  414. },
  415. });
  416. };
  417. /**
  418. * 连接蓝牙
  419. */
  420. const connectDevice = (e) => {
  421. console.log(e);
  422. let item = e;
  423. //停止扫描蓝牙
  424. console.info("停止搜寻附近的蓝牙外围设备");
  425. uni.stopBluetoothDevicesDiscovery({
  426. success: function (res) {
  427. console.log(device);
  428. if (item.selected == false) {
  429. console.log("第一次点击了");
  430. item.selected = true;
  431. setTimeout(function () {
  432. if (device.selected == undefined) {
  433. console.info("selected is undefined");
  434. linkFail(); //未找到设备, 请重新搜索
  435. return;
  436. }
  437. item.selected = false;
  438. }, 4000);
  439. } else {
  440. console.log("第二次点击了");
  441. return;
  442. }
  443. if (
  444. item.prefixName == undefined ||
  445. item.prefixName == "undefined" ||
  446. item.prefixName == ""
  447. ) {
  448. console.info("device.prefixName is undefined");
  449. linkFail(); //未找到设备, 请重新搜索
  450. return;
  451. }
  452. let prefixName = item.prefixName;
  453. connectPrefixName.value = item.prefixName;
  454. console.log(item);
  455. // datas.setData("connectPrefixName", connectPrefixName.value);
  456. // //断开蓝牙
  457. // bluetoothUtil.disconnectDevice();
  458. tools.showLoadingAlert("蓝牙连接中");
  459. console.info("连接的是" + prefixName, device);
  460. switch (prefixName) {
  461. case "ETC":
  462. 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"))
  463. let obj = ""
  464. if (device.name.includes("KC") || device.name.includes("K")) {
  465. obj = kcApi
  466. } else if (device.name.includes("JL")) {
  467. obj = jlQZApi
  468. } else if (device.name.includes("WJ")) {
  469. obj = wjApi9901
  470. } else if (device.name.includes("ATS")) {
  471. obj = ArtcBleUtilApi
  472. } else if (device.name.includes("MC")) {
  473. obj = mcApi9901
  474. } else if (device.name.includes("WQ")) {
  475. obj = wqApi
  476. }
  477. console.log("新")
  478. obj.connectDevice(
  479. device,
  480. function (res) {
  481. preDevice(res);
  482. },
  483. function (res) {
  484. listenStatus(res);
  485. }
  486. );
  487. // else if (device.name.includes("JY")) {
  488. // console.log("进来了JY",device.name.includes("JY"))
  489. // jyApiEtc.connectDevice(
  490. // device,
  491. // function (res) {
  492. // preDevice(res);
  493. // },
  494. // function (res) {
  495. // listenStatus(res);
  496. // }
  497. // );
  498. // }
  499. break;
  500. case "WJ":
  501. console.log("旧")
  502. wjApi.connectDevice(
  503. device,
  504. function (res) {
  505. connectSuccess(res);
  506. },
  507. function (res) {
  508. listenStatus(res);
  509. }
  510. );
  511. break;
  512. case "JL":
  513. jlApi.connectDevice(
  514. device,
  515. function (res) {
  516. console.log('设备链接1', res)
  517. connectSuccess(res);
  518. },
  519. function (res) {
  520. console.log('设备链接2', res)
  521. listenStatus(res);
  522. }
  523. );
  524. break;
  525. case "BY":
  526. // 宝溢用金溢sdk
  527. jyApi.connectDevice(
  528. device,
  529. function (res) {
  530. console.log('设备链接1', res)
  531. connectSuccess(res);
  532. },
  533. function (res) {
  534. console.log('设备链接2', res)
  535. listenStatus(res);
  536. }
  537. );
  538. break;
  539. case "JY":
  540. jyApi.connectDevice(
  541. device,
  542. function (res) {
  543. connectSuccess(res);
  544. },
  545. function (res) {
  546. listenStatus(res);
  547. }
  548. );
  549. break;
  550. case "AT":
  551. atApi.connectDevice(
  552. device,
  553. function (res) {
  554. connectSuccess(res);
  555. },
  556. function (res) {
  557. listenStatus(res);
  558. }
  559. );
  560. break;
  561. case "JT":
  562. console.info("连接的是=====123" + prefixName, device);
  563. jtApi.connectDevice(
  564. device,
  565. function (res) {
  566. console.log('设备链接1', res)
  567. connectSuccess(res);
  568. },
  569. function (res) {
  570. console.log('设备链接2', res)
  571. listenStatus(res);
  572. }
  573. );
  574. break;
  575. case "WQ":
  576. console.log("wqApi",wqApi)
  577. wqApi.connectDevice(
  578. device,
  579. function (res) {
  580. connectSuccess(res);
  581. },
  582. function (res) {
  583. listenStatus(res);
  584. }
  585. );
  586. break;
  587. case "CG":
  588. cgApi.connectDevice(
  589. device,
  590. function (res) {
  591. connectSuccess(res);
  592. },
  593. function (res) {
  594. listenStatus(res);
  595. }
  596. );
  597. break;
  598. case "TD":
  599. tdApi.connectDevice(
  600. device,
  601. function (res) {
  602. connectSuccess(res)
  603. }, function (res) {
  604. listenStatus(res);
  605. }
  606. );
  607. break;
  608. case "ZZ":
  609. zzApi.connectDevice(
  610. device,
  611. function (res) {
  612. connectSuccess(res);
  613. },
  614. function (res) {
  615. listenStatus(res);
  616. }
  617. );
  618. break;
  619. case "MC":
  620. mcApi.connectDevice(
  621. device,
  622. function (res) {
  623. connectSuccess(res);
  624. },
  625. function (res) {
  626. listenStatus(res);
  627. }
  628. );
  629. break;
  630. default: //未找到设备, 请重新搜索
  631. linkFail();
  632. break;
  633. }
  634. },
  635. fail: function (res) {
  636. console.log(res);
  637. linkFail(); //未找到设备, 请重新搜索
  638. },
  639. });
  640. };
  641. /**
  642. * 未找到设备, 请重新搜索
  643. */
  644. const linkFail = () => {
  645. datas.setData("bluLinkStatus", false);
  646. datas.setData("connectPrefixName", "");
  647. tools.showModalAlert("未找到设备, 请重新搜索", function successFunc() {
  648. load();
  649. });
  650. };
  651. /**
  652. * 连接成功
  653. */
  654. const connectSuccess = (res) => {
  655. console.log("连接回调函数func1");
  656. console.log(res);
  657. if (res.code == 0) {
  658. console.log("连接成功");
  659. tools.hideLoadingAlert(); //关闭加载框
  660. datas.setData("bluLinkStatus", true);
  661. datas.setData("connectPrefixName", connectPrefixName.value);
  662. // startHeartbeat() //执行心跳
  663. oks();
  664. } else {
  665. alertF(res.msg);
  666. }
  667. };
  668. // ====================== 页面卸载时清理资源 ======================
  669. onUnload(() => {
  670. // stopHeartbeat();
  671. // 实际项目中需调用 uni.closeBLEConnection 断开连接
  672. console.log('页面卸载,清理资源');
  673. });
  674. function oks() {
  675. //routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.ping码解锁 4.信息读取 5从哪里来回哪里去监听bluetoothLink 7消费明细去圈存 8单位账户圈存 9对公账户修复
  676. if (routeType.value == "1") {
  677. if (state.isAfter == '1') {
  678. uni.navigateTo({
  679. url: `/subpackage/after-sale/activation/activate-SH`,
  680. });
  681. } else {
  682. uni.navigateTo({
  683. url: `/subpackage/after-sale/activation/activate?transfer=${state.transfer}`,
  684. });
  685. }
  686. } else if (routeType.value == "2") {
  687. uni.navigateTo({
  688. url: `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=${state.connectSuccess}`,
  689. });
  690. } else if (routeType.value == "3") {
  691. uni.navigateTo({
  692. url: "/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?state=true&vehicleId=" + state.vehicleId,
  693. });
  694. } else if (routeType.value == "4") {
  695. uni.navigateTo({
  696. url: `/subpackage/after-sale/deviceInfo/deviceInfo?backIndex=${state.backIndex}`,
  697. });
  698. } else if (routeType.value == "5") {
  699. // #ifdef MP-ALIPAY
  700. uni.navigateTo({
  701. url: "/subpackage/after-sale/activation-once-again/activation-once-again-ali?state=true&id=" + state.id,
  702. });
  703. // #endif
  704. // #ifdef MP-WEIXIN
  705. if (state.difference == "1") {
  706. uni.navigateTo({
  707. url: `/subpackage/after-sale/activation-once-again/activation-once-again?status=true&state=true&vehicleId=${state.vehicleId}&vehPosImgUrl=${state.vehPosImgUrl}&vehNegImgUrl=${state.vehNegImgUrl}`,
  708. });
  709. } else if (state.difference == "2") {
  710. uni.navigateTo({
  711. url: `/subpackage/after-sale/refund-order-balance/refund-order-balance?status=true&state=true&vehicleId=${state.vehicleId}&&id=${state.id}&&refundBalance=${state.refundBalance}`,
  712. });
  713. } else {
  714. uni.$emit('bluetoothLink', { status: true })
  715. uni.navigateBack({
  716. delta: 1
  717. })
  718. }
  719. // #endif
  720. } else if (routeType.value == "6") {
  721. uni.navigateTo({
  722. url: "/subpackage/after-sale/activation-once-again/activation-once-again?state=true&id=" + state.id
  723. });
  724. } else if (routeType.value == "7") {
  725. uni.navigateTo({
  726. url: `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}`,
  727. });
  728. } else if (routeType.value == "8") {
  729. uni.navigateTo({
  730. url: `/subpackage/after-sale/account-recharge/recharge-weixin?accountId=${state.accountId}`,
  731. });
  732. } else if (routeType.value == "9") {
  733. uni.navigateTo({
  734. url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&accountId=${state.accountId}`,
  735. });
  736. } else if (routeType.value == "10") {
  737. uni.navigateTo({
  738. url: `/subpackage/personal-center/car-message-change?vehicleId=${state.vehicleId}`,
  739. });
  740. } else {
  741. return;
  742. }
  743. }
  744. /**
  745. * 前装设备
  746. */
  747. const preDevice = (res) => {
  748. console.log("连接成功1111=====", res);
  749. if (res.code == 0 || res.serviceCode == 0) {
  750. console.log("连接成功=====");
  751. datas.setData("bluLinkStatus", true);
  752. datas.setData("connectPrefixName", connectPrefixName.value);
  753. getCardId((cardNo) => {
  754. console.log("cardNo", cardNo);
  755. if (cardNo.includes('5201')) {
  756. // 正常激活 前装 5201
  757. oks()
  758. } else {
  759. // 前装9901
  760. etcOks()
  761. }
  762. })
  763. } else {
  764. alertF(res.msg);
  765. console.log(res.msg);
  766. }
  767. };
  768. function getCardId(fun) {
  769. //执行0015文件
  770. // tools.showLoadingAlert("执行指令");
  771. let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY];
  772. console.log(cmdArr);
  773. console.log(bluetoothUtil);
  774. bluetoothUtil.transCmd(cmdArr, '10', function (res) { //10:写卡 20:写OBU
  775. console.log("res====", res)
  776. var cardStr = res[2];
  777. if (cardStr == undefined || cardStr == "undefined" || cardStr == "") {
  778. tools.alertF("卡指令不符" + cardStr);
  779. return;
  780. }
  781. if (cardStr.length < 40) {
  782. tools.alertF("卡指令长度不符" + cardStr);
  783. return;
  784. }
  785. tools.hideLoadingAlert();
  786. fun(cardStr.substring(20, 40));
  787. })
  788. }
  789. function etcOks() {
  790. if (routeType.value == "4") {
  791. uni.navigateTo({
  792. url: "/subpackage/carPark/etc/etcDeviceInfo",
  793. });
  794. }
  795. }
  796. /**
  797. * 监听蓝牙状态
  798. */
  799. const listenStatus = (res) => {
  800. console.log("时时监听蓝牙状态func2", connectPrefixName.value, res.code);
  801. console.log(res);
  802. if (res.code == 0) {
  803. datas.setData("bluLinkStatus", true);
  804. datas.setData("connectPrefixName", connectPrefixName.value);
  805. // oks();
  806. } else {
  807. //断开蓝牙
  808. bluetoothUtil.disconnectDevice();
  809. datas.setData("bluLinkStatus", false);
  810. datas.setData("connectPrefixName", "");
  811. tools.showToastAlert("蓝牙已断开");
  812. // #ifdef MP-ALIPAY
  813. my.closeBluetoothAdapter({
  814. success(res) {
  815. // 关闭蓝牙适配器成功
  816. },
  817. fail(err) {
  818. // 处理关闭蓝牙适配器失败的情况
  819. }
  820. })
  821. // #endif
  822. }
  823. };
  824. /**
  825. * 提示加关蓝牙
  826. */
  827. const alertF = (msg : string) => {
  828. //隐藏加载框
  829. tools.hideLoadingAlert();
  830. //断开蓝牙
  831. bluetoothUtil.disconnectDevice();
  832. //提示对话框
  833. tools.showModalAlert(msg);
  834. };
  835. </script>
  836. <style>
  837. page {
  838. background-color: #f3f3f3;
  839. }
  840. :deep(.u-mode-center-box) {
  841. border-radius: 20rpx;
  842. }
  843. </style>
  844. <style lang="scss" scoped>
  845. .devices {
  846. min-height: 100vh;
  847. box-sizing: border-box;
  848. padding-bottom: 160rpx;
  849. position: relative;
  850. padding-top: 30rpx;
  851. background: #E9EDF0;
  852. .action {
  853. position: absolute;
  854. bottom: 0rpx;
  855. left: 0;
  856. height: 128rpx;
  857. background-color: #fff;
  858. border-radius: 30rpx 30rpx 0 0;
  859. width: 100vw;
  860. display: flex;
  861. align-items: center;
  862. justify-content: center;
  863. flex-direction: column;
  864. }
  865. .device {
  866. margin: 0 auto;
  867. width: 701rpx;
  868. display: flex;
  869. flex-direction: row;
  870. align-items: center;
  871. background: white;
  872. padding: 25rpx 20rpx;
  873. box-sizing: border-box;
  874. background: #FFFFFF;
  875. box-shadow: 2rpx 6rpx 6rpx 6rpx #DFDFDF;
  876. border-radius: 12rpx;
  877. .head {
  878. width: 120rpx;
  879. height: 120rpx;
  880. border-radius: 10rpx;
  881. background-color: #f3f3f3;
  882. }
  883. .center {
  884. flex: 1;
  885. margin-left: 30rpx;
  886. margin-right: 30rpx;
  887. .name {
  888. font-size: 30rpx;
  889. color: #333333;
  890. }
  891. .desc {
  892. font-size: 26rpx;
  893. color: #666666;
  894. margin-top: 25rpx;
  895. }
  896. }
  897. .icon {
  898. width: 38rpx;
  899. height: 38rpx;
  900. margin-right: 12rpx;
  901. }
  902. }
  903. .hint {
  904. margin: 60rpx 30rpx 0px;
  905. .txt {
  906. font-family: MicrosoftYaHei;
  907. font-size: 28rpx;
  908. color: #111111;
  909. line-height: 40rpx;
  910. display: flex;
  911. align-items: center;
  912. .imgs {
  913. width: 30rpx;
  914. height: 30rpx;
  915. margin-right: 10rpx;
  916. }
  917. }
  918. .grey-txt {
  919. font-size: 28rpx;
  920. color: #999;
  921. line-height: 40rpx;
  922. margin-top: 16rpx;
  923. }
  924. }
  925. .btn {
  926. margin: 70rpx 40rpx;
  927. }
  928. }
  929. </style>