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

bluetooth.vue 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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. device['sendTimeout']=20000
  572. wqApi.connectDevice(
  573. device,
  574. function (res) {
  575. connectSuccess(res);
  576. },
  577. function (res) {
  578. listenStatus(res);
  579. }
  580. );
  581. break;
  582. case "CG":
  583. cgApi.connectDevice(
  584. device,
  585. function (res) {
  586. connectSuccess(res);
  587. },
  588. function (res) {
  589. listenStatus(res);
  590. }
  591. );
  592. break;
  593. case "TD":
  594. tdApi.connectDevice(
  595. device,
  596. function (res) {
  597. connectSuccess(res)
  598. }, function (res) {
  599. listenStatus(res);
  600. }
  601. );
  602. break;
  603. case "ZZ":
  604. zzApi.connectDevice(
  605. device,
  606. function (res) {
  607. connectSuccess(res);
  608. },
  609. function (res) {
  610. listenStatus(res);
  611. }
  612. );
  613. break;
  614. case "MC":
  615. mcApi.connectDevice(
  616. device,
  617. function (res) {
  618. connectSuccess(res);
  619. },
  620. function (res) {
  621. listenStatus(res);
  622. }
  623. );
  624. break;
  625. default: //未找到设备, 请重新搜索
  626. linkFail();
  627. break;
  628. }
  629. },
  630. fail: function (res) {
  631. console.log(res);
  632. linkFail(); //未找到设备, 请重新搜索
  633. },
  634. });
  635. };
  636. /**
  637. * 未找到设备, 请重新搜索
  638. */
  639. const linkFail = () => {
  640. datas.setData("bluLinkStatus", false);
  641. datas.setData("connectPrefixName", "");
  642. tools.showModalAlert("未找到设备, 请重新搜索", function successFunc() {
  643. load();
  644. });
  645. };
  646. /**
  647. * 连接成功
  648. */
  649. const connectSuccess = (res) => {
  650. console.log("连接回调函数func1");
  651. console.log(res);
  652. if (res.code == 0) {
  653. console.log("连接成功");
  654. tools.hideLoadingAlert(); //关闭加载框
  655. datas.setData("bluLinkStatus", true);
  656. datas.setData("connectPrefixName", connectPrefixName.value);
  657. oks();
  658. } else {
  659. alertF(res.msg);
  660. }
  661. };
  662. function oks() {
  663. //routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.ping码解锁 4.信息读取 5从哪里来回哪里去监听bluetoothLink 7消费明细去圈存 8单位账户圈存 9对公账户修复
  664. if (routeType.value == "1") {
  665. if (state.isAfter == '1') {
  666. uni.navigateTo({
  667. url: `/subpackage/after-sale/activation/activate-SH`,
  668. });
  669. } else {
  670. uni.navigateTo({
  671. url: `/subpackage/after-sale/activation/activate?transfer=${state.transfer}`,
  672. });
  673. }
  674. } else if (routeType.value == "2") {
  675. uni.navigateTo({
  676. url: `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=${state.connectSuccess}`,
  677. });
  678. } else if (routeType.value == "3") {
  679. uni.navigateTo({
  680. url: "/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?state=true&vehicleId=" + state.vehicleId,
  681. });
  682. } else if (routeType.value == "4") {
  683. uni.navigateTo({
  684. url: `/subpackage/after-sale/deviceInfo/deviceInfo?backIndex=${state.backIndex}`,
  685. });
  686. } else if (routeType.value == "5") {
  687. // #ifdef MP-ALIPAY
  688. uni.navigateTo({
  689. url: "/subpackage/after-sale/activation-once-again/activation-once-again-ali?state=true&id=" + state.id,
  690. });
  691. // #endif
  692. // #ifdef MP-WEIXIN
  693. if (state.difference == "1") {
  694. uni.navigateTo({
  695. url: `/subpackage/after-sale/activation-once-again/activation-once-again?status=true&state=true&vehicleId=${state.vehicleId}&vehPosImgUrl=${state.vehPosImgUrl}&vehNegImgUrl=${state.vehNegImgUrl}`,
  696. });
  697. } else if (state.difference == "2") {
  698. uni.navigateTo({
  699. url: `/subpackage/after-sale/refund-order-balance/refund-order-balance?status=true&state=true&vehicleId=${state.vehicleId}&&id=${state.id}&&refundBalance=${state.refundBalance}`,
  700. });
  701. } else {
  702. uni.$emit('bluetoothLink', { status: true })
  703. uni.navigateBack({
  704. delta: 1
  705. })
  706. }
  707. // #endif
  708. } else if (routeType.value == "6") {
  709. uni.navigateTo({
  710. url: "/subpackage/after-sale/activation-once-again/activation-once-again?state=true&id=" + state.id
  711. });
  712. } else if (routeType.value == "7") {
  713. uni.navigateTo({
  714. url: `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}`,
  715. });
  716. } else if (routeType.value == "8") {
  717. uni.navigateTo({
  718. url: `/subpackage/after-sale/account-recharge/recharge-weixin?accountId=${state.accountId}`,
  719. });
  720. } else if (routeType.value == "9") {
  721. uni.navigateTo({
  722. url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&accountId=${state.accountId}`,
  723. });
  724. } else if (routeType.value == "10") {
  725. uni.navigateTo({
  726. url: `/subpackage/personal-center/car-message-change?vehicleId=${state.vehicleId}`,
  727. });
  728. } else {
  729. return;
  730. }
  731. }
  732. /**
  733. * 前装设备
  734. */
  735. const preDevice = (res) => {
  736. console.log("连接成功1111=====", res);
  737. if (res.code == 0 || res.serviceCode==0) {
  738. console.log("连接成功=====");
  739. datas.setData("bluLinkStatus", true);
  740. datas.setData("connectPrefixName", connectPrefixName.value);
  741. getCardId((cardNo) => {
  742. console.log("cardNo",cardNo);
  743. if(cardNo.includes('5201')){
  744. // 正常激活 前装 5201
  745. oks()
  746. }else{
  747. // 前装9901
  748. etcOks()
  749. }
  750. })
  751. } else {
  752. alertF(res.msg);
  753. console.log(res.msg);
  754. }
  755. };
  756. function getCardId(fun){
  757. //执行0015文件
  758. tools.showLoadingAlert("执行指令");
  759. let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY];
  760. console.log(cmdArr);
  761. console.log(bluetoothUtil);
  762. bluetoothUtil.transCmd(cmdArr, '10', function(res) { //10:写卡 20:写OBU
  763. console.log("res====", res)
  764. var cardStr = res[2];
  765. if (cardStr == undefined || cardStr == "undefined" || cardStr == "") {
  766. tools.alertF("卡指令不符" + cardStr);
  767. return;
  768. }
  769. if (cardStr.length < 40) {
  770. tools.alertF("卡指令长度不符" + cardStr);
  771. return;
  772. }
  773. tools.hideLoadingAlert();
  774. fun(cardStr.substring(20, 40));
  775. })
  776. }
  777. function etcOks() {
  778. if (routeType.value == "4") {
  779. uni.navigateTo({
  780. url: "/subpackage/carPark/etc/etcDeviceInfo",
  781. });
  782. }
  783. }
  784. /**
  785. * 监听蓝牙状态
  786. */
  787. const listenStatus = (res) => {
  788. console.log("时时监听蓝牙状态func2", connectPrefixName.value, res.code);
  789. console.log(res);
  790. if (res.code == 0) {
  791. datas.setData("bluLinkStatus", true);
  792. datas.setData("connectPrefixName", connectPrefixName.value);
  793. // oks();
  794. } else {
  795. //断开蓝牙
  796. bluetoothUtil.disconnectDevice();
  797. datas.setData("bluLinkStatus", false);
  798. datas.setData("connectPrefixName", "");
  799. tools.showToastAlert("蓝牙已断开");
  800. // #ifdef MP-ALIPAY
  801. my.closeBluetoothAdapter({
  802. success(res) {
  803. // 关闭蓝牙适配器成功
  804. },
  805. fail(err) {
  806. // 处理关闭蓝牙适配器失败的情况
  807. }
  808. })
  809. // #endif
  810. }
  811. };
  812. /**
  813. * 提示加关蓝牙
  814. */
  815. const alertF = (msg : string) => {
  816. //隐藏加载框
  817. tools.hideLoadingAlert();
  818. //断开蓝牙
  819. bluetoothUtil.disconnectDevice();
  820. //提示对话框
  821. tools.showModalAlert(msg);
  822. };
  823. </script>
  824. <style>
  825. page {
  826. background-color: #f3f3f3;
  827. }
  828. :deep(.u-mode-center-box) {
  829. border-radius: 20rpx;
  830. }
  831. </style>
  832. <style lang="scss" scoped>
  833. .devices {
  834. min-height: 100vh;
  835. box-sizing: border-box;
  836. padding-bottom: 160rpx;
  837. position: relative;
  838. padding-top: 30rpx;
  839. background: #E9EDF0;
  840. .action {
  841. position: absolute;
  842. bottom: 0rpx;
  843. left: 0;
  844. height: 128rpx;
  845. background-color: #fff;
  846. border-radius: 30rpx 30rpx 0 0;
  847. width: 100vw;
  848. display: flex;
  849. align-items: center;
  850. justify-content: center;
  851. flex-direction: column;
  852. }
  853. .device {
  854. margin: 0 auto;
  855. width: 701rpx;
  856. display: flex;
  857. flex-direction: row;
  858. align-items: center;
  859. background: white;
  860. padding: 25rpx 20rpx;
  861. box-sizing: border-box;
  862. background: #FFFFFF;
  863. box-shadow: 2rpx 6rpx 6rpx 6rpx #DFDFDF;
  864. border-radius: 12rpx;
  865. .head {
  866. width: 120rpx;
  867. height: 120rpx;
  868. border-radius: 10rpx;
  869. background-color: #f3f3f3;
  870. }
  871. .center {
  872. flex: 1;
  873. margin-left: 30rpx;
  874. margin-right: 30rpx;
  875. .name {
  876. font-size: 30rpx;
  877. color: #333333;
  878. }
  879. .desc {
  880. font-size: 26rpx;
  881. color: #666666;
  882. margin-top: 25rpx;
  883. }
  884. }
  885. .icon {
  886. width: 38rpx;
  887. height: 38rpx;
  888. margin-right: 12rpx;
  889. }
  890. }
  891. .hint {
  892. margin: 60rpx 30rpx 0px;
  893. .txt {
  894. font-family: MicrosoftYaHei;
  895. font-size: 28rpx;
  896. color: #111111;
  897. line-height: 40rpx;
  898. display: flex;
  899. align-items: center;
  900. .imgs {
  901. width: 30rpx;
  902. height: 30rpx;
  903. margin-right: 10rpx;
  904. }
  905. }
  906. .grey-txt {
  907. font-size: 28rpx;
  908. color: #999;
  909. line-height: 40rpx;
  910. margin-top: 16rpx;
  911. }
  912. }
  913. .btn {
  914. margin: 70rpx 40rpx;
  915. }
  916. }
  917. </style>