Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

bluetooth.vue 24KB

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