Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

bluetooth.vue 24KB

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