您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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