store.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  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.0.108:7456", //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["acc"] = {
  1710. ax: -ay,
  1711. ay: -ax,
  1712. az: az
  1713. };
  1714. box["gyro"] = {
  1715. gx: -gy,
  1716. gy: -gx,
  1717. gz: gz
  1718. };
  1719. box["min"] = min;
  1720. box["s"] = s;
  1721. box["ms"] = ms;
  1722. //更新数据给webview,在game-play-web||game-play-sub绑定
  1723. //后面更新数据都用此接口
  1724. uni.$emit('updateBLEDeviceData', box);
  1725. }
  1726. });
  1727. },
  1728. onTestEmit(state) {
  1729. let box = {};
  1730. let accArray = [];
  1731. var resValue =
  1732. '5B00E000260019F7F4FFF6FFF1000000E200260019F7F4FFF6FFF1000000E60031001BF81AFFF5FFF0000000E90031001BF81AFFF5FFF0000000EB0031001BF81AFFF5FFF000005D';
  1733. for (let i = 0; i < 5; i++) {
  1734. let index = i * 28;
  1735. let ms = BLE.hex2int(resValue.substr(2 + index, 4));
  1736. // console.log(index + "==" + resValue.substr(2 + index, 4));
  1737. let axStr = resValue.substr(6 + index, 4);
  1738. let ayStr = resValue.substr(10 + index, 4);
  1739. let azStr = resValue.substr(14 + index, 4);
  1740. let gxStr = resValue.substr(18 + index, 4);
  1741. let gyStr = resValue.substr(22 + index, 4);
  1742. let gzStr = resValue.substr(26 + index, 4);
  1743. //一个字节最大只能表示265 2个字节可以表示65536 然后你这边做一下转换 例如00 3E 3*16+14=62 ----->0.03 g
  1744. //(真实值= AD值 /32768 * 16)
  1745. //0.003 = 62 / 2768 * 16
  1746. let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
  1747. let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
  1748. let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
  1749. //角速度(AD值/32768 * 2000) 角速度单位是 °/s 范围是 正负2000
  1750. let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
  1751. let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
  1752. let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
  1753. accArray.push({
  1754. ax: ax,
  1755. ay: ay,
  1756. az: az,
  1757. gx: gx,
  1758. gy: gy,
  1759. gz: gz,
  1760. ms: ms
  1761. })
  1762. }
  1763. for (let i = 0; i < accArray.length; i++) {
  1764. let _temp = accArray[i];
  1765. box["acc"] = {
  1766. ax: _temp.ax,
  1767. ay: _temp.ay,
  1768. az: _temp.az,
  1769. };
  1770. box["gyro"] = {
  1771. gx: _temp.gx,
  1772. gy: _temp.gy,
  1773. gz: _temp.gz,
  1774. };
  1775. box["ms"] = _temp.ms;
  1776. uni.$emit('updateBLEDeviceData', box);
  1777. }
  1778. },
  1779. //向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
  1780. B_WriteBLECharacteristicValue(state, context) {
  1781. let {
  1782. value,
  1783. retryCount,
  1784. success,
  1785. getFail,
  1786. bSendHex,
  1787. } = context;
  1788. if (!value && value === '') {
  1789. uni.showToast({
  1790. title: "指令为空"
  1791. })
  1792. return;
  1793. }
  1794. let _sendData;
  1795. if (bSendHex) {
  1796. state.bRopeKeyTwo = 0;
  1797. state.bRopeKeyOne = 0;
  1798. //如果是发送16进制
  1799. state.bListenerHexUpdate = true;
  1800. //重置原 update
  1801. state.bListenerUpdate = false;
  1802. let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
  1803. return parseInt(h, 16)
  1804. }))
  1805. _sendData = typedArray.buffer;
  1806. } else {
  1807. state.bListenerHexUpdate = false;
  1808. //记录一下指令
  1809. state.currentInstruction = value;
  1810. state.showToast = false;
  1811. state.bListenerUpdate = false;
  1812. state.bListenerAccArray = false;
  1813. //V 获取版本,M 获取mac 地址
  1814. if (value == "V")
  1815. state.showToast = true;
  1816. if (value == "M") {
  1817. state.showToast = true;
  1818. state.bListenerMac = true;
  1819. }
  1820. if (value == "4") {
  1821. state.bListenerUpdate = false;
  1822. }
  1823. if (value == "3") {
  1824. if (state.bListenerUpdate) {
  1825. console.warn("原始数据已开启");
  1826. }
  1827. state.bListenerUpdate = true;
  1828. }
  1829. if (value == "h") {
  1830. state.bListenerAccArray = false;
  1831. }
  1832. if (value == "H") {
  1833. if (state.bListenerAccArray) {
  1834. uni.showToast({
  1835. title: "加速计组数据已开启"
  1836. })
  1837. return;
  1838. }
  1839. state.bListenerAccArray = true;
  1840. }
  1841. _sendData = BLE.str2ab(value);
  1842. }
  1843. console.log("currentInstruction:" + state.currentInstruction);
  1844. uni.writeBLECharacteristicValue({
  1845. deviceId: state.deviceId,
  1846. serviceId: state.serviceId,
  1847. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  1848. characteristicId: state.writeCharacteristicId,
  1849. // 这里的value是ArrayBuffer类型
  1850. value: _sendData,
  1851. success: (res) => {
  1852. console.log('writeBLECharacteristicValue success', res.errMsg, value,
  1853. retryCount);
  1854. if (success) {
  1855. success(res);
  1856. }
  1857. },
  1858. fail: (fail) => {
  1859. console.log(fail)
  1860. //重新写入
  1861. if (retryCount > 0) {
  1862. console.log("writeBLECharacteristicValue Rewrite ===================>" +
  1863. value + " == " + retryCount);
  1864. retryCount--;
  1865. setTimeout(() => {
  1866. this.commit("B_WriteBLECharacteristicValue", {
  1867. value,
  1868. retryCount,
  1869. success,
  1870. getFail
  1871. });
  1872. }, 300);
  1873. }
  1874. if (getFail) {
  1875. getFail(fail);
  1876. }
  1877. }
  1878. })
  1879. },
  1880. B_OnSetMTU(state) {
  1881. uni.setBLEMTU({
  1882. deviceId: state.deviceId,
  1883. mtu: 80,
  1884. success: (res) => {
  1885. console.log("设置mtu");
  1886. console.log(res)
  1887. uni.$emit('log', "设置mtu=80," + JSON.stringify(
  1888. res));
  1889. },
  1890. fail: (error) => {
  1891. console.log(error)
  1892. }
  1893. })
  1894. },
  1895. /**
  1896. * 断开蓝牙连接
  1897. */
  1898. B_CloseBLEConnection(state, context) {
  1899. let {
  1900. deviceId,
  1901. success = null
  1902. } = context;
  1903. uni.closeBLEConnection({
  1904. deviceId,
  1905. success: res => {
  1906. console.log("关闭蓝牙连接!deviceId=" + deviceId);
  1907. if (success)
  1908. success();
  1909. },
  1910. fail: (fail) => {
  1911. console.log("关闭蓝牙失败", fail);
  1912. }
  1913. });
  1914. }
  1915. }
  1916. })
  1917. export default store