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 25KB

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