store.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import config from 'common/config.js'
  4. import reqUtil from 'util/util-js/requstUtil.js'
  5. import date from 'util/util-js/date.js'
  6. import cNumber from 'util/util-js/makeNumber.js'
  7. import BLE from 'util/util-js/BLE.js';
  8. //快速打击部分
  9. import o0 from "@/util/util-js/o0.js"
  10. import o0Project from "@/util/util-js/o0Project.js"
  11. import o0ProjectRelease from "@/util/util-js/o0ProjectRelease0.1.js"
  12. import deviceData from "@/util/util-js/devices.js"
  13. Vue.use(Vuex)
  14. const store = new Vuex.Store({
  15. state: {
  16. // vLog:'',
  17. //引导层
  18. bGuidePages: false,
  19. //是否显示Canvas
  20. bCanvasShow: true,
  21. /**
  22. * 是否需要强制登录
  23. */
  24. forcedLogin: false,
  25. /**
  26. * 蓝牙实时发送数据的页面的名称
  27. */
  28. currentPageName: '',
  29. hasLogin: false,
  30. userInfo: null,
  31. userName: "匿名",
  32. days: 0,
  33. remainingDays: 0,
  34. signature: '',
  35. avatarUrl: "/static/defaultAvatar.png",
  36. /**
  37. * 新手教程相关
  38. */
  39. // 是否是新用户,
  40. //TODO:登录接口返回的数据来判断
  41. bNewUser: false,
  42. //是否是第一次走新手
  43. bNewGuide: false,
  44. //解锁状态,和首次安装app相关
  45. //注意添加新字段时候。需要到 platform-page/guide.vue 确认需不需要添加新的reset
  46. guideUnlockState: {
  47. firstInstallation: true, //是否首次安装
  48. firstDisconnectBluetooth: true, //是否首次连接蓝牙
  49. firstUnlockJumpUp: true, //是否首次向上跳
  50. firstUnlockLeftAndRightJump: true, //是否首次左右跳
  51. firstUnlockLeftAndRightRotationJump: true,
  52. firstPromptSelectLevel: true //是否首次提示选择关卡
  53. },
  54. token: '',
  55. gender: 0,
  56. //省市区数据
  57. city: {
  58. label: '北京市-北京市-东城区',
  59. cityCode: "110101",
  60. //picker 选择器的index数组
  61. value: [0, 0, 0]
  62. },
  63. birthday: date.formatTime(new Date()),
  64. //默认值
  65. height: 0,
  66. weight: 0,
  67. //最近在玩的列表
  68. playGames: [],
  69. //最近在玩的排行游戏列表
  70. playRankingGames: [],
  71. //全部的游戏列表
  72. allGames: [],
  73. //关注的游戏列表
  74. favoriteGames: [],
  75. // 排行榜里面显示的游戏
  76. rankSelectedGame: null,
  77. rankInfo: null,
  78. cityName: "某市",
  79. /**
  80. * 默认的运动数据
  81. * date.addDaysFromNewDate(new Date(),1)
  82. */
  83. defaultPlanData: {
  84. startTime: date.formatDate(new Date()),
  85. endTime: date.addDaysFromNewDate(new Date(), 6),
  86. targetWeight: 0, //目标公斤
  87. calorie: 360, //运动消耗的卡路里,默认300 大卡
  88. cumulativeCalorie: 0, //累计增重
  89. sportTime: 40, //运动时间
  90. /**
  91. * 本地记录的消耗卡路里数量
  92. */
  93. localCalorie: 0,
  94. /**
  95. * 显示卡路里,过了12点清空
  96. */
  97. showCalorie: 0,
  98. /**
  99. * 总和
  100. */
  101. allCalorie: 0
  102. },
  103. /**
  104. * 计划的运动数据
  105. */
  106. planData: {
  107. startTime: date.formatDate(new Date()),
  108. endTime: date.formatDate(new Date()), //date.addDaysFromNewDate(new Date(),1),
  109. targetWeight: 0, //目标公斤
  110. cumulativeCalorie: 0, //累计增重
  111. calorie: 300, //运动消耗的卡路里
  112. sportTime: 40, //运动时间
  113. /**
  114. * 本地记录的消耗卡路里数量
  115. */
  116. localCalorie: 0,
  117. /**
  118. * 显示卡路里,过了12点清空
  119. */
  120. showCalorie: 0,
  121. /**
  122. * 总和
  123. */
  124. allCalorie: 0
  125. },
  126. //记录表盘计划刷新的卡路里
  127. oldArcbarProCalorie: 0,
  128. //记录表盘当前的总卡路里
  129. oldArcbarAllCalorie: 0,
  130. //当前运动的世时间
  131. localSportTime: 0,
  132. //当前运动时间,运动时候记录的时间
  133. runingTime: 0,
  134. //蓝牙设备信息列表
  135. //id 不可变,用于保存到本地区分
  136. BLEInfoList: deviceData.getDeviceList(),
  137. //记录的蓝牙设备,保存id, 和对应的蓝牙连接数据
  138. BLEDeviceList: [],
  139. //显示的蓝牙设备,取本地数据时候更新
  140. BLEDeviceShowList: [],
  141. //选择连接的蓝牙设备
  142. BLEConnectDevice: null,
  143. //获取到的服务
  144. BLEGetServices: null,
  145. //当前发送给蓝牙的指令,目前是只有蓝牙手柄
  146. currentInstruction: '',
  147. instructionState: {
  148. // bAcc: false, //是否开启加速计状态
  149. // bGyroscope: false, //是否开启陀螺仪状态
  150. bOpen: false, //是否开启指令
  151. bSteps: false, //是否开启步数
  152. },
  153. //绑定的设备
  154. DeviceBindingList: [{
  155. id: 0,
  156. cname: "开启手机数据",
  157. ename: "bindMobilePhoneBandage",
  158. icon: "/static/devicesIcon/bandage.png",
  159. mIcon: "/static/devicesIcon/bandage.png",
  160. bRatio: false,
  161. usageMode: 'bindPhone',
  162. describe: '手机情景下使用',
  163. limitType: 'rebound', //限制回弹版本
  164. deviceType: 'mySelf', //指的是使用手机本身加速计计算
  165. deviceName: 'PHONE', //连接硬件名称
  166. }],
  167. ConnectBindingDevice: null,
  168. cIndex: -1,
  169. //当前是否连接
  170. bConnection: false,
  171. /**
  172. * 通过验证的连接,比如通过mac验证,或者说是首页直连,都设置这个参数,确保已经连上
  173. */
  174. bVerifiedConnection: false,
  175. /**
  176. * 默认不是旧设备,旧设备使用的轴向不一样,名字为 BGBox_202012 ,新设备为 BGBox_202112
  177. */
  178. bOldDeviceType: false,
  179. /**
  180. * Android 出现不匹配的情况下,判断
  181. * ios 暂时没有此类问题
  182. */
  183. bPhoneMatched: false,
  184. //最近连接过的设备
  185. finallyUseDevice: null,
  186. /**
  187. * 用户选择好友的信息
  188. */
  189. finallySelectFriendInfo: null,
  190. //phoneNumber
  191. phoneNumber: '',
  192. mailboxNumber: '',
  193. //是否是第一次设置密码,根据这个值判断.默认未设置,即设置true
  194. setPasswordFirstTime: true,
  195. openid: '',
  196. appleid: '',
  197. //获取验证码
  198. bCodeDisabled: false,
  199. count: 59,
  200. interval: null,
  201. //conversion列表
  202. oldSwiperList: [],
  203. // 计划任务过期
  204. bPlanExpired: false,
  205. // 制定玩计划任务后
  206. bPlanFinish: false,
  207. //标准体重,男女根据当前年龄计算
  208. standardWeight: 0,
  209. //是否安装了微信
  210. bInstallWechat: false,
  211. bHideWeixin: false,
  212. //导航栏高度。这里统一参数,单位px
  213. navHeight: 46,
  214. tabbarHeight: 65,
  215. systemInfo: null, //系统全部信息
  216. clientName: '', //但是客户端名字
  217. system: '', // 系统版本
  218. platform: '', // 平台
  219. appName: '',
  220. version: '1.6.3', //软件版本
  221. versionCode: '21120701', //app.vue 自动获取.目前是h5 设置给了一个默认值
  222. showEndTime: config.endTime, //游戏显示时间字段,后台返回对应此时间之前的数据
  223. //现在游戏显示在对应的平台
  224. gamePlatform: {
  225. 0: 'android',
  226. 1: 'ios',
  227. 2: 'all'
  228. },
  229. globalAcc: null,
  230. globalOri: null,
  231. globalAccData: {
  232. ax: 0,
  233. ay: 0,
  234. az: 0
  235. },
  236. globalGyroData: {
  237. gx: 0,
  238. gy: 0,
  239. gz: 0
  240. },
  241. globalLastGyroData: {
  242. gx: 0,
  243. gy: 0,
  244. gz: 0
  245. },
  246. globalMyAttitude: null,
  247. /**
  248. * 当前显示的模式下标,区分总体的显示模块
  249. * 比如拳击模块体验下,设置 0
  250. * 跳绳为主的模式体验下,设置 1
  251. */
  252. currentModeIndex: 0,
  253. //蓝牙变量操作
  254. /**
  255. * 操作蓝牙设备
  256. */
  257. bOpenBluetooth: false,
  258. /**
  259. * 是否初始化蓝牙适配器
  260. */
  261. bOpenSuccess: false,
  262. /**
  263. * 是否监听蓝牙状态变化
  264. */
  265. bListenAdapterStateChange: false,
  266. /**
  267. * 是否监听寻找新设备事件
  268. */
  269. bListenDeviceFound: false,
  270. // 设备Id
  271. BLEDeviceId: "",
  272. // 服务Id
  273. BLEServiceId: "",
  274. // 特征值id
  275. BLENotifyCharacteristicId: "",
  276. //监听rssi对象
  277. BLERSSIInterval: null,
  278. //蓝牙服务timeout
  279. getBLEDeviceServicesTimeout: null,
  280. //本地游戏地址
  281. // http://192.168.0.112:7456/build/index.html
  282. // http://127.0.0.1:7456/build/index.html
  283. LocationGameUrl: "", //192.168.1.12:7456
  284. //快速打击对象
  285. filter: null,
  286. deviceMs: 1,
  287. //改进版的沙袋打击对象
  288. sandbagAlgorithm: null,
  289. sandbagAlgorithmLastTime: new Date().getTime(),
  290. /**
  291. * 蓝牙参数对象
  292. */
  293. // 设备Id
  294. deviceId: "",
  295. // 服务Id
  296. serviceId: "",
  297. notifyCharacteristicId: "",
  298. writeCharacteristicId: "",
  299. showToast: false,
  300. bListenerUpdate: false,
  301. bListenerJson: false,
  302. bListenerMac: false,
  303. bListenerAccArray: false,
  304. /**
  305. * OTA config
  306. */
  307. UUID_OTA_SERVICE: "f000ffc0-0451-4000-b000-000000000000", //OTA 服务对应的服务的 UUID
  308. UUID_IDENTFY: "f000ffc1-0451-4000-b000-000000000000", //OTA 版本特征值的UUID,读取版本就是写向这个特征值写入:0x00
  309. UUID_BLOCK: "f000ffc2-0451-4000-b000-000000000000", //OTA 写bin文件特征值UUID,发送bin文件就是写这个特征值
  310. /*****/
  311. /**
  312. * 发送16进制时候,返回的刷新数据
  313. */
  314. bListenerHexUpdate: false,
  315. BluetoothAdapter: null,
  316. //版本状态,用于区分部分特定的环境
  317. versionCodeState: {
  318. showGame: false,
  319. showVideo: false,
  320. versionCode: 0,
  321. title: 'none'
  322. },
  323. //显示蓝牙是否断开连接Modal
  324. bShowBLEConnectModal: false,
  325. bGamePlaying: false,
  326. //跳绳条件下计数
  327. bRopeKeyOne: 0,
  328. bRopeKeyTwo: 0,
  329. //钻石,金币
  330. cDiamond: 0,
  331. cGold: 0,
  332. /**
  333. * 任务相关
  334. */
  335. currentJumpTask: null,
  336. multiPersonList: [],
  337. singlePersonList: [],
  338. levels: [],
  339. /**
  340. * 校准识别部分
  341. */
  342. convertAcc: [{
  343. type: 'x',
  344. match: 'ax', //默认匹配一一对应
  345. direction: 1,
  346. }, {
  347. type: 'y',
  348. match: 'ay',
  349. direction: -1,
  350. }, {
  351. type: 'z',
  352. match: 'az',
  353. direction: -1,
  354. }],
  355. convertGyro: [{
  356. type: 'x',
  357. match: 'gx', //默认匹配一一对应
  358. direction: 1,
  359. }, {
  360. type: 'y',
  361. match: 'gy',
  362. direction: 1,
  363. }, {
  364. type: 'z',
  365. match: 'gz',
  366. direction: 1,
  367. }],
  368. /**
  369. * 签到列表
  370. */
  371. signInList: [],
  372. isSignIn: false,
  373. },
  374. mutations: {
  375. onSetLocationGameUrl(state, value) {
  376. uni.setStorageSync('LocationGameUrl', value);
  377. state.LocationGameUrl = value;
  378. },
  379. //获取本地任务对象
  380. onGetLocationGameUrl(state) {
  381. //如果存在本地任务
  382. const value = uni.getStorageSync('LocationGameUrl');
  383. if (value) {
  384. state.LocationGameUrl = value;
  385. }
  386. return value;
  387. console.log('onGetLocationGameUrl ' + value);
  388. },
  389. /**
  390. * 蓝牙解析后的数据,转化成对应的坐标系方向
  391. * @param {Object} context
  392. */
  393. onConvertDeviceData(state, context) {
  394. let {
  395. data,
  396. callback = null
  397. } = context;
  398. let {
  399. acc,
  400. gyro,
  401. } = data;
  402. //根据已校准的数据转化对应的轴
  403. let outAcc = {
  404. ax: acc[state.convertAcc[0].match] * state.convertAcc[0].direction,
  405. ay: acc[state.convertAcc[1].match] * state.convertAcc[1].direction,
  406. az: acc[state.convertAcc[2].match] * state.convertAcc[2].direction
  407. };
  408. let outGyro = {
  409. gx: gyro[state.convertGyro[0].match] * state.convertGyro[0].direction,
  410. gy: gyro[state.convertGyro[1].match] * state.convertGyro[1].direction,
  411. gz: gyro[state.convertGyro[2].match] * state.convertGyro[2].direction
  412. }
  413. if (callback)
  414. callback({
  415. convertAcc: outAcc,
  416. convertGyro: outGyro
  417. });
  418. },
  419. onAccAndGyroConvertDataGet(state) {
  420. const convertAcc = uni.getStorageSync('convertAcc');
  421. if (convertAcc) {
  422. state.convertAcc = convertAcc;
  423. }
  424. const convertGyro = uni.getStorageSync('convertGyro');
  425. if (convertGyro) {
  426. state.convertGyro = convertGyro;
  427. }
  428. },
  429. onAccAndGyroConvertDataSave(state) {
  430. uni.setStorageSync('convertAcc', state.convertAcc);
  431. uni.setStorageSync('convertGyro', state.convertGyro);
  432. },
  433. onAccAndGyroConvertDataReset(state) {
  434. state.convertAcc = [{
  435. type: 'x',
  436. match: 'ax', //默认匹配一一对应
  437. direction: 1,
  438. }, {
  439. type: 'y',
  440. match: 'ay',
  441. direction: -1,
  442. }, {
  443. type: 'z',
  444. match: 'az',
  445. direction: -1,
  446. }];
  447. state.convertGyro = [{
  448. type: 'x',
  449. match: 'gx', //默认匹配一一对应
  450. direction: 1,
  451. }, {
  452. type: 'y',
  453. match: 'gy',
  454. direction: 1,
  455. }, {
  456. type: 'z',
  457. match: 'gz',
  458. direction: 1,
  459. }];
  460. //重置一下数据保存
  461. this.commit('onAccAndGyroConvertDataSave');
  462. },
  463. setGuideUnlockState(state, _guideUnlockState) {
  464. uni.setStorageSync('guideUnlockState', _guideUnlockState);
  465. state.guideUnlockState = _guideUnlockState;
  466. },
  467. getGuideUnlockState(state, _guideUnlockState) {
  468. //如果存在本地任务
  469. const value = uni.getStorageSync('guideUnlockState');
  470. if (value) {
  471. state.guideUnlockState = value;
  472. }
  473. console.log('获取guideUnlockState', state.guideUnlockState)
  474. },
  475. /**
  476. * 设置当前操作的任务记录到本地
  477. * @param {Object} state
  478. * @param {Object} _taskObj
  479. */
  480. setActionJumpTask(state, _taskObj) {
  481. uni.setStorageSync('currentJumpTask', _taskObj);
  482. state.currentJumpTask = _taskObj;
  483. },
  484. //获取本地任务对象
  485. getActionJumpTask(state) {
  486. //如果存在本地任务
  487. const value = uni.getStorageSync('currentJumpTask');
  488. if (value) {
  489. state.currentJumpTask = value;
  490. }
  491. },
  492. resetActionJumpTask(state) {
  493. state.currentJumpTask = null;
  494. uni.setStorageSync('currentJumpTask', state.currentJumpTask);
  495. },
  496. setFinallSelectFriendInfo(state, friendInfo) {
  497. state.finallySelectFriendInfo = friendInfo;
  498. console.log('finallySelectFriendInfo', JSON.stringify(friendInfo));
  499. },
  500. clearFinallFriendInfo(state) {
  501. state.finallySelectFriendInfo = null;
  502. },
  503. /**
  504. * 获取记录的最后一次连接设备
  505. * @param {Object} state
  506. */
  507. getFinalUseDevice(state) {
  508. // 获取本地存储的最后一次使用的设备
  509. //1.获取最近连接的蓝牙设备, 指蓝牙搜索到的obj
  510. const value = uni.getStorageSync('finallyUseDevice');
  511. if (value) {
  512. state.finallyUseDevice = value;
  513. }
  514. console.log('获取的finallyUseDevice', value);
  515. },
  516. /**
  517. * 存储最后一次使用的设备信息,后面登陆时候,如果存在设备最后一次使用信息,则自动连接
  518. * @param {Object} state
  519. * @param {Object} device
  520. */
  521. setFinallUseDevice(state, device) {
  522. uni.setStorageSync('finallyUseDevice', device);
  523. state.finallyUseDevice = device;
  524. // console.log("保存finallyUseDevice:", state.finallyUseDevice);
  525. // uni.setStorage({
  526. // key: 'finallyUseDevice',
  527. // data: device,
  528. // success: (res) => {
  529. // state.finallyUseDevice = device;
  530. // console.log("保存finallyUseDevice:", res);
  531. // }
  532. // })
  533. },
  534. //获取记录的蓝牙列表数据
  535. getBLEDeviceList(state) {
  536. // console.log("getBLEDeviceList=");
  537. uni.getStorage({
  538. key: 'BLEDeviceList',
  539. success: (res) => {
  540. // console.log("*****getBLEDeviceList=", res);
  541. let _list = res.data;
  542. state.BLEDeviceList = res.data;
  543. //更新BLEDeviceShowList 数组
  544. state.BLEDeviceShowList = [];
  545. _list.forEach(item => {
  546. //如果记录到本地的id,和信息列表中的id一致,则结合
  547. for (let i = 0; i < state.BLEInfoList.length; i++) {
  548. let eq = state.BLEInfoList[i];
  549. if (item.id == eq.id) {
  550. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  551. break;
  552. }
  553. }
  554. })
  555. }
  556. })
  557. },
  558. //添加蓝牙设备数据
  559. addBLEDevice(state, data) {
  560. let devicelist = [];
  561. if (state.BLEDeviceList && state.BLEDeviceList.length != 0) {
  562. devicelist = state.BLEDeviceList;
  563. }
  564. // console.log(data, devicelist)
  565. let bHas = false;
  566. devicelist.forEach((item, index, selfArr) => {
  567. if (item.id == data.id) {
  568. //如果存在,更新保存的数据,比如 mac或者uuid等
  569. selfArr[index] = item = Object.assign({}, item, data);
  570. bHas = true;
  571. }
  572. })
  573. //把当前添加的的蓝牙设信息备作为最后一次连接覆盖到本地
  574. this.commit('setFinallUseDevice', data);
  575. if (!bHas) {
  576. //如果不是更新数据,就添加但却数据到列表
  577. devicelist.push(data);
  578. }
  579. uni.setStorage({
  580. key: 'BLEDeviceList',
  581. data: devicelist,
  582. success: (res) => {
  583. // uni.showToast({
  584. // title: "保存成功"
  585. // })
  586. state.BLEDeviceList = devicelist;
  587. // console.log("devicelist:",devicelist);
  588. //更新BLEDeviceShowList 数组
  589. state.BLEDeviceShowList = [];
  590. devicelist.forEach(item => {
  591. //如果记录到本地的id,和信息列表中的id一致,则结合
  592. for (let i = 0; i < state.BLEInfoList.length; i++) {
  593. let eq = state.BLEInfoList[i];
  594. if (item.id == eq.id) {
  595. // console.log("存储的======================:", item, eq);
  596. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  597. break;
  598. }
  599. }
  600. })
  601. // console.log("state.BLEDeviceShowList:",state.BLEDeviceShowList);
  602. }
  603. })
  604. },
  605. //删除蓝牙设备数据
  606. deleteBLEDevice(state, index) {
  607. let devicelist = [];
  608. devicelist = state.BLEDeviceList;
  609. devicelist.splice(index, 1);
  610. uni.setStorage({
  611. key: 'BLEDeviceList',
  612. data: devicelist,
  613. success: (res) => {
  614. uni.showToast({
  615. title: "删除成功"
  616. })
  617. state.BLEDeviceList = devicelist;
  618. //更新BLEDeviceShowList 数组
  619. state.BLEDeviceShowList = [];
  620. devicelist.forEach(item => {
  621. //如果记录到本地的id,和信息列表中的id一致,则结合
  622. for (let i = 0; i < state.BLEInfoList.length; i++) {
  623. let eq = state.BLEInfoList[i];
  624. if (item.id == eq.id) {
  625. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  626. break;
  627. }
  628. }
  629. })
  630. }
  631. })
  632. },
  633. initAdapter(state, callback) {
  634. //初始化蓝牙模块
  635. let params = {
  636. success: (res) => {
  637. state.bOpenSuccess = true;
  638. state.bOpenBluetooth = true;
  639. if (callback)
  640. callback(res);
  641. //监听断开事件
  642. this.commit("B_OnBLEConnectionStateChange");
  643. },
  644. fail: (fail) => {
  645. state.bOpenSuccess = false;
  646. state.bOpenBluetooth = false;
  647. uni.showToast({
  648. title: '蓝牙尚未开启!',
  649. icon: 'none'
  650. })
  651. },
  652. complete: (complete) => {
  653. // console.log("complete bListenAdapterStateChange:", state.bListenAdapterStateChange);
  654. if (state.bListenAdapterStateChange) return;
  655. state.bListenAdapterStateChange = true;
  656. uni.onBluetoothAdapterStateChange((res) => {
  657. // console.log('adapterState changed, now is', res)
  658. // 手机蓝牙状态
  659. state.bOpenBluetooth = res.available;
  660. if (state.bOpenBluetooth && !state.bOpenSuccess) {
  661. this.commit('initAdapter');
  662. }
  663. })
  664. }
  665. };
  666. this.commit("B_OpenBluetoothAdapter", params);
  667. },
  668. // todo 未使用到
  669. onGetDevices(state, context) {
  670. let {
  671. success
  672. } = context;
  673. if (!state.BLEConnectDevice) return;
  674. // #ifdef APP-PLUS
  675. let deviceId = state.BLEConnectDevice.deviceId;
  676. uni.getBLEDeviceRSSI({
  677. deviceId,
  678. success: res => {
  679. let _dis = Math.pow(Math.E, (Math.abs(res.RSSI) - 66.78) / 16.56);
  680. if (_dis > state.BLEConnectDevice.limitDis) {
  681. if (state.cIndex != -1) {
  682. uni.showToast({
  683. title: '设备断开连接!',
  684. icon: 'none',
  685. duration: 2000,
  686. mask: true
  687. })
  688. }
  689. setTimeout(() => {
  690. this.commit("B_CloseBLEConnection", {
  691. deviceId: deviceId
  692. })
  693. state.cIndex = -1;
  694. state.bConnection = false;
  695. state.bVerifiedConnection = false;
  696. }, 1000)
  697. } else {
  698. // console.log("DIS~~~~~~~~~", _dis);
  699. if (success) {
  700. success({
  701. RSSI: res.RSSI,
  702. DIS: _dis
  703. });
  704. }
  705. }
  706. }
  707. })
  708. // #endif
  709. },
  710. //清除连接的开启的timeout
  711. onUnloadCreateBLEConnectionTimeout(state) {
  712. if (state.getBLEDeviceServicesTimeout) {
  713. clearTimeout(state.getBLEDeviceServicesTimeout);
  714. state.getBLEDeviceServicesTimeout = null;
  715. }
  716. },
  717. initBLEData(state) {
  718. // 设备Id
  719. state.deviceId = "";
  720. // 服务Id
  721. state.serviceId = "";
  722. state.notifyCharacteristicId = "";
  723. state.writeCharacteristicId = "";
  724. state.currentInstruction = "";
  725. state.showToast = false;
  726. state.bListenerUpdate = false;
  727. state.bListenerJson = false;
  728. state.bListenerMac = false;
  729. state.bListenerAccArray = false;
  730. //更新二进制的
  731. state.bListenerHexUpdate = false;
  732. },
  733. //连接蓝牙
  734. onCreateBLEConnection(state, context) {
  735. let {
  736. index,
  737. item,
  738. initItem = false,
  739. getSuccess = null,
  740. getinitAdapter = null
  741. } = context;
  742. uni.showToast({
  743. title: '连接设备中...',
  744. icon: 'loading',
  745. duration: 10000,
  746. mask: true
  747. })
  748. let params = {
  749. item: item,
  750. success: (success) => {
  751. state.bConnection = true;
  752. if (state.getBLEDeviceServicesTimeout) {
  753. clearTimeout(state.getBLEDeviceServicesTimeout);
  754. state.getBLEDeviceServicesTimeout = null;
  755. }
  756. state.getBLEDeviceServicesTimeout = setTimeout(() => {
  757. let retryCount = 5;
  758. this.commit("B_GetBLEDeviceServices", {
  759. retryCount: retryCount,
  760. item: item,
  761. callback: () => {
  762. uni.showToast({
  763. title: '连接成功',
  764. icon: 'loading',
  765. duration: 2000,
  766. mask: true
  767. })
  768. //是否需要设置item,默认不设置
  769. if (initItem) {
  770. state.cIndex = index;
  771. state.BLEConnectDevice = item;
  772. }
  773. if (getSuccess)
  774. getSuccess();
  775. /**
  776. * 直接连接过成功
  777. */
  778. state.bVerifiedConnection = true;
  779. },
  780. getServiceList: (serviceList) => {
  781. //搜索服务失败后
  782. state.BLEGetServices = serviceList;
  783. },
  784. getFail: () => {
  785. this.commit("B_CloseBLEConnection", {
  786. deviceId: item.deviceId
  787. })
  788. // state.cIndex = -1;
  789. // state.bConnection = false;
  790. // state.bVerifiedConnection = false;
  791. this.commit("onResetBLEConnection");
  792. }
  793. });
  794. }, 2000);
  795. },
  796. fail: (fail) => {
  797. console.log("***fail:", fail);
  798. if (fail.errCode === 10012) {
  799. console.log("连接超时,请重试!");
  800. uni.showToast({
  801. title: '连接失败,开启设备后尝试重新连接!',
  802. icon: 'none',
  803. duration: 3000,
  804. mask: true
  805. })
  806. } else if (fail.errCode === 10013) {
  807. console.log("连接失败,蓝牙地址无效!");
  808. uni.showToast({
  809. title: '连接失败,蓝牙地址无效',
  810. icon: 'none',
  811. duration: 2000,
  812. mask: true
  813. })
  814. } else if (fail.errCode === 10000) {
  815. this.commit('initAdapter', () => {
  816. if (getinitAdapter) {
  817. getinitAdapter();
  818. }
  819. })
  820. } else {
  821. // err.errCode10003原因多种:蓝牙设备未开启或异常导致无法连接;蓝牙设备被占用或者上次蓝牙连接未断开导致无法连接
  822. console.log("连接失败,请重试!", state.BLEConnectDevice);
  823. uni.showToast({
  824. title: '请尝试开启设备和重启app。',
  825. icon: 'none',
  826. duration: 2000,
  827. mask: true
  828. })
  829. }
  830. }
  831. };
  832. this.commit("B_CreateBLEConnection", params);
  833. },
  834. //devices hardware 连接后验证,这里不需要处理 bVerifiedConnection,通过mac 验证后处理
  835. onCreateBLESuccess(state, context) {
  836. let {
  837. item,
  838. getSuccess = null
  839. } = context;
  840. this.commit("B_CreateBLEConnection", {
  841. item: item,
  842. success: success => {
  843. state.BLEConnectDevice = item;
  844. state.bConnection = true;
  845. if (getSuccess) {
  846. getSuccess();
  847. }
  848. },
  849. fail: fail => {
  850. if (fail.errCode === 10012) {
  851. console.log("连接超时,请重试!");
  852. uni.showToast({
  853. title: '连接超时,检查对应设备是否开启?',
  854. icon: 'none',
  855. duration: 2000,
  856. mask: true
  857. })
  858. } else if (fail.errCode === 10013) {
  859. console.log("连接失败,蓝牙地址无效!");
  860. uni.showToast({
  861. title: '蓝牙地址无效,检查设备是否正常?',
  862. icon: 'none',
  863. duration: 2000,
  864. mask: true
  865. })
  866. } else if (fail.errCode === 10000) {
  867. console.log("连接失败,初始化 wx.openBluetoothAdapter 调用之后使用");
  868. uni.showToast({
  869. title: '连接失败,检查手机蓝牙是否开启?',
  870. icon: 'none',
  871. duration: 2000,
  872. mask: true
  873. })
  874. } else {
  875. console.log("连接失败,请重试!");
  876. uni.showModal({
  877. title: '连接失败',
  878. content: '设备未开启或被占用。请重启app和设备后重新连接。'
  879. })
  880. // uni.showToast({
  881. // title: '设备未开启或被占用异常导致无法连接。',
  882. // icon: 'none',
  883. // duration: 2000,
  884. // mask: true
  885. // })
  886. }
  887. }
  888. });
  889. },
  890. //获取蓝牙服务
  891. onGetBLEDeviceServices(state, context) {
  892. let {
  893. item,
  894. success = null,
  895. } = context;
  896. let retryCount = 5;
  897. this.commit("B_GetBLEDeviceServices", {
  898. retryCount: retryCount,
  899. item: item,
  900. callback: success,
  901. getServiceList: (serviceList) => {
  902. state.BLEGetServices = serviceList;
  903. },
  904. getFail: () => {
  905. this.commit("B_CloseBLEConnection", {
  906. deviceId: item.deviceId
  907. })
  908. this.commit("onResetBLEConnection");
  909. }
  910. })
  911. },
  912. //重置蓝牙连接参数
  913. onResetBLEConnection(state) {
  914. state.cIndex = -1;
  915. state.BLEConnectDevice = null;
  916. //蓝牙服务
  917. state.BLEGetServices = null;
  918. state.bConnection = false;
  919. state.bVerifiedConnection = false;
  920. },
  921. onCloseBLEConnection(state, context) {
  922. console.log("onCloseBLEConnection", state.BLEConnectDevice);
  923. let {
  924. getSuccess = null,
  925. } = context;
  926. if (state.BLERSSIInterval) {
  927. clearInterval(state.BLERSSIInterval);
  928. state.BLERSSIInterval = null;
  929. }
  930. this.commit("B_CloseBLEConnection", {
  931. deviceId: state.BLEConnectDevice.deviceId,
  932. success: () => {
  933. state.cIndex = -1;
  934. state.BLEConnectDevice = null;
  935. //蓝牙服务
  936. state.BLEGetServices = null;
  937. if (getSuccess) {
  938. getSuccess();
  939. }
  940. state.bConnection = false;
  941. state.bVerifiedConnection = false;
  942. uni.closeBluetoothAdapter({
  943. success(res) {
  944. console.log(res)
  945. state.bOpenBluetooth = false;
  946. }
  947. })
  948. }
  949. });
  950. },
  951. //不关闭 adapter
  952. onOnlyCloseBLEConnection(state, context) {
  953. let {
  954. getSuccess = null
  955. } = context;
  956. if (state.BLERSSIInterval) {
  957. clearInterval(state.BLERSSIInterval);
  958. state.BLERSSIInterval = null;
  959. }
  960. this.commit("B_CloseBLEConnection", {
  961. deviceId: state.BLEConnectDevice.deviceId,
  962. success: () => {
  963. state.cIndex = -1;
  964. state.BLEConnectDevice = null;
  965. //蓝牙服务
  966. state.BLEGetServices = null;
  967. if (getSuccess) {
  968. getSuccess();
  969. }
  970. state.bConnection = false;
  971. state.bVerifiedConnection = false;
  972. }
  973. });
  974. },
  975. onWriteBLEConnectionValue(state, context) {
  976. //#ifdef H5
  977. console.warn("h5不支持蓝牙:", 'onWriteBLEConnectionValue');
  978. return;
  979. //#endif
  980. let {
  981. getSuccess = null,
  982. getFail = null,
  983. value,
  984. bSendHex = false,
  985. bOpen = false,
  986. } = context;
  987. if (!state.BLEConnectDevice && state.cIndex == -1) {
  988. uni.showToast({
  989. title: '蓝牙设备未连接',
  990. icon: 'none'
  991. })
  992. }
  993. // console.log(22);
  994. //记录蓝牙盒子当前的指令
  995. // state.currentInstruction = value;
  996. // 发送 3 :开启原始数据
  997. // 发送4 :关闭原始数据
  998. // 发送 5 :开启步数
  999. // 发送6 :关闭步数
  1000. if (value == "3") {
  1001. state.instructionState.bOpen = true;
  1002. } else if (value == "4") {
  1003. state.instructionState.bOpen = false;
  1004. } else if (value == "5") {
  1005. state.instructionState.bSteps = true;
  1006. } else if (value == "6") {
  1007. state.instructionState.bSteps = false;
  1008. } else if (bSendHex && bOpen) {
  1009. state.instructionState.bOpen = true;
  1010. } else if (bSendHex && !bOpen) {
  1011. state.instructionState.bOpen = false;
  1012. }
  1013. let retryCount = 5;
  1014. this.commit("B_WriteBLECharacteristicValue", {
  1015. value,
  1016. retryCount,
  1017. getSuccess,
  1018. getFail,
  1019. bSendHex
  1020. });
  1021. },
  1022. //获取距离
  1023. onGetRSSITransDistance(state, context) {
  1024. let {
  1025. RSSI
  1026. } = context;
  1027. BLE.getRSSITransDistance(RSSI);
  1028. },
  1029. //添加使用的前端信息
  1030. gOnAddClientInfo(state, context) {
  1031. uni.getSystemInfo({
  1032. success: (res) => {
  1033. // console.log("系统信息:", res);
  1034. let clientInfo = res;
  1035. clientInfo.clientSystem = res.system;
  1036. reqUtil.requestData(config.URL.ADDCLIENTINFO, clientInfo, 'POST').then(
  1037. res => {
  1038. console.warn(res);
  1039. },
  1040. e => {}
  1041. );
  1042. },
  1043. fail: (err) => {},
  1044. complete: () => {}
  1045. })
  1046. },
  1047. //创建快速打击对象
  1048. gCreateFilterObj(state) {
  1049. state.filter = null;
  1050. state.deviceMs = 1;
  1051. state.filter = new o0Project.Filter();
  1052. console.log("gCreateFilterObj");
  1053. },
  1054. //更新快速打击对象数据
  1055. gUpdateFilter(state, context) {
  1056. let {
  1057. data,
  1058. callback
  1059. } = context;
  1060. let {
  1061. min,
  1062. s,
  1063. ms
  1064. } = data;
  1065. var msGap = ms - state.deviceMs;
  1066. state.deviceMs = ms;
  1067. while (msGap < 0) {
  1068. msGap += 1000;
  1069. }
  1070. // console.log(data);
  1071. let {
  1072. ax,
  1073. ay,
  1074. az
  1075. } = data.acc;
  1076. let {
  1077. gx,
  1078. gy,
  1079. gz
  1080. } = data.gyro;
  1081. state.filter.Update(new o0.Vector3(ax, ay, az), msGap, new o0.Vector3(gx, gy, gz),
  1082. callback); //我自己的更新acc的函数
  1083. },
  1084. /**
  1085. * 创建一个沙袋打击对象
  1086. * @param {Object} state
  1087. */
  1088. gCreateSandbagAlgorithm(state) {
  1089. state.sandbagAlgorithm = null;
  1090. state.deviceMs = 1;
  1091. state.sandbagAlgorithmLastTime = new Date().getTime();
  1092. state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
  1093. console.log("gCreateSandbagAlgorithm");
  1094. },
  1095. /**
  1096. * 更新 沙袋打击对象 数据
  1097. * @param {Object} state
  1098. * @param {Object} context
  1099. */
  1100. gUpdateSandbagAlgorithm(state, context) {
  1101. let {
  1102. data,
  1103. callback = null
  1104. } = context;
  1105. let {
  1106. min,
  1107. s,
  1108. ms
  1109. } = data;
  1110. let msGap = ms - state.deviceMs;
  1111. state.deviceMs = ms;
  1112. while (msGap < 0) {
  1113. msGap += 1000;
  1114. }
  1115. let {
  1116. ax,
  1117. ay,
  1118. az
  1119. } = data.acc;
  1120. let {
  1121. gx,
  1122. gy,
  1123. gz
  1124. } = data.gyro;
  1125. // ax / 10, az / 10, gz, -gx, data.ms ----- old
  1126. // ay / 10, -az / 10, gy, gz, data.ms
  1127. let [hit, dir] = state.sandbagAlgorithm.Update(ay, -az, gz, gy, msGap);
  1128. if (dir != undefined) {
  1129. let temp = state.sandbagAlgorithm.getTempValue(dir);
  1130. if (callback) {
  1131. callback(temp);
  1132. }
  1133. }
  1134. },
  1135. /**
  1136. * 开启加速计,陀螺仪,并且模拟ble发送
  1137. * @param {Object} state
  1138. */
  1139. gStartSimulateBLEUpdate(state) {
  1140. //todo 区分平台,目前是android 模块
  1141. if (state.globalMyAttitude == null) {
  1142. state.globalMyAttitude = uni.requireNativePlugin("MyAttitude");
  1143. let globalEvent = uni.requireNativePlugin('globalEvent');
  1144. globalEvent.addEventListener('updateAccAndGyro', function(e) {
  1145. //updateAccAndGyro{"accelerometer":[-0.178375244140625,9.327804565429688,2.6168670654296875],"gyroscope":[0.0018310546875,-0.0019989013671875,0.0027923583984375]}
  1146. //console.log('updateAccAndGyro' + JSON.stringify(e));
  1147. let _accArray = e.accelerometer;
  1148. let _gyroArray = e.gyroscope;
  1149. state.globalAccData.ax = _accArray[0];
  1150. state.globalAccData.ay = _accArray[1];
  1151. state.globalAccData.az = _accArray[2];
  1152. state.globalGyroData.gx = _gyroArray[0];
  1153. state.globalGyroData.gy = _gyroArray[1];
  1154. state.globalGyroData.gz = _gyroArray[2];
  1155. let box = {};
  1156. box["acc"] = state.globalAccData;
  1157. box["gyro"] = state.globalGyroData;
  1158. box["ms"] = e.ms;
  1159. //更新数据给webview,在game-play-web||game-play-sub绑定
  1160. //后面更新数据都用此接口
  1161. uni.$emit('updateBLEDeviceData', box);
  1162. });
  1163. }
  1164. var ret = state.globalMyAttitude.onStartAccAndGyro();
  1165. if (!ret.accelerometer || !ret.gyroscope) {
  1166. uni.showModal({
  1167. title: '提示',
  1168. content: '是否初始化,加速计:' + ret.accelerometer + ',陀螺仪:' + ret.gyroscope
  1169. })
  1170. }
  1171. console.log('gStartSimulateBLEUpdate:', ret);
  1172. },
  1173. /**
  1174. * 停止加速计,陀螺仪
  1175. * @param {Object} state
  1176. */
  1177. gStopSimulateBLEUpdate(state) {
  1178. //todo 区分平台,目前是android 模块
  1179. let globalEvent = uni.requireNativePlugin('globalEvent');
  1180. globalEvent.removeEventListener('updateAccAndGyro');
  1181. var ret = state.globalMyAttitude.onStopAccAndGyro();
  1182. console.log('gStopSimulateBLEUpdate:', ret);
  1183. state.globalMyAttitude = null;
  1184. },
  1185. /**
  1186. * 限制开始游戏
  1187. */
  1188. glimitPlayGame(state, context) {
  1189. let {
  1190. gameTags,
  1191. callback
  1192. } = context;
  1193. //没有标签直接进去
  1194. if (gameTags.length == 0) {
  1195. callback();
  1196. return;
  1197. }
  1198. let canPlay = false;
  1199. gameTags.forEach((item) => {
  1200. //如果存在普通模式
  1201. if (item.tagMode === 'normal') {
  1202. canPlay = true;
  1203. }
  1204. if (canPlay)
  1205. return;
  1206. })
  1207. if (!canPlay) {
  1208. //2.如果普通模式不存在,就判断是否连接硬件了
  1209. if (!state.BLEConnectDevice || state.cIndex == -1) {
  1210. uni.showToast({
  1211. title: "请连接标签对应的设备模式!",
  1212. icon: "none",
  1213. duration: 2000,
  1214. mask: true
  1215. })
  1216. return;
  1217. }
  1218. //3.如果连接了设备,判断但是处于什么模式
  1219. gameTags.forEach((item, index, selfArr) => {
  1220. //如果存在普通模式
  1221. if (item.tagMode === state.BLEConnectDevice.usageMode) {
  1222. canPlay = true;
  1223. }
  1224. if (canPlay)
  1225. return;
  1226. if (index == selfArr.length - 1) {
  1227. uni.showToast({
  1228. title: "游戏没有当前设备模式!",
  1229. icon: "none",
  1230. duration: 2000,
  1231. mask: true
  1232. })
  1233. }
  1234. })
  1235. }
  1236. if (canPlay) {
  1237. callback();
  1238. }
  1239. },
  1240. checkAppUpdata(state) {
  1241. //#ifdef APP-PLUS
  1242. let _temp = {
  1243. appid: plus.runtime.appid,
  1244. version: state.version,
  1245. versionCode: state.versionCode,
  1246. platform: state.platform.toLocaleLowerCase(),
  1247. }
  1248. //#endif
  1249. //#ifdef H5
  1250. //此 _temp 测试用
  1251. let _temp = {
  1252. appid: '1',
  1253. version: "2.0.0",
  1254. versionCode: "20122202",
  1255. platform: "android",
  1256. }
  1257. //#endif
  1258. reqUtil.requestData(config.URL.APPVERSIONUPDATE, _temp).then(res => {
  1259. console.log('requestData APPVERSIONUPDATE =====', res);
  1260. let _data = res.data;
  1261. if (res.code == 0 && res.data.status === 1) {
  1262. uni.showModal({ //提醒用户更新
  1263. title: "更新提示",
  1264. content: res.data.note,
  1265. success: (res) => {
  1266. if (res.confirm) {
  1267. if (state.platform.toLocaleLowerCase() == "android") {
  1268. plus.runtime.openURL(_data.url, function(res) {
  1269. plus.nativeUI.alert("本机没安装应用宝,请安装后获取新版本。");
  1270. }, 'com.tencent.android.qqdownloader');
  1271. } else {
  1272. //ios
  1273. plus.runtime.openURL(_data.url);
  1274. }
  1275. }
  1276. }
  1277. })
  1278. } else {
  1279. uni.showToast({
  1280. title: '当前为最新版本',
  1281. icon: 'none',
  1282. duration: 2000,
  1283. mask: true
  1284. })
  1285. }
  1286. },
  1287. e => {
  1288. console.log(e)
  1289. });
  1290. },
  1291. /**
  1292. * 蓝牙BLE迁移到store.js
  1293. */
  1294. // 初始化蓝牙模块适配器
  1295. B_OpenBluetoothAdapter(state, context) {
  1296. let {
  1297. success,
  1298. fail,
  1299. complete
  1300. } = context;
  1301. //#ifdef H5
  1302. console.warn('h5不加载蓝牙模块');
  1303. return;
  1304. //#endif
  1305. uni.openBluetoothAdapter({
  1306. success: res => {
  1307. if (success)
  1308. success(res);
  1309. },
  1310. fail: res => {
  1311. if (fail)
  1312. fail(res);
  1313. },
  1314. complete: res => {
  1315. if (complete)
  1316. complete(res);
  1317. }
  1318. })
  1319. },
  1320. /**
  1321. * 关闭蓝牙模块适配器
  1322. */
  1323. B_CloseBluetoothAdapter() {
  1324. //#ifdef H5
  1325. console.warn('h5不加载蓝牙模块');
  1326. return;
  1327. //#endif
  1328. uni.closeBluetoothAdapter({
  1329. success: res => {
  1330. console.log('断开蓝牙模块成功');
  1331. uni.showToast({
  1332. icon: "none",
  1333. title: "蓝牙已经断开!",
  1334. mask: false,
  1335. duration: 3000
  1336. });
  1337. }
  1338. });
  1339. },
  1340. B_OnBLEConnectionStateChange(state) {
  1341. let _self = this;
  1342. //#ifdef H5
  1343. console.warn('h5不加载蓝牙模块');
  1344. return;
  1345. //#endif
  1346. uni.onBLEConnectionStateChange(res => {
  1347. // 该方法回调中可以用于处理连接意外断开等异常情况
  1348. console.log(`蓝牙连接状态 -------------------------->`, JSON.stringify(res));
  1349. if (!res.connected) {
  1350. //要在连接的状态下 ,并且获取过匹配列表有参数的情况下,才提示重连
  1351. if (!state.bShowBLEConnectModal && state.bVerifiedConnection) {
  1352. state.bShowBLEConnectModal = true;
  1353. let _connectItem = Object.assign({}, state.BLEConnectDevice);
  1354. let _cIndex = state.cIndex;
  1355. //断开连接后reset一下参数
  1356. _self.commit("onResetBLEConnection");
  1357. let _tip = state.bGamePlaying ? "蓝牙已断开是否重新连接蓝牙?重连需要重启游戏!" : "蓝牙已断开是否重新连接蓝牙";
  1358. uni.showModal({
  1359. title: _tip,
  1360. success: (sRes) => {
  1361. state.bShowBLEConnectModal = false;
  1362. if (sRes.confirm) {
  1363. console.log("重连的_cIndex:", _cIndex);
  1364. _self.commit("onCreateBLEConnection", {
  1365. item: _connectItem,
  1366. index: _cIndex,
  1367. initItem: true,
  1368. getSuccess: () => {
  1369. //此处不检查外部设备
  1370. uni.$emit('retryConnectBLESuccess');
  1371. },
  1372. getinitAdapter: () => {}
  1373. })
  1374. }
  1375. }
  1376. })
  1377. } else {
  1378. //断开连接后reset一下参数
  1379. _self.commit("onResetBLEConnection");
  1380. }
  1381. uni.$emit('callbackCloseBLE');
  1382. }
  1383. });
  1384. },
  1385. /**
  1386. * 连接低功耗蓝牙设备。
  1387. * 若APP在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。
  1388. */
  1389. B_CreateBLEConnection(state, context) {
  1390. let {
  1391. item,
  1392. success,
  1393. fail
  1394. } = context;
  1395. this.commit('initBLEData');
  1396. state.deviceId = item.deviceId;
  1397. let timeout = 10000;
  1398. // console.log("B_CreateBLEConnection deviceId ==", state.deviceId)
  1399. uni.createBLEConnection({
  1400. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  1401. deviceId: state.deviceId,
  1402. timeout: timeout,
  1403. success: res => {
  1404. if (success) {
  1405. success(res);
  1406. }
  1407. //设置mtu
  1408. // setTimeout(() => {
  1409. // uni.setBLEMTU({
  1410. // deviceId: state.deviceId,
  1411. // mtu: 80,
  1412. // success: (res) => {
  1413. // console.log("设置mtu");
  1414. // console.log(res)
  1415. // uni.$emit('log', "设置mtu=80," + JSON.stringify(
  1416. // res));
  1417. // },
  1418. // fail: (error) => {
  1419. // console.log(error)
  1420. // }
  1421. // })
  1422. // }, 1000)
  1423. },
  1424. fail: res => {
  1425. if (fail)
  1426. fail(res);
  1427. }
  1428. });
  1429. },
  1430. /**
  1431. * 获取设备的服务ID
  1432. */
  1433. B_GetBLEDeviceServices(state, context) {
  1434. let {
  1435. retryCount,
  1436. item,
  1437. callback,
  1438. getServiceList,
  1439. getFail,
  1440. } = context;
  1441. let serviceList = [];
  1442. let _self = this;
  1443. uni.getBLEDeviceServices({
  1444. deviceId: item.deviceId,
  1445. success: res => {
  1446. // console.log("getBLEDeviceServices==", JSON.stringify(res), item);
  1447. serviceList = res.services;
  1448. if (getServiceList) {
  1449. getServiceList(serviceList);
  1450. }
  1451. if (serviceList.length == 0) {
  1452. console.log(item.deviceId + " retryCount:" + retryCount);
  1453. if (retryCount > 0) {
  1454. retryCount--;
  1455. context.retryCount = retryCount;
  1456. setTimeout(() => {
  1457. this.commit('B_GetBLEDeviceServices', context);
  1458. }, 1000)
  1459. return;
  1460. }
  1461. if (getFail) {
  1462. getFail();
  1463. }
  1464. uni.hideToast();
  1465. uni.showModal({
  1466. title: '提示',
  1467. content: '1.获取服务失败,请尝试重新连接设备。\r\n2.尝试重启设备再重新连接。'
  1468. })
  1469. }
  1470. for (let i = 0; i < serviceList.length; i++) {
  1471. let service = serviceList[i];
  1472. if (service.uuid.toLocaleLowerCase() === item.PRIMARY_SERVICE
  1473. .toLocaleLowerCase()) {
  1474. state.serviceId = service.uuid;
  1475. //开始获取指定服务的特征值
  1476. _self.commit('B_GetBLEDeviceCharacteristics', {
  1477. item: item,
  1478. callback: callback
  1479. });
  1480. break;
  1481. }
  1482. }
  1483. },
  1484. fail: failRes => {
  1485. console.log('device services:', failRes.services);
  1486. uni.hideToast();
  1487. uni.showModal({
  1488. title: '连接错误',
  1489. content: '请尝试重新连接设备。'
  1490. })
  1491. if (getFail) {
  1492. getFail();
  1493. }
  1494. }
  1495. });
  1496. },
  1497. /**
  1498. * 获取指定服务的特征值
  1499. */
  1500. B_GetBLEDeviceCharacteristics(state, context) {
  1501. let {
  1502. item,
  1503. callback
  1504. } = context;
  1505. let deviceId = state.deviceId;
  1506. let serviceId = state.serviceId;
  1507. let characteristicsList = [];
  1508. uni.getBLEDeviceCharacteristics({
  1509. deviceId,
  1510. serviceId,
  1511. success: res => {
  1512. if (item.PRIMARY_NOTIFY != '') {
  1513. state.notifyCharacteristicId = item.PRIMARY_NOTIFY;
  1514. this.commit('B_NotifyBLECharacteristicValueChange', {
  1515. callback: callback
  1516. });
  1517. }
  1518. if (item.PRIMARY_WRITE != '') {
  1519. state.writeCharacteristicId = item.PRIMARY_WRITE;
  1520. }
  1521. },
  1522. fail: res => {
  1523. console.log('device getBLEDeviceCharacteristics failed:', JSON.stringify(res))
  1524. }
  1525. })
  1526. },
  1527. //启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。
  1528. //注意:必须设备的特征值支持notify或者indicate才可以成功调用,具体参照 characteristic 的 properties 属性
  1529. B_NotifyBLECharacteristicValueChange(state, context) {
  1530. let {
  1531. callback
  1532. } = context;
  1533. // 启用notify功能
  1534. // console.log("启用notify功能");
  1535. uni.notifyBLECharacteristicValueChange({
  1536. state: true,
  1537. deviceId: state.deviceId,
  1538. serviceId: state.serviceId,
  1539. characteristicId: state.notifyCharacteristicId,
  1540. success: (res) => {
  1541. this.commit('B_OnBLECharacteristicValueChange', {
  1542. callback: callback
  1543. });
  1544. },
  1545. fail: (res) => {
  1546. uni.showToast({
  1547. title: 'notify启动失败',
  1548. icon: "none",
  1549. mask: true
  1550. });
  1551. }
  1552. })
  1553. },
  1554. //监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。
  1555. B_OnBLECharacteristicValueChange(state, context) {
  1556. let {
  1557. callback
  1558. } = context;
  1559. // console.log("onBLECharacteristicValueChange success");
  1560. if (callback) {
  1561. callback({
  1562. notifyCharacteristicId: state.notifyCharacteristicId,
  1563. writeCharacteristicId: state.writeCharacteristicId
  1564. })
  1565. }
  1566. uni.onBLECharacteristicValueChange(function(res) {
  1567. //如果是ota 更新服务,这里处理通知ota更新数据
  1568. if (res.serviceId.toLocaleLowerCase() === state.UUID_OTA_SERVICE) {
  1569. uni.$emit("OTAValueChange", res);
  1570. return;
  1571. }
  1572. //serviceId 0000FFF0-0000-1000-8000-00805F9B34FB characteristic 0000FFF1-0000-1000-8000-00805F9B34FB
  1573. // console.log(`store ${res.serviceId} characteristic ${res.characteristicId} has changed, now is ${res.value}`);
  1574. let box = {};
  1575. var resValue = BLE.ab2hext(res.value); //16进制字符串
  1576. if (state.currentInstruction == "V" && state.showToast) {
  1577. var resValueStr = BLE.hexToString(resValue);
  1578. let _info = {
  1579. type: 'version',
  1580. instruction: 'V',
  1581. value: resValueStr.replace(/\{|}/g, '').trim()
  1582. }
  1583. uni.$emit('listenerBLE', _info);
  1584. state.currentInstruction = "";
  1585. state.showToast = false;
  1586. return;
  1587. } else if (state.currentInstruction == 'M' && state.bListenerMac) {
  1588. var resValueStr = BLE.hexToString(resValue);
  1589. let _info = {
  1590. type: 'mac',
  1591. instruction: 'M',
  1592. value: resValueStr.replace(/\{|}/g, '').trim()
  1593. }
  1594. uni.$emit('listenerBLE', _info);
  1595. state.currentInstruction = "";
  1596. state.bListenerMac = false;
  1597. return;
  1598. }
  1599. //步数数据解析
  1600. if (state.bListenerJson) {
  1601. var resValueStr = BLE.hexToString(resValue);
  1602. console.log(resValueStr);
  1603. box["Json"] = resValueStr;
  1604. uni.$emit('updateBLEDeviceJson', box);
  1605. }
  1606. //解析4组加速计数据
  1607. if (state.bListenerAccArray) {
  1608. let accArray = [];
  1609. // 5B00E000260019F7F4FFF6FFF1000000E200260019F7F4FFF6FFF1000000E60031001BF81AFFF5FFF0000000E90031001BF81AFFF5FFF0000000EB0031001BF81AFFF5FFF000005D: length =144
  1610. // console.log("1======= " + BLE.buf2hex(res.value));
  1611. // var hex =
  1612. // '5B00E000260019F7F4FFF6FFF1000000E200260019F7F4FFF6FFF1000000E60031001BF81AFFF5FFF0000000E90031001BF81AFFF5FFF0000000EB0031001BF81AFFF5FFF000005D'
  1613. // var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function(h) {
  1614. // return parseInt(h, 16)
  1615. // }))
  1616. // var buffer = typedArray.buffer;
  1617. // console.log("hex= " + resValue + ",length:"+ resValue.length);
  1618. // console.log(resValue.length);
  1619. // console.log(res.value);
  1620. // console.log(buffer);
  1621. for (let i = 0; i < 5; i++) {
  1622. let index = i * 28;
  1623. let ms = BLE.hex2int(resValue.substr(2 + index, 4));
  1624. // console.log(index + "==" + resValue.substr(2 + index, 4));
  1625. let axStr = resValue.substr(6 + index, 4);
  1626. let ayStr = resValue.substr(10 + index, 4);
  1627. let azStr = resValue.substr(14 + index, 4);
  1628. let gxStr = resValue.substr(18 + index, 4);
  1629. let gyStr = resValue.substr(22 + index, 4);
  1630. let gzStr = resValue.substr(26 + index, 4);
  1631. //一个字节最大只能表示265 2个字节可以表示65536 然后你这边做一下转换 例如00 3E 3*16+14=62 ----->0.03 g
  1632. //(真实值= AD值 /32768 * 16)
  1633. //0.003 = 62 / 2768 * 16
  1634. let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
  1635. let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
  1636. let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
  1637. //角速度(AD值/32768 * 2000) 角速度单位是 °/s 范围是 正负2000
  1638. let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
  1639. let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
  1640. let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
  1641. accArray.push({
  1642. acc: {
  1643. ax: ax,
  1644. ay: ay,
  1645. az: az
  1646. },
  1647. gyro: {
  1648. gx: gx,
  1649. gy: gy,
  1650. gz: gz
  1651. },
  1652. ms: ms
  1653. })
  1654. }
  1655. uni.$emit('updateBLEDeviceData', accArray);
  1656. // for (let i = 0; i < accArray.length; i++) {
  1657. // let _temp = accArray[i];
  1658. // box["acc"] = {
  1659. // ax: _temp.ax,
  1660. // ay: _temp.ay,
  1661. // az: _temp.az,
  1662. // };
  1663. // box["gyro"] = {
  1664. // gx: _temp.gx,
  1665. // gy: _temp.gy,
  1666. // gz: _temp.gz,
  1667. // };
  1668. // box["ms"] = _temp.ms;
  1669. // uni.$emit('updateBLEDeviceData', box);
  1670. // }
  1671. }
  1672. //原始数据解析
  1673. if (state.bListenerUpdate) {
  1674. //R/L 左手还是右手
  1675. let handle = resValue.substr(6, 2);
  1676. let axStr = resValue.substr(8, 4);
  1677. let ayStr = resValue.substr(12, 4);
  1678. let azStr = resValue.substr(16, 4);
  1679. //一个字节最大只能表示265 2个字节可以表示65536 然后你这边做一下转换 例如00 3E 3*16+14=62 ----->0.03 g
  1680. //(真实值= AD值 /32768 * 16)
  1681. //0.003 = 62 / 2768 * 16
  1682. let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
  1683. let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
  1684. let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
  1685. let gxStr = resValue.substr(20, 4);
  1686. let gyStr = resValue.substr(24, 4);
  1687. let gzStr = resValue.substr(28, 4);
  1688. //角速度(AD值/32768 * 2000) 角速度单位是 °/s 范围是 正负2000
  1689. let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
  1690. let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
  1691. let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
  1692. //毫秒
  1693. let ms = BLE.hex2int(resValue.substr(2, 4));
  1694. //分
  1695. let min = BLE.hex2int(resValue.substr(32, 2));
  1696. //秒
  1697. let s = BLE.hex2int(resValue.substr(34, 2));
  1698. box["handle"] = BLE.hexToString(handle);
  1699. box["acc"] = {
  1700. ax,
  1701. ay,
  1702. az
  1703. };
  1704. box["gyro"] = {
  1705. gx,
  1706. gy,
  1707. gz
  1708. };
  1709. box["min"] = min;
  1710. box["s"] = s;
  1711. box["ms"] = ms;
  1712. //更新数据给webview,在game-play-web||game-play-sub绑定
  1713. //后面更新数据都用此接口
  1714. uni.$emit('updateBLEDeviceData', box);
  1715. }
  1716. });
  1717. },
  1718. onTestEmit(state) {
  1719. let box = {};
  1720. let accArray = [];
  1721. var resValue =
  1722. '5B00E000260019F7F4FFF6FFF1000000E200260019F7F4FFF6FFF1000000E60031001BF81AFFF5FFF0000000E90031001BF81AFFF5FFF0000000EB0031001BF81AFFF5FFF000005D';
  1723. for (let i = 0; i < 5; i++) {
  1724. let index = i * 28;
  1725. let ms = BLE.hex2int(resValue.substr(2 + index, 4));
  1726. // console.log(index + "==" + resValue.substr(2 + index, 4));
  1727. let axStr = resValue.substr(6 + index, 4);
  1728. let ayStr = resValue.substr(10 + index, 4);
  1729. let azStr = resValue.substr(14 + index, 4);
  1730. let gxStr = resValue.substr(18 + index, 4);
  1731. let gyStr = resValue.substr(22 + index, 4);
  1732. let gzStr = resValue.substr(26 + index, 4);
  1733. //一个字节最大只能表示265 2个字节可以表示65536 然后你这边做一下转换 例如00 3E 3*16+14=62 ----->0.03 g
  1734. //(真实值= AD值 /32768 * 16)
  1735. //0.003 = 62 / 2768 * 16
  1736. let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
  1737. let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
  1738. let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
  1739. //角速度(AD值/32768 * 2000) 角速度单位是 °/s 范围是 正负2000
  1740. let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
  1741. let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
  1742. let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
  1743. accArray.push({
  1744. ax: ax,
  1745. ay: ay,
  1746. az: az,
  1747. gx: gx,
  1748. gy: gy,
  1749. gz: gz,
  1750. ms: ms
  1751. })
  1752. }
  1753. for (let i = 0; i < accArray.length; i++) {
  1754. let _temp = accArray[i];
  1755. box["acc"] = {
  1756. ax: _temp.ax,
  1757. ay: _temp.ay,
  1758. az: _temp.az,
  1759. };
  1760. box["gyro"] = {
  1761. gx: _temp.gx,
  1762. gy: _temp.gy,
  1763. gz: _temp.gz,
  1764. };
  1765. box["ms"] = _temp.ms;
  1766. uni.$emit('updateBLEDeviceData', box);
  1767. }
  1768. },
  1769. //向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
  1770. B_WriteBLECharacteristicValue(state, context) {
  1771. let {
  1772. value,
  1773. retryCount,
  1774. success,
  1775. getFail,
  1776. bSendHex,
  1777. } = context;
  1778. if (!value && value === '') {
  1779. uni.showToast({
  1780. title: "指令为空"
  1781. })
  1782. return;
  1783. }
  1784. let _sendData;
  1785. if (bSendHex) {
  1786. state.bRopeKeyTwo = 0;
  1787. state.bRopeKeyOne = 0;
  1788. //如果是发送16进制
  1789. state.bListenerHexUpdate = true;
  1790. //重置原 update
  1791. state.bListenerUpdate = false;
  1792. let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
  1793. return parseInt(h, 16)
  1794. }))
  1795. _sendData = typedArray.buffer;
  1796. } else {
  1797. state.bListenerHexUpdate = false;
  1798. //记录一下指令
  1799. state.currentInstruction = value;
  1800. state.showToast = false;
  1801. state.bListenerUpdate = false;
  1802. state.bListenerAccArray = false;
  1803. //V 获取版本,M 获取mac 地址
  1804. if (value == "V")
  1805. state.showToast = true;
  1806. if (value == "M") {
  1807. state.showToast = true;
  1808. state.bListenerMac = true;
  1809. }
  1810. if (value == "4") {
  1811. state.bListenerUpdate = false;
  1812. }
  1813. if (value == "3") {
  1814. if (state.bListenerUpdate) {
  1815. console.warn("原始数据已开启");
  1816. }
  1817. state.bListenerUpdate = true;
  1818. }
  1819. if (value == "h") {
  1820. state.bListenerAccArray = false;
  1821. }
  1822. if (value == "H") {
  1823. if (state.bListenerAccArray) {
  1824. uni.showToast({
  1825. title: "加速计组数据已开启"
  1826. })
  1827. return;
  1828. }
  1829. state.bListenerAccArray = true;
  1830. }
  1831. _sendData = BLE.str2ab(value);
  1832. }
  1833. console.log("currentInstruction:" + state.currentInstruction);
  1834. uni.writeBLECharacteristicValue({
  1835. deviceId: state.deviceId,
  1836. serviceId: state.serviceId,
  1837. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1838. characteristicId: state.writeCharacteristicId,
  1839. // 这里的value是ArrayBuffer类型
  1840. value: _sendData,
  1841. success: (res) => {
  1842. console.log('writeBLECharacteristicValue success', res.errMsg, value,
  1843. retryCount);
  1844. if (success) {
  1845. success(res);
  1846. }
  1847. },
  1848. fail: (fail) => {
  1849. console.log(fail)
  1850. //重新写入
  1851. if (retryCount > 0) {
  1852. console.log("writeBLECharacteristicValue Rewrite ===================>" +
  1853. value + " == " + retryCount);
  1854. retryCount--;
  1855. setTimeout(() => {
  1856. this.commit("B_WriteBLECharacteristicValue", {
  1857. value,
  1858. retryCount,
  1859. success,
  1860. getFail
  1861. });
  1862. }, 300);
  1863. }
  1864. if (getFail) {
  1865. getFail(fail);
  1866. }
  1867. }
  1868. })
  1869. },
  1870. B_OnSetMTU(state) {
  1871. uni.setBLEMTU({
  1872. deviceId: state.deviceId,
  1873. mtu: 80,
  1874. success: (res) => {
  1875. console.log("设置mtu");
  1876. console.log(res)
  1877. uni.$emit('log', "设置mtu=80," + JSON.stringify(
  1878. res));
  1879. },
  1880. fail: (error) => {
  1881. console.log(error)
  1882. }
  1883. })
  1884. },
  1885. /**
  1886. * 断开蓝牙连接
  1887. */
  1888. B_CloseBLEConnection(state, context) {
  1889. let {
  1890. deviceId,
  1891. success = null
  1892. } = context;
  1893. uni.closeBLEConnection({
  1894. deviceId,
  1895. success: res => {
  1896. console.log("关闭蓝牙连接!deviceId=" + deviceId);
  1897. if (success)
  1898. success();
  1899. },
  1900. fail: (fail) => {
  1901. console.log("关闭蓝牙失败", fail);
  1902. }
  1903. });
  1904. }
  1905. }
  1906. })
  1907. export default store