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

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