選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

bluetooth.vue 25KB

6ヶ月前
6ヶ月前
6ヶ月前
1年前
6ヶ月前
6ヶ月前
6ヶ月前
1年前
1年前
5ヶ月前
5ヶ月前
1年前
6ヶ月前
1年前
1年前
10ヶ月前
6ヶ月前
6ヶ月前
7ヶ月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
6ヶ月前
10ヶ月前
7ヶ月前
6ヶ月前
7ヶ月前
6ヶ月前
6ヶ月前
1年前
1年前
1年前
1年前
1年前
1年前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
1年前
1年前
1年前
1年前
6ヶ月前
5ヶ月前
11ヶ月前
5ヶ月前
5ヶ月前
1年前
5ヶ月前
11ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
1年前
1年前
1年前
6ヶ月前
7ヶ月前
6ヶ月前
11ヶ月前
7ヶ月前
6ヶ月前
6ヶ月前
1年前
1年前
1年前
1年前
7ヶ月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
6ヶ月前
7ヶ月前
5ヶ月前
1年前
5ヶ月前
6ヶ月前
1年前
1年前
6ヶ月前
6ヶ月前
6ヶ月前
6ヶ月前
6ヶ月前
6ヶ月前
6ヶ月前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  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. deviceList.value = foundDevices;
  373. foundDevices = [];
  374. console.log("deviceList.value", deviceList.value);
  375. }
  376. }
  377. }
  378. });
  379. },
  380. fail: function (res) {
  381. console.log(res);
  382. tools.hideLoadingAlert();
  383. },
  384. });
  385. },
  386. fail: function (res) {
  387. console.log(res);
  388. alertF("手机蓝牙未打开或不支持蓝牙");
  389. },
  390. });
  391. };
  392. /**
  393. * 连接蓝牙
  394. */
  395. const connectDevice = (e) => {
  396. console.log(e);
  397. let item = e;
  398. //停止扫描蓝牙
  399. console.info("停止搜寻附近的蓝牙外围设备");
  400. uni.stopBluetoothDevicesDiscovery({
  401. success: function (res) {
  402. console.log(device);
  403. if (item.selected == false) {
  404. console.log("第一次点击了");
  405. item.selected = true;
  406. setTimeout(function () {
  407. if (device.selected == undefined) {
  408. console.info("selected is undefined");
  409. linkFail(); //未找到设备, 请重新搜索
  410. return;
  411. }
  412. item.selected = false;
  413. }, 4000);
  414. } else {
  415. console.log("第二次点击了");
  416. return;
  417. }
  418. if (
  419. item.prefixName == undefined ||
  420. item.prefixName == "undefined" ||
  421. item.prefixName == ""
  422. ) {
  423. console.info("device.prefixName is undefined");
  424. linkFail(); //未找到设备, 请重新搜索
  425. return;
  426. }
  427. let prefixName = item.prefixName;
  428. connectPrefixName.value = item.prefixName;
  429. console.log(item);
  430. // datas.setData("connectPrefixName", connectPrefixName.value);
  431. // //断开蓝牙
  432. // bluetoothUtil.disconnectDevice();
  433. tools.showLoadingAlert("蓝牙连接中");
  434. console.info("连接的是" + prefixName, device);
  435. switch (prefixName) {
  436. case "ETC":
  437. 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"))
  438. let obj = ""
  439. if (device.name.includes("KC") || device.name.includes("K")) {
  440. obj=kcApi
  441. } else if (device.name.includes("JL")) {
  442. obj=jlQZApi
  443. } else if (device.name.includes("WJ")) {
  444. obj=wjApi9901
  445. }else if (device.name.includes("ATS")) {
  446. obj=ArtcBleUtilApi
  447. }else if (device.name.includes("MC")) {
  448. obj=mcApi9901
  449. }
  450. console.log("新")
  451. obj.connectDevice(
  452. device,
  453. function (res) {
  454. preDevice(res);
  455. },
  456. function (res) {
  457. listenStatus(res);
  458. }
  459. );
  460. // else if (device.name.includes("JY")) {
  461. // console.log("进来了JY",device.name.includes("JY"))
  462. // jyApiEtc.connectDevice(
  463. // device,
  464. // function (res) {
  465. // preDevice(res);
  466. // },
  467. // function (res) {
  468. // listenStatus(res);
  469. // }
  470. // );
  471. // }
  472. break;
  473. case "WJ":
  474. console.log("旧")
  475. wjApi.connectDevice(
  476. device,
  477. function (res) {
  478. connectSuccess(res);
  479. },
  480. function (res) {
  481. listenStatus(res);
  482. }
  483. );
  484. break;
  485. case "JL":
  486. jlApi.connectDevice(
  487. device,
  488. function (res) {
  489. console.log('设备链接1', res)
  490. connectSuccess(res);
  491. },
  492. function (res) {
  493. console.log('设备链接2', res)
  494. listenStatus(res);
  495. }
  496. );
  497. break;
  498. case "JY":
  499. jyApi.connectDevice(
  500. device,
  501. function (res) {
  502. connectSuccess(res);
  503. },
  504. function (res) {
  505. listenStatus(res);
  506. }
  507. );
  508. break;
  509. case "AT":
  510. atApi.connectDevice(
  511. device,
  512. function (res) {
  513. connectSuccess(res);
  514. },
  515. function (res) {
  516. listenStatus(res);
  517. }
  518. );
  519. break;
  520. case "JT":
  521. console.info("连接的是=====123" + prefixName, device);
  522. jtApi.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 "WQ":
  535. wqApi.connectDevice(
  536. device,
  537. function (res) {
  538. connectSuccess(res);
  539. },
  540. function (res) {
  541. listenStatus(res);
  542. }
  543. );
  544. break;
  545. case "CG":
  546. cgApi.connectDevice(
  547. device,
  548. function (res) {
  549. connectSuccess(res);
  550. },
  551. function (res) {
  552. listenStatus(res);
  553. }
  554. );
  555. break;
  556. case "TD":
  557. tdApi.connectDevice(
  558. device,
  559. function (res) {
  560. connectSuccess(res)
  561. }, function (res) {
  562. listenStatus(res);
  563. }
  564. );
  565. break;
  566. case "ZZ":
  567. zzApi.connectDevice(
  568. device,
  569. function (res) {
  570. connectSuccess(res);
  571. },
  572. function (res) {
  573. listenStatus(res);
  574. }
  575. );
  576. break;
  577. case "MC":
  578. mcApi.connectDevice(
  579. device,
  580. function (res) {
  581. connectSuccess(res);
  582. },
  583. function (res) {
  584. listenStatus(res);
  585. }
  586. );
  587. break;
  588. default: //未找到设备, 请重新搜索
  589. linkFail();
  590. break;
  591. }
  592. },
  593. fail: function (res) {
  594. console.log(res);
  595. linkFail(); //未找到设备, 请重新搜索
  596. },
  597. });
  598. };
  599. /**
  600. * 未找到设备, 请重新搜索
  601. */
  602. const linkFail = () => {
  603. datas.setData("bluLinkStatus", false);
  604. datas.setData("connectPrefixName", "");
  605. tools.showModalAlert("未找到设备, 请重新搜索", function successFunc() {
  606. load();
  607. });
  608. };
  609. /**
  610. * 连接成功
  611. */
  612. const connectSuccess = (res) => {
  613. console.log("连接回调函数func1");
  614. console.log(res);
  615. if (res.code == 0) {
  616. console.log("连接成功");
  617. tools.hideLoadingAlert(); //关闭加载框
  618. datas.setData("bluLinkStatus", true);
  619. datas.setData("connectPrefixName", connectPrefixName.value);
  620. oks();
  621. } else {
  622. alertF(res.msg);
  623. }
  624. };
  625. function oks() {
  626. //routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.ping码解锁 4.信息读取 5从哪里来回哪里去监听bluetoothLink 7消费明细去圈存 8单位账户圈存 9对公账户修复
  627. if (routeType.value == "1") {
  628. if (state.isAfter == '1') {
  629. uni.navigateTo({
  630. url: `/subpackage/after-sale/activation/activate-SH`,
  631. });
  632. } else {
  633. uni.navigateTo({
  634. url: `/subpackage/after-sale/activation/activate?transfer=${state.transfer}`,
  635. });
  636. }
  637. } else if (routeType.value == "2") {
  638. uni.navigateTo({
  639. url: `/subpackage/carPark/recharge/recharge-weixin?connectSuccess=${state.connectSuccess}`,
  640. });
  641. } else if (routeType.value == "3") {
  642. uni.navigateTo({
  643. url: "/subpackage/after-sale/pin-code-deblocking/pin-code-confirm?state=true&vehicleId=" + state.vehicleId,
  644. });
  645. } else if (routeType.value == "4") {
  646. uni.navigateTo({
  647. url: `/subpackage/after-sale/deviceInfo/deviceInfo?backIndex=${state.backIndex}`,
  648. });
  649. } else if (routeType.value == "5") {
  650. // #ifdef MP-ALIPAY
  651. uni.navigateTo({
  652. url: "/subpackage/after-sale/activation-once-again/activation-once-again-ali?state=true&id=" + state.id,
  653. });
  654. // #endif
  655. // #ifdef MP-WEIXIN
  656. if (state.difference == "1") {
  657. uni.navigateTo({
  658. url: `/subpackage/after-sale/activation-once-again/activation-once-again?status=true&state=true&vehicleId=${state.vehicleId}&vehPosImgUrl=${state.vehPosImgUrl}&vehNegImgUrl=${state.vehNegImgUrl}`,
  659. });
  660. } else if (state.difference == "2") {
  661. uni.navigateTo({
  662. url: `/subpackage/after-sale/refund-order-balance/refund-order-balance?status=true&state=true&vehicleId=${state.vehicleId}&&id=${state.id}&&refundBalance=${state.refundBalance}`,
  663. });
  664. } else {
  665. uni.$emit('bluetoothLink', { status: true })
  666. uni.navigateBack({
  667. delta: 1
  668. })
  669. }
  670. // #endif
  671. } else if (routeType.value == "6") {
  672. uni.navigateTo({
  673. url: "/subpackage/after-sale/activation-once-again/activation-once-again?state=true&id=" + state.id
  674. });
  675. } else if (routeType.value == "7") {
  676. uni.navigateTo({
  677. url: `/subpackage/personal-center/trapping-and-repairing/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}`,
  678. });
  679. } else if (routeType.value == "8") {
  680. uni.navigateTo({
  681. url: `/subpackage/after-sale/account-recharge/recharge-weixin?accountId=${state.accountId}`,
  682. });
  683. } else if (routeType.value == "9") {
  684. uni.navigateTo({
  685. url: `/subpackage/personal-center/trapping-and-repairing-account/recharge-two?rechargeMoney=${state.rechargeMoney}&&orderNum=${state.orderNum}&&payMoney=${state.payMoney}&&accountId=${state.accountId}`,
  686. });
  687. } else if (routeType.value == "10") {
  688. uni.navigateTo({
  689. url: `/subpackage/personal-center/car-message-change?vehicleId=${state.vehicleId}`,
  690. });
  691. } else {
  692. return;
  693. }
  694. }
  695. /**
  696. * 前装设备
  697. */
  698. const preDevice = (res) => {
  699. console.log("连接成功1111=====", res);
  700. if (res.code == 0 || res.serviceCode==0) {
  701. console.log("连接成功=====");
  702. datas.setData("bluLinkStatus", true);
  703. datas.setData("connectPrefixName", connectPrefixName.value);
  704. getCardId((cardNo) => {
  705. console.log("cardNo",cardNo);
  706. if(cardNo.includes('5201')){
  707. // 正常激活 前装 5201
  708. oks()
  709. }else{
  710. // 前装9901
  711. etcOks()
  712. }
  713. })
  714. } else {
  715. alertF(res.msg);
  716. console.log(res.msg);
  717. }
  718. };
  719. function getCardId(fun){
  720. //执行0015文件
  721. tools.showLoadingAlert("执行指令");
  722. let cmdArr = [cmd.HOME_DIRECTORY, cmd.APPLICATION_DIRECTORY, cmd.CMD_READBINARY];
  723. console.log(cmdArr);
  724. console.log(bluetoothUtil);
  725. bluetoothUtil.transCmd(cmdArr, '10', function(res) { //10:写卡 20:写OBU
  726. console.log("res====", res)
  727. var cardStr = res[2];
  728. if (cardStr == undefined || cardStr == "undefined" || cardStr == "") {
  729. tools.alertF("卡指令不符" + cardStr);
  730. return;
  731. }
  732. if (cardStr.length < 40) {
  733. tools.alertF("卡指令长度不符" + cardStr);
  734. return;
  735. }
  736. tools.hideLoadingAlert();
  737. fun(cardStr.substring(20, 40));
  738. })
  739. }
  740. function etcOks() {
  741. if (routeType.value == "4") {
  742. uni.navigateTo({
  743. url: "/subpackage/carPark/etc/etcDeviceInfo",
  744. });
  745. }
  746. }
  747. /**
  748. * 监听蓝牙状态
  749. */
  750. const listenStatus = (res) => {
  751. console.log("时时监听蓝牙状态func2", connectPrefixName.value, res.code);
  752. console.log(res);
  753. if (res.code == 0) {
  754. datas.setData("bluLinkStatus", true);
  755. datas.setData("connectPrefixName", connectPrefixName.value);
  756. // oks();
  757. } else {
  758. //断开蓝牙
  759. bluetoothUtil.disconnectDevice();
  760. datas.setData("bluLinkStatus", false);
  761. datas.setData("connectPrefixName", "");
  762. tools.showToastAlert("蓝牙已断开");
  763. // #ifdef MP-ALIPAY
  764. my.closeBluetoothAdapter({
  765. success(res) {
  766. // 关闭蓝牙适配器成功
  767. },
  768. fail(err) {
  769. // 处理关闭蓝牙适配器失败的情况
  770. }
  771. })
  772. // #endif
  773. }
  774. };
  775. /**
  776. * 提示加关蓝牙
  777. */
  778. const alertF = (msg : string) => {
  779. //隐藏加载框
  780. tools.hideLoadingAlert();
  781. //断开蓝牙
  782. bluetoothUtil.disconnectDevice();
  783. //提示对话框
  784. tools.showModalAlert(msg);
  785. };
  786. </script>
  787. <style>
  788. page {
  789. background-color: #f3f3f3;
  790. }
  791. :deep(.u-mode-center-box) {
  792. border-radius: 20rpx;
  793. }
  794. </style>
  795. <style lang="scss" scoped>
  796. .devices {
  797. min-height: 100vh;
  798. box-sizing: border-box;
  799. padding-bottom: 160rpx;
  800. position: relative;
  801. padding-top: 30rpx;
  802. background: #E9EDF0;
  803. .action {
  804. position: absolute;
  805. bottom: 0rpx;
  806. left: 0;
  807. height: 128rpx;
  808. background-color: #fff;
  809. border-radius: 30rpx 30rpx 0 0;
  810. width: 100vw;
  811. display: flex;
  812. align-items: center;
  813. justify-content: center;
  814. flex-direction: column;
  815. }
  816. .device {
  817. margin: 0 auto;
  818. width: 701rpx;
  819. display: flex;
  820. flex-direction: row;
  821. align-items: center;
  822. background: white;
  823. padding: 25rpx 20rpx;
  824. box-sizing: border-box;
  825. background: #FFFFFF;
  826. box-shadow: 2rpx 6rpx 6rpx 6rpx #DFDFDF;
  827. border-radius: 12rpx;
  828. .head {
  829. width: 120rpx;
  830. height: 120rpx;
  831. border-radius: 10rpx;
  832. background-color: #f3f3f3;
  833. }
  834. .center {
  835. flex: 1;
  836. margin-left: 30rpx;
  837. margin-right: 30rpx;
  838. .name {
  839. font-size: 30rpx;
  840. color: #333333;
  841. }
  842. .desc {
  843. font-size: 26rpx;
  844. color: #666666;
  845. margin-top: 25rpx;
  846. }
  847. }
  848. .icon {
  849. width: 38rpx;
  850. height: 38rpx;
  851. margin-right: 12rpx;
  852. }
  853. }
  854. .hint {
  855. margin: 60rpx 30rpx 0px;
  856. .txt {
  857. font-family: MicrosoftYaHei;
  858. font-size: 28rpx;
  859. color: #111111;
  860. line-height: 40rpx;
  861. display: flex;
  862. align-items: center;
  863. .imgs {
  864. width: 30rpx;
  865. height: 30rpx;
  866. margin-right: 10rpx;
  867. }
  868. }
  869. .grey-txt {
  870. font-size: 28rpx;
  871. color: #999;
  872. line-height: 40rpx;
  873. margin-top: 16rpx;
  874. }
  875. }
  876. .btn {
  877. margin: 70rpx 40rpx;
  878. }
  879. }
  880. </style>