store.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150
  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. import BLERGB from 'util/util-js/BLE_RGB.js'
  9. //快速打击部分
  10. import o0 from "@/util/util-js/o0.js"
  11. import o0Project from "@/util/util-js/o0Project.js"
  12. import o0ProjectRelease from "@/util/util-js/o0ProjectRelease0.1.js"
  13. import deviceData from "@/util/util-js/devices.js"
  14. // 加载算法插件 JumpIdentificationModule
  15. var jumpIdenModule = uni.requireNativePlugin("JumpIdentificationModule")
  16. Vue.use(Vuex)
  17. const store = new Vuex.Store({
  18. state: {
  19. // vLog:'',
  20. //引导层
  21. bGuidePages: false,
  22. //是否显示Canvas
  23. bCanvasShow: true,
  24. /**
  25. * 是否需要强制登录
  26. */
  27. forcedLogin: false,
  28. /**
  29. * 蓝牙实时发送数据的页面的名称
  30. */
  31. currentPageName: '',
  32. hasLogin: false,
  33. userInfo: null,
  34. userName: "匿名",
  35. days: 0,
  36. remainingDays: 0,
  37. signature: '',
  38. avatarUrl: "/static/defaultAvatar.png",
  39. /**
  40. * 新手教程相关
  41. */
  42. // 是否是新用户,
  43. //TODO:登录接口返回的数据来判断
  44. bNewUser: false,
  45. //是否是第一次走新手
  46. bNewGuide: false,
  47. //解锁状态,和首次安装app相关
  48. //注意添加新字段时候。需要到 platform-page/guide.vue 确认需不需要添加新的reset
  49. guideUnlockState: {
  50. firstInstallation: true, //是否首次安装
  51. firstDisconnectBluetooth: true, //是否首次连接蓝牙
  52. firstUnlockJumpUp: true, //是否首次向上跳
  53. firstUnlockLeftAndRightJump: true, //是否首次左右跳
  54. firstUnlockLeftAndRightRotationJump: true,
  55. firstPromptSelectLevel: true //是否首次提示选择关卡
  56. },
  57. token: '',
  58. gender: 0,
  59. //省市区数据
  60. city: {
  61. label: '北京市-北京市-东城区',
  62. cityCode: "110101",
  63. //picker 选择器的index数组
  64. value: [0, 0, 0]
  65. },
  66. birthday: date.formatTime(new Date()),
  67. //默认值
  68. height: 0,
  69. weight: 0,
  70. //最近在玩的列表
  71. playGames: [],
  72. //最近在玩的排行游戏列表
  73. playRankingGames: [],
  74. //全部的游戏列表
  75. allGames: [],
  76. //关注的游戏列表
  77. favoriteGames: [],
  78. // 排行榜里面显示的游戏
  79. rankSelectedGame: null,
  80. rankInfo: null,
  81. cityName: "某市",
  82. /**
  83. * 默认的运动数据
  84. * date.addDaysFromNewDate(new Date(),1)
  85. */
  86. defaultPlanData: {
  87. startTime: date.formatDate(new Date()),
  88. endTime: date.addDaysFromNewDate(new Date(), 6),
  89. targetWeight: 0, //目标公斤
  90. calorie: 360, //运动消耗的卡路里,默认300 大卡
  91. cumulativeCalorie: 0, //累计增重
  92. sportTime: 40, //运动时间
  93. /**
  94. * 本地记录的消耗卡路里数量
  95. */
  96. localCalorie: 0,
  97. /**
  98. * 显示卡路里,过了12点清空
  99. */
  100. showCalorie: 0,
  101. /**
  102. * 总和
  103. */
  104. allCalorie: 0
  105. },
  106. /**
  107. * 计划的运动数据
  108. */
  109. planData: {
  110. startTime: date.formatDate(new Date()),
  111. endTime: date.formatDate(new Date()), //date.addDaysFromNewDate(new Date(),1),
  112. targetWeight: 0, //目标公斤
  113. cumulativeCalorie: 0, //累计增重
  114. calorie: 300, //运动消耗的卡路里
  115. sportTime: 40, //运动时间
  116. /**
  117. * 本地记录的消耗卡路里数量
  118. */
  119. localCalorie: 0,
  120. /**
  121. * 显示卡路里,过了12点清空
  122. */
  123. showCalorie: 0,
  124. /**
  125. * 总和
  126. */
  127. allCalorie: 0
  128. },
  129. //记录表盘计划刷新的卡路里
  130. oldArcbarProCalorie: 0,
  131. //记录表盘当前的总卡路里
  132. oldArcbarAllCalorie: 0,
  133. //当前运动的世时间
  134. localSportTime: 0,
  135. //当前运动时间,运动时候记录的时间
  136. runingTime: 0,
  137. //蓝牙设备信息列表
  138. //id 不可变,用于保存到本地区分
  139. BLEInfoList: deviceData.getDeviceList(),
  140. //记录的蓝牙设备,保存id, 和对应的蓝牙连接数据
  141. BLEDeviceList: [],
  142. //显示的蓝牙设备,取本地数据时候更新
  143. BLEDeviceShowList: [],
  144. //选择连接的蓝牙设备
  145. BLEConnectDevice: null,
  146. //获取到的服务
  147. BLEGetServices: null,
  148. //当前发送给蓝牙的指令,目前是只有蓝牙手柄
  149. currentInstruction: '',
  150. instructionState: {
  151. // bAcc: false, //是否开启加速计状态
  152. // bGyroscope: false, //是否开启陀螺仪状态
  153. bOpen: false, //是否开启指令
  154. bSteps: false, //是否开启步数
  155. },
  156. //绑定的设备
  157. DeviceBindingList: [{
  158. id: 0,
  159. cname: "开启手机数据",
  160. ename: "bindMobilePhoneBandage",
  161. icon: "/static/devicesIcon/bandage.png",
  162. mIcon: "/static/devicesIcon/bandage.png",
  163. bRatio: false,
  164. usageMode: 'bindPhone',
  165. describe: '手机情景下使用',
  166. limitType: 'rebound', //限制回弹版本
  167. deviceType: 'mySelf', //指的是使用手机本身加速计计算
  168. deviceName: 'PHONE', //连接硬件名称
  169. }],
  170. ConnectBindingDevice: null,
  171. cIndex: -1,
  172. //当前是否连接
  173. bConnection: false,
  174. /**
  175. * 通过验证的连接,比如通过mac验证,或者说是首页直连,都设置这个参数,确保已经连上
  176. */
  177. bVerifiedConnection: false,
  178. /**
  179. * 默认不是旧设备,旧设备使用的轴向不一样,名字为 BGBox_202012 ,新设备为 BGBox_202112
  180. */
  181. bOldDeviceType: false,
  182. /**
  183. * Android 出现不匹配的情况下,判断
  184. * ios 暂时没有此类问题
  185. */
  186. bPhoneMatched: false,
  187. //最近连接过的设备
  188. finallyUseDevice: null,
  189. /**
  190. * 用户选择好友的信息
  191. */
  192. finallySelectFriendInfo: null,
  193. //phoneNumber
  194. phoneNumber: '',
  195. mailboxNumber: '',
  196. //是否是第一次设置密码,根据这个值判断.默认未设置,即设置true
  197. setPasswordFirstTime: true,
  198. openid: '',
  199. appleid: '',
  200. //获取验证码
  201. bCodeDisabled: false,
  202. count: 59,
  203. interval: null,
  204. //conversion列表
  205. oldSwiperList: [],
  206. // 计划任务过期
  207. bPlanExpired: false,
  208. // 制定玩计划任务后
  209. bPlanFinish: false,
  210. //标准体重,男女根据当前年龄计算
  211. standardWeight: 0,
  212. //是否安装了微信
  213. bInstallWechat: false,
  214. bHideWeixin: false,
  215. //导航栏高度。这里统一参数,单位px
  216. navHeight: 46,
  217. tabbarHeight: 65,
  218. systemInfo: null, //系统全部信息
  219. clientName: '', //但是客户端名字
  220. system: '', // 系统版本
  221. platform: '', // 平台
  222. appName: '',
  223. version: '1.6.3', //软件版本
  224. versionCode: '21120701', //app.vue 自动获取.目前是h5 设置给了一个默认值
  225. showEndTime: config.endTime, //游戏显示时间字段,后台返回对应此时间之前的数据
  226. //现在游戏显示在对应的平台
  227. gamePlatform: {
  228. 0: 'android',
  229. 1: 'ios',
  230. 2: 'all'
  231. },
  232. globalAcc: null,
  233. globalOri: null,
  234. globalAccData: {
  235. ax: 0,
  236. ay: 0,
  237. az: 0
  238. },
  239. globalGyroData: {
  240. gx: 0,
  241. gy: 0,
  242. gz: 0
  243. },
  244. globalLastGyroData: {
  245. gx: 0,
  246. gy: 0,
  247. gz: 0
  248. },
  249. globalMyAttitude: null,
  250. /**
  251. * 当前显示的模式下标,区分总体的显示模块
  252. * 比如拳击模块体验下,设置 0
  253. * 跳绳为主的模式体验下,设置 1
  254. */
  255. currentModeIndex: 0,
  256. //蓝牙变量操作
  257. /**
  258. * 操作蓝牙设备
  259. */
  260. bOpenBluetooth: false,
  261. /**
  262. * 是否初始化蓝牙适配器
  263. */
  264. bOpenSuccess: false,
  265. /**
  266. * 是否监听蓝牙状态变化
  267. */
  268. bListenAdapterStateChange: false,
  269. /**
  270. * 是否监听寻找新设备事件
  271. */
  272. bListenDeviceFound: false,
  273. // 设备Id
  274. BLEDeviceId: "",
  275. // 服务Id
  276. BLEServiceId: "",
  277. // 特征值id
  278. BLENotifyCharacteristicId: "",
  279. //监听rssi对象
  280. BLERSSIInterval: null,
  281. //蓝牙服务timeout
  282. getBLEDeviceServicesTimeout: null,
  283. //本地游戏地址
  284. // http://192.168.0.112:7456/build/index.html
  285. // http://127.0.0.1:7456/build/index.html
  286. LocationGameUrl: "http://110.43.54.43/t8/",
  287. //快速打击对象
  288. filter: null,
  289. deviceMs: 1,
  290. //改进版的沙袋打击对象
  291. sandbagAlgorithm: null,
  292. sandbagAlgorithmLastTime: new Date().getTime(),
  293. //记录一个沙包打击数量
  294. sandbagHitCount: 0,
  295. netSandbagHitCount: 0,
  296. /**
  297. * 蓝牙参数对象
  298. */
  299. // 设备Id
  300. deviceId: "",
  301. // 服务Id
  302. serviceId: "",
  303. notifyCharacteristicId: "",
  304. writeCharacteristicId: "",
  305. showToast: false,
  306. bListenerUpdate: false,
  307. bListenerJson: false,
  308. bListenerMac: false,
  309. bListenerAccArray: false,
  310. /**
  311. * OTA config
  312. */
  313. UUID_OTA_SERVICE: "f000ffc0-0451-4000-b000-000000000000", //OTA 服务对应的服务的 UUID
  314. UUID_IDENTFY: "f000ffc1-0451-4000-b000-000000000000", //OTA 版本特征值的UUID,读取版本就是写向这个特征值写入:0x00
  315. UUID_BLOCK: "f000ffc2-0451-4000-b000-000000000000", //OTA 写bin文件特征值UUID,发送bin文件就是写这个特征值
  316. /*****/
  317. /**
  318. * 发送16进制时候,返回的刷新数据
  319. */
  320. bListenerHexUpdate: false,
  321. BluetoothAdapter: null,
  322. //版本状态,用于区分部分特定的环境
  323. versionCodeState: {
  324. showGame: false,
  325. showVideo: false,
  326. versionCode: 0,
  327. title: 'none'
  328. },
  329. //显示蓝牙是否断开连接Modal
  330. bShowBLEConnectModal: false,
  331. bGamePlaying: false,
  332. //跳绳条件下计数
  333. bRopeKeyOne: 0,
  334. bRopeKeyTwo: 0,
  335. //钻石,金币
  336. cDiamond: 0,
  337. cGold: 0,
  338. /**
  339. * 任务相关
  340. */
  341. currentJumpTask: null,
  342. multiPersonList: [],
  343. singlePersonList: [],
  344. levels: [],
  345. /**
  346. * 校准识别部分
  347. */
  348. convertAcc: [{
  349. type: 'x',
  350. match: 'ax', //默认匹配一一对应
  351. direction: 1,
  352. }, {
  353. type: 'y',
  354. match: 'ay',
  355. direction: -1,
  356. }, {
  357. type: 'z',
  358. match: 'az',
  359. direction: -1,
  360. }],
  361. convertGyro: [{
  362. type: 'x',
  363. match: 'gx', //默认匹配一一对应
  364. direction: 1,
  365. }, {
  366. type: 'y',
  367. match: 'gy',
  368. direction: 1,
  369. }, {
  370. type: 'z',
  371. match: 'gz',
  372. direction: 1,
  373. }],
  374. /**
  375. * 签到列表
  376. */
  377. signInList: [],
  378. isSignIn: false,
  379. //读取文件的名称
  380. readDataName: "",
  381. filesList: [],
  382. //灯带灯光闪烁
  383. lightInterval: null,
  384. lightTimeout: null,
  385. showLight: '',
  386. showLightArray: [],
  387. lightCount: 0,
  388. readBLELight: '5B0E02141E141E141E00000000000000005D'
  389. },
  390. mutations: {
  391. /**
  392. * 蓝牙解析后的数据,转化成对应的坐标系方向
  393. * @param {Object} context
  394. */
  395. onConvertDeviceData(state, context) {
  396. let {
  397. data,
  398. callback = null
  399. } = context;
  400. let {
  401. acc,
  402. gyro,
  403. } = data;
  404. //根据已校准的数据转化对应的轴
  405. let outAcc = {
  406. ax: acc[state.convertAcc[0].match] * state.convertAcc[0].direction,
  407. ay: acc[state.convertAcc[1].match] * state.convertAcc[1].direction,
  408. az: acc[state.convertAcc[2].match] * state.convertAcc[2].direction
  409. };
  410. let outGyro = {
  411. gx: gyro[state.convertGyro[0].match] * state.convertGyro[0].direction,
  412. gy: gyro[state.convertGyro[1].match] * state.convertGyro[1].direction,
  413. gz: gyro[state.convertGyro[2].match] * state.convertGyro[2].direction
  414. }
  415. if (callback)
  416. callback({
  417. convertAcc: outAcc,
  418. convertGyro: outGyro
  419. });
  420. },
  421. onAccAndGyroConvertDataGet(state) {
  422. const convertAcc = uni.getStorageSync('convertAcc');
  423. if (convertAcc) {
  424. state.convertAcc = convertAcc;
  425. }
  426. const convertGyro = uni.getStorageSync('convertGyro');
  427. if (convertGyro) {
  428. state.convertGyro = convertGyro;
  429. }
  430. },
  431. onAccAndGyroConvertDataSave(state) {
  432. uni.setStorageSync('convertAcc', state.convertAcc);
  433. uni.setStorageSync('convertGyro', state.convertGyro);
  434. },
  435. onAccAndGyroConvertDataReset(state) {
  436. state.convertAcc = [{
  437. type: 'x',
  438. match: 'ax', //默认匹配一一对应
  439. direction: 1,
  440. }, {
  441. type: 'y',
  442. match: 'ay',
  443. direction: -1,
  444. }, {
  445. type: 'z',
  446. match: 'az',
  447. direction: -1,
  448. }];
  449. state.convertGyro = [{
  450. type: 'x',
  451. match: 'gx', //默认匹配一一对应
  452. direction: 1,
  453. }, {
  454. type: 'y',
  455. match: 'gy',
  456. direction: 1,
  457. }, {
  458. type: 'z',
  459. match: 'gz',
  460. direction: 1,
  461. }];
  462. //重置一下数据保存
  463. this.commit('onAccAndGyroConvertDataSave');
  464. },
  465. /**
  466. * 保存一份本地数据,加速计和陀螺仪
  467. * @param {Object} data
  468. * @param {Object} state
  469. */
  470. setOutAccAndGyroData(state, data) {
  471. uni.setStorageSync('OutAccAndGyroData', data);
  472. },
  473. getOutAccAndGyroData(state) {
  474. const value = uni.getStorageSync('OutAccAndGyroData');
  475. return value;
  476. },
  477. copyOutAccANdGyroData() {
  478. const value = uni.getStorageSync('OutAccAndGyroData');
  479. uni.setClipboardData({
  480. data: value,
  481. success: () => {
  482. uni.showToast({
  483. icon: 'none',
  484. title: '复制成功'
  485. });
  486. }
  487. });
  488. },
  489. setGuideUnlockState(state, _guideUnlockState) {
  490. uni.setStorageSync('guideUnlockState', _guideUnlockState);
  491. state.guideUnlockState = _guideUnlockState;
  492. },
  493. getGuideUnlockState(state, _guideUnlockState) {
  494. //如果存在本地任务
  495. const value = uni.getStorageSync('guideUnlockState');
  496. if (value) {
  497. state.guideUnlockState = value;
  498. }
  499. console.log('获取guideUnlockState', state.guideUnlockState)
  500. },
  501. /**
  502. * 设置当前操作的任务记录到本地
  503. * @param {Object} state
  504. * @param {Object} _taskObj
  505. */
  506. setActionJumpTask(state, _taskObj) {
  507. uni.setStorageSync('currentJumpTask', _taskObj);
  508. state.currentJumpTask = _taskObj;
  509. },
  510. //获取本地任务对象
  511. getActionJumpTask(state) {
  512. //如果存在本地任务
  513. const value = uni.getStorageSync('currentJumpTask');
  514. if (value) {
  515. state.currentJumpTask = value;
  516. }
  517. },
  518. resetActionJumpTask(state) {
  519. state.currentJumpTask = null;
  520. uni.setStorageSync('currentJumpTask', state.currentJumpTask);
  521. },
  522. setFinallSelectFriendInfo(state, friendInfo) {
  523. state.finallySelectFriendInfo = friendInfo;
  524. console.log('finallySelectFriendInfo', JSON.stringify(friendInfo));
  525. },
  526. clearFinallFriendInfo(state) {
  527. state.finallySelectFriendInfo = null;
  528. },
  529. /**
  530. * 获取记录的最后一次连接设备
  531. * @param {Object} state
  532. */
  533. getFinalUseDevice(state) {
  534. // 获取本地存储的最后一次使用的设备
  535. //1.获取最近连接的蓝牙设备, 指蓝牙搜索到的obj
  536. const value = uni.getStorageSync('finallyUseDevice');
  537. if (value) {
  538. state.finallyUseDevice = value;
  539. }
  540. console.log('获取的finallyUseDevice', value);
  541. },
  542. /**
  543. * 存储最后一次使用的设备信息,后面登陆时候,如果存在设备最后一次使用信息,则自动连接
  544. * @param {Object} state
  545. * @param {Object} device
  546. */
  547. setFinallUseDevice(state, device) {
  548. uni.setStorageSync('finallyUseDevice', device);
  549. state.finallyUseDevice = device;
  550. // console.log("保存finallyUseDevice:", state.finallyUseDevice);
  551. // uni.setStorage({
  552. // key: 'finallyUseDevice',
  553. // data: device,
  554. // success: (res) => {
  555. // state.finallyUseDevice = device;
  556. // console.log("保存finallyUseDevice:", res);
  557. // }
  558. // })
  559. },
  560. /**
  561. * 移除记录的use device
  562. */
  563. clearFinallUseDevice(state) {
  564. uni.removeStorage({
  565. key: 'finallyUseDevice',
  566. success: (res) => {
  567. state.finallyUseDevice = null;
  568. console.log("移除finallyUseDevice:", res);
  569. }
  570. })
  571. },
  572. /**
  573. * 设置运动时间
  574. * @param {Object} state
  575. * @param {Object} time
  576. */
  577. setLocalSportTime(state, time) {
  578. // let _sportTime = Number(time);
  579. state.localSportTime = Number(time);
  580. uni.setStorage({
  581. key: 'localSportTime',
  582. data: state.localSportTime,
  583. success: (res) => {
  584. // uni.showToast({
  585. // title: "保存成功"
  586. // })
  587. }
  588. })
  589. },
  590. /**
  591. * 设置卡路里
  592. * @param {Object} state
  593. * @param {Object} calorie
  594. */
  595. setLocalCalorie(state, calorie) {
  596. state.planData.localCalorie = Number(calorie);
  597. uni.setStorage({
  598. key: 'localCalorie',
  599. data: state.planData.localCalorie,
  600. success: (res) => {
  601. // uni.showToast({
  602. // title: "保存成功"
  603. // })
  604. }
  605. })
  606. },
  607. /**
  608. * 设置表盘显示的卡路里,
  609. * @param {Object} state
  610. * @param {Object} calorie
  611. */
  612. setShowCalorie(state, calorie) {
  613. state.planData.showCalorie = Number(calorie);
  614. uni.setStorage({
  615. key: 'showCalorie',
  616. data: state.planData.showCalorie,
  617. success: (res) => {
  618. // uni.showToast({
  619. // title: "保存成功"
  620. // })
  621. }
  622. })
  623. },
  624. /**
  625. * 增加卡路里
  626. * @param {Object} state
  627. * @param {Object} calorie
  628. */
  629. addlocalCalorie(state, calorie) {
  630. //卡路里不能为负数
  631. calorie = Math.abs(calorie);
  632. //当前需要添加的卡路里
  633. let temNum = Number(calorie);
  634. //本地的卡路里
  635. let temNum2 = Number(state.planData.localCalorie);
  636. // 本地加 + 传入的卡路里
  637. let _numberLocal = temNum.add(temNum2);
  638. //显示的卡路里
  639. let _showCalorie = Number(state.planData.showCalorie);
  640. //显示的卡路里加上 本地卡路里 和添加的卡路里之和要小于或等于 计划的卡路里
  641. let _allCalorie = _numberLocal.add(_showCalorie);
  642. // console.log("计算的最后卡路里_showCalorie:", _showCalorie,_allCalorie);
  643. //如果超过计划的,用计划的卡路里记录
  644. if (_allCalorie > state.planData.calorie) {
  645. let _calorie = Number(state.planData.calorie);
  646. //假如更新时候,localCalorie 值不为0,但是还未更新给服务器,此时,不能设置localCalorie 0
  647. //用传入的值,减去 allcalorie 总和和目标的差
  648. let _value = Number(_allCalorie).sub(_calorie);
  649. let _endValue = Number(_numberLocal).sub(_value);
  650. state.planData.localCalorie = Number(_endValue.toFixed(2));
  651. //如果大于或者等于的话,用计划 于 显示的卡路里 差值
  652. // state.planData.localCalorie = Number(_calorie.sub(_showCalorie).toFixed(2));
  653. // //显示最大值
  654. // state.planData.showCalorie = Number(_calorie.sub(state.planData.localCalorie).toFixed(2));
  655. } else {
  656. //
  657. state.planData.localCalorie = Number(_numberLocal.toFixed(2));
  658. // //输入的卡路里 + 自身显示的卡路里
  659. // state.planData.showCalorie = Number(temNum.add(_showCalorie).toFixed(2));
  660. }
  661. console.log("计算的最后卡路里:", state.planData);
  662. if (state.planData.localCalorie < 0) {
  663. //如果修改计划时候,本地数据计算的结果为负数,先取总和,localCalorie负再重置为0
  664. state.planData.showCalorie = _showCalorie.add(state.planData.localCalorie);
  665. state.planData.allCalorie = state.planData.showCalorie;
  666. state.planData.localCalorie = 0;
  667. } else {
  668. state.planData.allCalorie = _showCalorie.add(state.planData.localCalorie);
  669. }
  670. try {
  671. uni.setStorageSync('localCalorie', state.planData.localCalorie);
  672. } catch (e) {
  673. // error
  674. console.error(e);
  675. }
  676. try {
  677. uni.setStorageSync('showCalorie', state.planData.showCalorie);
  678. } catch (e) {
  679. // error
  680. console.error(e);
  681. }
  682. // uni.setStorage({
  683. // key: 'localCalorie',
  684. // data: state.planData.localCalorie,
  685. // success: (res) => {
  686. // // uni.showToast({
  687. // // title: "保存成功"
  688. // // })
  689. // }
  690. // })
  691. // uni.setStorage({
  692. // key: 'showCalorie',
  693. // data: state.planData.showCalorie,
  694. // success: (res) => {
  695. // // uni.showToast({
  696. // // title: "保存成功"
  697. // // })
  698. // }
  699. // })
  700. },
  701. /**
  702. * 每次登陆同步本地数据到服务器
  703. * 当天的数据更新,只更新一次
  704. * @param {Object} state
  705. */
  706. syncLocalDataToServer(state, callback) {
  707. let self = this;
  708. uni.getStorage({
  709. key: 'syncDate',
  710. success: function(res) {
  711. // console.log(res.data);
  712. let oldTime = res.data;
  713. let nDate = new Date();
  714. let newTime = date.formatDate(nDate);
  715. let days = date.datedifference(newTime, oldTime);
  716. // console.log(days);
  717. // 如果相差大于1天,
  718. if (days != 0) {
  719. // 更新存储日期
  720. uni.setStorageSync("syncDate", newTime);
  721. // 执行更新函数
  722. self.commit("syncRequestEvent", {
  723. success: () => {
  724. //清空显示的本地数据
  725. self.commit("setShowCalorie", 0);
  726. state.planData.allCalorie = state.planData.showCalorie.
  727. add(state.planData.localCalorie);
  728. if (callback)
  729. callback({
  730. newDate: nDate
  731. });
  732. }
  733. });
  734. //清空记录的本地运动时间
  735. // console.log('情况运动时间');
  736. self.commit("setLocalSportTime", 0);
  737. //设置本地数据是0
  738. state.localSportTime = 0;
  739. } else {
  740. if (callback)
  741. callback({
  742. newDate: nDate
  743. });
  744. }
  745. // date.getDays.
  746. },
  747. fail: function(res) {
  748. // console.error(res);
  749. // 如果没有日期,则存储一个新的
  750. let nDate = new Date();
  751. let tempTime = date.formatDate(nDate);
  752. uni.setStorageSync("syncDate", tempTime);
  753. if (callback)
  754. callback({
  755. newDate: nDate
  756. });
  757. }
  758. });
  759. },
  760. // 同步数据的请求
  761. syncRequestEvent(state, data) {
  762. let self = this;
  763. let {
  764. success,
  765. fail
  766. } = data;
  767. //需要卡路里取整存服务器,小数点后面,继续保留。以消除累计误差
  768. let oldLocalCalorie = state.planData.localCalorie;
  769. let _localCalorieInt = parseInt(state.planData.localCalorie);
  770. //小数点后面
  771. let _afterLocalCalorie = Number(oldLocalCalorie).sub(_localCalorieInt);
  772. console.log("*******===:", oldLocalCalorie, _localCalorieInt, _afterLocalCalorie);
  773. if (_localCalorieInt === 0) {
  774. // uni.showToast({
  775. // title: '',
  776. // icon: 'loading',
  777. // mask: true,
  778. // duration: 1000
  779. // })
  780. if (success)
  781. success();
  782. return;
  783. }
  784. uni.showToast({
  785. title: '',
  786. icon: 'loading',
  787. mask: false,
  788. duration: 10000
  789. })
  790. //把卡路里累计到cumulativeCalorie 变量,之后传服务器 += Math.round(state.planData.localCalorie)
  791. state.planData.cumulativeCalorie += _localCalorieInt;
  792. //添加到showCalorie 中
  793. state.planData.showCalorie = Number(state.planData.showCalorie).add(_localCalorieInt);
  794. state.planData.allCalorie = state.planData.showCalorie.add(_afterLocalCalorie);
  795. //不管是否同步成功,清空本地记录的卡路里,前一步已添加到cumulativeCalorie
  796. self.commit("setLocalCalorie", _afterLocalCalorie);
  797. self.commit("setShowCalorie", Number(state.planData.showCalorie));
  798. // 把卡路里记录到服务器
  799. reqUtil.requestData(config.URL.FITNESSPROGRAM, state.planData, 'POST').then(
  800. res => {
  801. // console.warn(res);
  802. if (res.code == 0) {
  803. uni.showToast({
  804. title: '同步成功',
  805. mask: true,
  806. duration: 1000
  807. });
  808. //同步一下服务器的返回值
  809. state.planData = Object.assign(state.planData, res.data);
  810. //暂时默认同步拳击1 的卡路里
  811. reqUtil.requestData(config.URL.UPLOADRANKING, {
  812. gameId: '1', //拳击模式 game id = 1;
  813. score: _localCalorieInt,
  814. cityCode: state.city.cityCode,
  815. }, "POST").then(res => {
  816. console.warn('****上传首页拳击卡路里,后面多个模式,可能需要多个不同的游戏id ***', res);
  817. },
  818. e => {
  819. console.log(e)
  820. });
  821. setTimeout(() => {
  822. uni.hideToast();
  823. }, 1000);
  824. if (success)
  825. success();
  826. } else {
  827. state.planData.cumulativeCalorie = Number(state.planData.cumulativeCalorie).sub(
  828. _localCalorieInt);
  829. state.planData.showCalorie = Number(state.planData.showCalorie).sub(
  830. _localCalorieInt);
  831. self.commit("setLocalCalorie", oldLocalCalorie);
  832. if (fail)
  833. fail();
  834. }
  835. console.log("减法 ==", Number(state.planData.cumulativeCalorie).sub(_localCalorieInt));
  836. },
  837. e => {
  838. console.log(e);
  839. state.planData.cumulativeCalorie = Number(state.planData.cumulativeCalorie).sub(
  840. _localCalorieInt);
  841. state.planData.showCalorie = Number(state.planData.showCalorie).sub(_localCalorieInt);
  842. self.commit("setLocalCalorie", oldLocalCalorie);
  843. uni.hideToast();
  844. if (fail)
  845. fail();
  846. }
  847. );
  848. },
  849. //登录成功后,重置一下状态
  850. resetCountDown(state) {
  851. if (state.interval) {
  852. clearInterval(state.interval);
  853. state.interval = null;
  854. state.count = 59;
  855. state.bCodeDisabled = false;
  856. }
  857. },
  858. /**
  859. * 验证码操作 区分手机号和邮箱
  860. * @param {Object} state
  861. * @param {Object} context
  862. */
  863. countDown(state, context) {
  864. let {
  865. account,
  866. type
  867. } = context;
  868. //限制验证码操作
  869. state.bCodeDisabled = true;
  870. state.interval = setInterval(() => {
  871. --state.count;
  872. if (state.count <= 0) {
  873. clearInterval(state.interval);
  874. state.interval = null;
  875. state.count = 59;
  876. state.bCodeDisabled = false;
  877. }
  878. }, 1000);
  879. setTimeout(() => {
  880. clearInterval(state.interval)
  881. state.count = 59;
  882. state.bCodeDisabled = false;
  883. }, 60000);
  884. //GETCODE "phoneNumber": phoneNumber; GETCODEACCORDINGTYPE
  885. reqUtil.requestData(config.URL.GETCODEACCORDINGTYPE, {
  886. account,
  887. type
  888. }).then(res => {
  889. console.log('requestData GETCODE =====', res);
  890. uni.showToast({
  891. title: "发送成功",
  892. mask: true,
  893. duration: 1000
  894. })
  895. },
  896. e => {
  897. console.log(e)
  898. });
  899. },
  900. //获取记录的蓝牙列表数据
  901. getBLEDeviceList(state) {
  902. // console.log("getBLEDeviceList=");
  903. uni.getStorage({
  904. key: 'BLEDeviceList',
  905. success: (res) => {
  906. // console.log("*****getBLEDeviceList=", res);
  907. let _list = res.data;
  908. state.BLEDeviceList = res.data;
  909. //更新BLEDeviceShowList 数组
  910. state.BLEDeviceShowList = [];
  911. _list.forEach(item => {
  912. //如果记录到本地的id,和信息列表中的id一致,则结合
  913. for (let i = 0; i < state.BLEInfoList.length; i++) {
  914. let eq = state.BLEInfoList[i];
  915. if (item.id == eq.id) {
  916. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  917. break;
  918. }
  919. }
  920. })
  921. }
  922. })
  923. },
  924. //添加蓝牙设备数据
  925. addBLEDevice(state, data) {
  926. let devicelist = [];
  927. if (state.BLEDeviceList && state.BLEDeviceList.length != 0) {
  928. devicelist = state.BLEDeviceList;
  929. }
  930. // console.log(data, devicelist)
  931. let bHas = false;
  932. devicelist.forEach((item, index, selfArr) => {
  933. if (item.id == data.id) {
  934. //如果存在,更新保存的数据,比如 mac或者uuid等
  935. selfArr[index] = item = Object.assign({}, item, data);
  936. bHas = true;
  937. }
  938. })
  939. //把当前添加的的蓝牙设信息备作为最后一次连接覆盖到本地
  940. this.commit('setFinallUseDevice', data);
  941. if (!bHas) {
  942. //如果不是更新数据,就添加但却数据到列表
  943. devicelist.push(data);
  944. }
  945. uni.setStorage({
  946. key: 'BLEDeviceList',
  947. data: devicelist,
  948. success: (res) => {
  949. // uni.showToast({
  950. // title: "保存成功"
  951. // })
  952. state.BLEDeviceList = devicelist;
  953. // console.log("devicelist:",devicelist);
  954. //更新BLEDeviceShowList 数组
  955. state.BLEDeviceShowList = [];
  956. devicelist.forEach(item => {
  957. //如果记录到本地的id,和信息列表中的id一致,则结合
  958. for (let i = 0; i < state.BLEInfoList.length; i++) {
  959. let eq = state.BLEInfoList[i];
  960. if (item.id == eq.id) {
  961. // console.log("存储的======================:", item, eq);
  962. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  963. break;
  964. }
  965. }
  966. })
  967. // console.log("state.BLEDeviceShowList:",state.BLEDeviceShowList);
  968. }
  969. })
  970. },
  971. //删除蓝牙设备数据
  972. deleteBLEDevice(state, index) {
  973. let devicelist = [];
  974. devicelist = state.BLEDeviceList;
  975. devicelist.splice(index, 1);
  976. uni.setStorage({
  977. key: 'BLEDeviceList',
  978. data: devicelist,
  979. success: (res) => {
  980. uni.showToast({
  981. title: "删除成功"
  982. })
  983. state.BLEDeviceList = devicelist;
  984. //更新BLEDeviceShowList 数组
  985. state.BLEDeviceShowList = [];
  986. devicelist.forEach(item => {
  987. //如果记录到本地的id,和信息列表中的id一致,则结合
  988. for (let i = 0; i < state.BLEInfoList.length; i++) {
  989. let eq = state.BLEInfoList[i];
  990. if (item.id == eq.id) {
  991. state.BLEDeviceShowList.push(Object.assign({}, item, eq));
  992. break;
  993. }
  994. }
  995. })
  996. }
  997. })
  998. },
  999. //获取计划表数据
  1000. getPlanData(state, callback) {
  1001. reqUtil.requestData(config.URL.FITNESSPROGRAMGET).then(res => {
  1002. // console.log('获取计划表数据:getPlanData=====', res.data);
  1003. if (res.code == 0) {
  1004. state.planData = Object.assign(state.planData, res.data);
  1005. // 处理本地数据
  1006. let templocalCalorie = uni.getStorageSync("localCalorie");
  1007. // console.log("templocalCalorie:", templocalCalorie, state.planData);
  1008. if (templocalCalorie) {
  1009. templocalCalorie = Number(templocalCalorie);
  1010. if (templocalCalorie > state.planData.calorie) {
  1011. state.planData.localCalorie = state.planData.calorie;
  1012. uni.setStorage({
  1013. key: "localCalorie",
  1014. data: state.planData.localCalorie
  1015. });
  1016. } else {
  1017. state.planData.localCalorie = templocalCalorie;
  1018. }
  1019. } else {
  1020. state.planData.localCalorie = 0;
  1021. }
  1022. //处理本地的cumulativeCalorie
  1023. let tempShowCalorie = uni.getStorageSync("showCalorie");
  1024. // console.log("tempShowCalorie:", tempShowCalorie, state.planData);
  1025. if (tempShowCalorie) {
  1026. tempShowCalorie = Number(tempShowCalorie);
  1027. if (tempShowCalorie > state.planData.calorie) {
  1028. state.planData.showCalorie = state.planData.calorie;
  1029. uni.setStorage({
  1030. key: "showCalorie",
  1031. data: state.planData.showCalorie
  1032. });
  1033. } else {
  1034. state.planData.showCalorie = tempShowCalorie;
  1035. }
  1036. } else {
  1037. state.planData.showCalorie = 0;
  1038. }
  1039. state.planData.allCalorie = state.planData.showCalorie.add(state.planData
  1040. .localCalorie);
  1041. // console.log("======",state.planData )
  1042. state.days = date.datedifference(res.data.startTime, res.data.endTime) + 1;
  1043. let nDate = new Date();
  1044. let tempTime = date.formatDate(nDate);
  1045. state.remainingDays = date.datedifference(tempTime, res.data.endTime) + 1;
  1046. console.log("state.remainingDays======", tempTime, res.data.endTime, state
  1047. .remainingDays);
  1048. }
  1049. // showArcbar
  1050. if (callback) {
  1051. callback();
  1052. }
  1053. },
  1054. e => {
  1055. console.log(e)
  1056. });
  1057. },
  1058. /**
  1059. * 获取全部游戏
  1060. * @param {Object} state
  1061. */
  1062. getAllGame(state, callback) {
  1063. //获得全部游戏列表
  1064. if (state.allGames.length != 0) {
  1065. if (callback)
  1066. callback();
  1067. return;
  1068. }
  1069. reqUtil.requestData(
  1070. config.URL.GAMELIST_BY_RANKING_SHOW_AND_PLATFORM, {
  1071. rankingShow: 1,
  1072. page: 1,
  1073. size: 100
  1074. }
  1075. ).then(res => {
  1076. // console.log('获取默认的全部游戏 =====', res);
  1077. if (res.code == 0) {
  1078. state.allGames = [];
  1079. state.allGames = state.allGames.concat(res.data);
  1080. }
  1081. if (callback)
  1082. callback();
  1083. },
  1084. e => {
  1085. console.log(e);
  1086. if (callback)
  1087. callback();
  1088. }
  1089. );
  1090. },
  1091. getRankGame(state, data) {
  1092. let {
  1093. param,
  1094. callback
  1095. } = data;
  1096. reqUtil.requestData(config.URL.GETRANKRANGR, param).then(res => {
  1097. console.log('获取默认的游戏数据:GETRANKRANGR=====', res);
  1098. if (res.data != null) {
  1099. state.rankSelectedGame = res.data.gameInfo;
  1100. state.rankInfo = res.data.rankInfo;
  1101. //然后获取排名
  1102. }
  1103. if (callback)
  1104. callback(res);
  1105. },
  1106. e => {
  1107. console.log(e)
  1108. });
  1109. },
  1110. /**
  1111. * 苹果端登陆
  1112. * @param {Object} state
  1113. * @param {Object} data
  1114. */
  1115. appleUserInfoLogin(state, data) {
  1116. let self = this;
  1117. let {
  1118. params,
  1119. callback
  1120. } = data;
  1121. console.log('获取用户数据:USERINFOAPPLEADD params=====', params);
  1122. reqUtil.requestData(config.URL.USERINFOAPPLEADD, params, 'POST').then(res => {
  1123. console.log('获取用户数据:USERINFOAPPLEADD =====', res);
  1124. if (res.code == 0) {
  1125. let userInfo = res.data;
  1126. self.commit('login', userInfo);
  1127. console.log("11~~");
  1128. } else if (res.code = 201) {
  1129. state.hasLogin = true;
  1130. }
  1131. console.log("apple callback!!!");
  1132. callback();
  1133. },
  1134. e => {
  1135. console.log(e)
  1136. });
  1137. },
  1138. //添加用户信息和登录
  1139. addUserAvatarAndLogin(state, data) {
  1140. let self = this;
  1141. let {
  1142. params,
  1143. filePath,
  1144. callback
  1145. } = data;
  1146. console.log("addUserAvatarAndLogin 初始化对应数据");
  1147. reqUtil.reqUpload(config.URL.USERINFOADDAVATARINFO, params, filePath).then(res => {
  1148. console.log('获取用户数据:USERINFOADDAVATARINFO =====', res);
  1149. if (res.code == 0) {
  1150. let userInfo = res.data;
  1151. self.commit('login', userInfo);
  1152. } else if (res.code = 201) {
  1153. state.hasLogin = true;
  1154. }
  1155. if (callback) {
  1156. callback();
  1157. }
  1158. },
  1159. e => {
  1160. console.log(e)
  1161. });
  1162. },
  1163. //app登录或h5
  1164. accountLogin(state, callback) {
  1165. let self = this;
  1166. // console.log("app登录或h5 初始化对应数据")
  1167. reqUtil.requestData(config.URL.USERINFOURL).then(res => {
  1168. console.warn('获取用户数据:USERINFOURL =====', res);
  1169. if (res.code == 0) {
  1170. let userInfo = res.data.userInfo;
  1171. state.phoneNumber = res.data.phoneNumber || '';
  1172. state.mailboxNumber = res.data.mailboxNumber || '';
  1173. state.setPasswordFirstTime = res.data.setPasswordFirstTime;
  1174. state.openid = res.data.openid || '';
  1175. self.commit('login', userInfo);
  1176. } else if (res.code = 201) {
  1177. state.hasLogin = true;
  1178. //新用户重置一下新手教程数据
  1179. self.commit('setGuideUnlockState', {
  1180. //是否首次安装
  1181. firstInstallation: true, //是否首次安装
  1182. firstDisconnectBluetooth: true, //是否首次连接蓝牙
  1183. firstUnlockJumpUp: true, //是否首次向上跳
  1184. firstUnlockLeftAndRightJump: true, //是否首次左右跳
  1185. firstUnlockLeftAndRightRotationJump: true,
  1186. firstPromptSelectLevel: true //是否首次提示选择关卡
  1187. });
  1188. }
  1189. if (callback) {
  1190. callback();
  1191. }
  1192. },
  1193. e => {
  1194. console.log(e)
  1195. });
  1196. },
  1197. //小程序页面登录
  1198. login(state, userInfo) {
  1199. console.log("登陆的信息==", userInfo);
  1200. if (userInfo.cityCode == "" || userInfo.cityCode == null) {
  1201. //不存在就设置默认值
  1202. userInfo.cityCode = state.city.cityCode;
  1203. }
  1204. let cityCode = userInfo.cityCode;
  1205. // console.log("cicicicitycode:", cityCode);
  1206. let provinceData = require('@/components/slambb-picker/city-data/province.js').default;
  1207. let cityData = require('@/components/slambb-picker/city-data/city.js').default;
  1208. let areaData = require('@/components/slambb-picker/city-data/area.js').default;
  1209. // 解析citycode
  1210. for (let i = 0; i < provinceData.length; i++) {
  1211. if (provinceData[i].value == cityCode.substr(0, 2)) {
  1212. let currentCityData = cityData[i];
  1213. for (let j = 0; j < currentCityData.length; j++) {
  1214. if (currentCityData[j].value == cityCode.substr(0, 4)) {
  1215. let areaDataTemp = areaData[i][j];
  1216. for (let k = 0; k < areaDataTemp.length; k++) {
  1217. if (areaDataTemp[k].value == cityCode) {
  1218. state.city.value = [i, j, k];
  1219. state.city.label = provinceData[i].label +
  1220. '-' +
  1221. currentCityData[j].label +
  1222. '-' +
  1223. areaDataTemp[k].label;
  1224. state.cityName = currentCityData[j].label;
  1225. break;
  1226. }
  1227. }
  1228. break;
  1229. }
  1230. }
  1231. break;
  1232. }
  1233. }
  1234. state.userInfo = userInfo;
  1235. state.userName = userInfo.username || '新用户';
  1236. state.avatarUrl = userInfo.avatarUrl || '/static/defaultAvatar.png';
  1237. state.gender = userInfo.gender;
  1238. state.signature = userInfo.signature || '';
  1239. state.birthday = userInfo.birthday;
  1240. state.city.cityCode = cityCode.toString();
  1241. state.weight = userInfo.weight || state.weight;
  1242. state.height = userInfo.height || state.height;
  1243. state.hasLogin = true;
  1244. //登录时候 获取一下排行榜里面的游戏
  1245. // this.commit('getRankGame', {
  1246. // param: {
  1247. // type: "china",
  1248. // cityCode: 12345
  1249. // }
  1250. // });
  1251. //登录之后,进入此页面先设置平台参数
  1252. if (state.platform == "ios") {
  1253. uni.setStorageSync("platform", 1);
  1254. } else if (state.platform == "android") {
  1255. uni.setStorageSync("platform", 0);
  1256. }
  1257. //获取版本信息
  1258. this.commit('getVersionCode');
  1259. },
  1260. // 退出登录
  1261. // 删除token 操作
  1262. delectToken(state, data) {
  1263. let self = this;
  1264. let {
  1265. success
  1266. } = data;
  1267. reqUtil.requestData(config.URL.USERLOGINOUT, {}).then(res => {
  1268. console.log('USERLOGINOUT=====', res);
  1269. self.commit("logout");
  1270. try {
  1271. //清空保存的storage
  1272. uni.clearStorageSync();
  1273. } catch (e) {
  1274. // error
  1275. console.error(e);
  1276. }
  1277. if (state.BLERSSIInterval) {
  1278. clearInterval(state.BLERSSIInterval);
  1279. state.BLERSSIInterval = null;
  1280. }
  1281. if (state.BLEConnectDevice) {
  1282. self.commit("onCloseBLEConnection", {
  1283. getSuccess: () => {}
  1284. });
  1285. }
  1286. if (success) {
  1287. success(res);
  1288. }
  1289. },
  1290. e => {
  1291. console.log(e)
  1292. });
  1293. },
  1294. logout(state) {
  1295. state.userInfo = null;
  1296. state.userName = "匿名";
  1297. state.avatarUrl = '/static/defaultAvatar.png';
  1298. state.days = '0';
  1299. state.signature = '';
  1300. state.gender = 0;
  1301. state.hasLogin = false;
  1302. state.phoneNumber = '';
  1303. state.mailboxNumber = '';
  1304. state.openid = '';
  1305. state.appleid = '';
  1306. //处理设备值
  1307. state.cIndex = -1;
  1308. //绑定的设备
  1309. state.ConnectBindingDevice = null;
  1310. //蓝牙设备
  1311. state.BLEConnectDevice = null;
  1312. //蓝牙服务
  1313. state.BLEGetServices = null;
  1314. //最近连接过的设备
  1315. state.finallyUseDevice = null;
  1316. //最近选择的好友
  1317. state.finallySelectFriendInfo = null;
  1318. //记录的蓝牙设备,保存id, 和对应的蓝牙连接数据
  1319. state.BLEDeviceList = [];
  1320. //显示的蓝牙设备,取本地数据时候更新
  1321. state.BLEDeviceShowList = [];
  1322. //记录表盘计划刷新的卡路里
  1323. state.oldArcbarProCalorie = 0;
  1324. //记录表盘当前的总卡路里
  1325. state.oldArcbarAllCalorie = 0;
  1326. //任务相关
  1327. state.currentJumpTask = null;
  1328. },
  1329. loginUserInfo(state, data) {
  1330. let {
  1331. infoRes,
  1332. success,
  1333. fail
  1334. } = data;
  1335. console.log('loginUserInfo');
  1336. reqUtil.requestData(config.URL.WXGETUSERINFO, {
  1337. appid: 'wxd6dfd60729d33d17',
  1338. encryptedData: infoRes.encryptedData,
  1339. iv: infoRes.iv,
  1340. signature: infoRes.signature,
  1341. rawData: infoRes.rawData
  1342. }).then(res => {
  1343. console.log('wxInfoRes=====', res);
  1344. let userInfo = res.data;
  1345. this.commit('login', userInfo);
  1346. if (success) {
  1347. success(res);
  1348. }
  1349. },
  1350. e => {
  1351. console.log(e)
  1352. if (fail) {
  1353. success(fail);
  1354. }
  1355. });
  1356. },
  1357. //这里统一静默处理login
  1358. oauth(state, context) {
  1359. let {
  1360. value,
  1361. callback
  1362. } = context;
  1363. uni.login({
  1364. provider: value,
  1365. success: (res) => {
  1366. // console.log('code:', res);
  1367. reqUtil.requestData(config.URL.USERlOGINURL, {
  1368. appid: 'wxd6dfd60729d33d17',
  1369. code: res.code,
  1370. platfrom: value
  1371. }).then(res => {
  1372. console.log('login token=====', res);
  1373. state.token = res.data.token;
  1374. uni.setStorageSync('token', state.token);
  1375. uni.getUserInfo({
  1376. provider: value,
  1377. success: (infoRes) => {
  1378. if (callback) {
  1379. callback(infoRes);
  1380. }
  1381. },
  1382. fail: (failRes) => {
  1383. //假如没有授权,login 之后,不做处理,需要用户点击授权时候,再进行处理用户登录
  1384. console.log('getUserInfo failRes:', failRes)
  1385. }
  1386. });
  1387. },
  1388. e => {
  1389. console.log(e)
  1390. });
  1391. },
  1392. fail: (err) => {
  1393. console.error('授权登录失败:' + JSON.stringify(err));
  1394. }
  1395. });
  1396. },
  1397. onLuanchLogin(state, data) {
  1398. let {
  1399. success
  1400. } = data;
  1401. const filters = ['weixin', 'qq', 'sinaweibo'];
  1402. let platform = '';
  1403. uni.getProvider({
  1404. service: 'oauth',
  1405. success: (res) => {
  1406. if (res.provider && res.provider.length) {
  1407. for (let i = 0; i < res.provider.length; i++) {
  1408. if (~filters.indexOf(res.provider[i])) {
  1409. platform = res.provider[i];
  1410. console.log("platform=", platform);
  1411. uni.showToast({
  1412. icon: 'loading',
  1413. title: ''
  1414. })
  1415. this.commit('oauth', {
  1416. value: platform,
  1417. callback: (infoRes) => {
  1418. // console.log("infoRes:", infoRes);
  1419. this.commit('loginUserInfo', {
  1420. infoRes: infoRes,
  1421. success: (res) => {
  1422. console.log("获取用户成功");
  1423. if (success) {
  1424. success(res);
  1425. }
  1426. uni.hideToast();
  1427. },
  1428. fail: (res) => {
  1429. console.error("获取用户失败");
  1430. uni.hideToast();
  1431. }
  1432. });
  1433. }
  1434. })
  1435. }
  1436. }
  1437. this.hasProvider = true;
  1438. }
  1439. },
  1440. fail: (err) => {
  1441. console.error('获取服务供应商失败:' + JSON.stringify(err));
  1442. }
  1443. });
  1444. },
  1445. initAdapter(state, callback) {
  1446. //初始化蓝牙模块
  1447. let params = {
  1448. success: (res) => {
  1449. state.bOpenSuccess = true;
  1450. state.bOpenBluetooth = true;
  1451. if (callback)
  1452. callback(res);
  1453. //监听断开事件
  1454. this.commit("B_OnBLEConnectionStateChange");
  1455. },
  1456. fail: (fail) => {
  1457. state.bOpenSuccess = false;
  1458. state.bOpenBluetooth = false;
  1459. uni.showToast({
  1460. title: '蓝牙尚未开启!',
  1461. icon: 'none'
  1462. })
  1463. },
  1464. complete: (complete) => {
  1465. // console.log("complete bListenAdapterStateChange:", state.bListenAdapterStateChange);
  1466. if (state.bListenAdapterStateChange) return;
  1467. state.bListenAdapterStateChange = true;
  1468. uni.onBluetoothAdapterStateChange((res) => {
  1469. // console.log('adapterState changed, now is', res)
  1470. // 手机蓝牙状态
  1471. state.bOpenBluetooth = res.available;
  1472. if (state.bOpenBluetooth && !state.bOpenSuccess) {
  1473. this.commit('initAdapter');
  1474. }
  1475. })
  1476. }
  1477. };
  1478. this.commit("B_OpenBluetoothAdapter", params);
  1479. },
  1480. // todo 未使用到
  1481. onGetDevices(state, context) {
  1482. let {
  1483. success
  1484. } = context;
  1485. if (!state.BLEConnectDevice) return;
  1486. // #ifdef APP-PLUS
  1487. let deviceId = state.BLEConnectDevice.deviceId;
  1488. uni.getBLEDeviceRSSI({
  1489. deviceId,
  1490. success: res => {
  1491. let _dis = Math.pow(Math.E, (Math.abs(res.RSSI) - 66.78) / 16.56);
  1492. if (_dis > state.BLEConnectDevice.limitDis) {
  1493. if (state.cIndex != -1) {
  1494. uni.showToast({
  1495. title: '设备断开连接!',
  1496. icon: 'none',
  1497. duration: 2000,
  1498. mask: true
  1499. })
  1500. }
  1501. setTimeout(() => {
  1502. this.commit("B_CloseBLEConnection", {
  1503. deviceId: deviceId
  1504. })
  1505. state.cIndex = -1;
  1506. state.bConnection = false;
  1507. state.bVerifiedConnection = false;
  1508. }, 1000)
  1509. } else {
  1510. // console.log("DIS~~~~~~~~~", _dis);
  1511. if (success) {
  1512. success({
  1513. RSSI: res.RSSI,
  1514. DIS: _dis
  1515. });
  1516. }
  1517. }
  1518. }
  1519. })
  1520. // #endif
  1521. },
  1522. //清除连接的开启的timeout
  1523. onUnloadCreateBLEConnectionTimeout(state) {
  1524. if (state.getBLEDeviceServicesTimeout) {
  1525. clearTimeout(state.getBLEDeviceServicesTimeout);
  1526. state.getBLEDeviceServicesTimeout = null;
  1527. }
  1528. },
  1529. initBLEData(state) {
  1530. // 设备Id
  1531. state.deviceId = "";
  1532. // 服务Id
  1533. state.serviceId = "";
  1534. state.notifyCharacteristicId = "";
  1535. state.writeCharacteristicId = "";
  1536. state.currentInstruction = "";
  1537. state.showToast = false;
  1538. state.bListenerUpdate = false;
  1539. state.bListenerJson = false;
  1540. state.bListenerMac = false;
  1541. state.bListenerAccArray = false;
  1542. //更新二进制的
  1543. state.bListenerHexUpdate = false;
  1544. },
  1545. //连接蓝牙
  1546. onCreateBLEConnection(state, context) {
  1547. let {
  1548. index,
  1549. item,
  1550. initItem = false,
  1551. getSuccess = null,
  1552. getinitAdapter = null
  1553. } = context;
  1554. uni.showToast({
  1555. title: '连接设备中...',
  1556. icon: 'loading',
  1557. duration: 10000,
  1558. mask: true
  1559. })
  1560. let params = {
  1561. item: item,
  1562. success: (success) => {
  1563. state.bConnection = true;
  1564. if (state.getBLEDeviceServicesTimeout) {
  1565. clearTimeout(state.getBLEDeviceServicesTimeout);
  1566. state.getBLEDeviceServicesTimeout = null;
  1567. }
  1568. state.getBLEDeviceServicesTimeout = setTimeout(() => {
  1569. let retryCount = 5;
  1570. this.commit("B_GetBLEDeviceServices", {
  1571. retryCount: retryCount,
  1572. item: item,
  1573. callback: () => {
  1574. uni.showToast({
  1575. title: '连接成功',
  1576. icon: 'loading',
  1577. duration: 2000,
  1578. mask: true
  1579. })
  1580. //是否需要设置item,默认不设置
  1581. if (initItem) {
  1582. state.cIndex = index;
  1583. state.BLEConnectDevice = item;
  1584. }
  1585. if (getSuccess)
  1586. getSuccess();
  1587. /**
  1588. * 直接连接过成功
  1589. */
  1590. state.bVerifiedConnection = true;
  1591. },
  1592. getServiceList: (serviceList) => {
  1593. //搜索服务失败后
  1594. state.BLEGetServices = serviceList;
  1595. },
  1596. getFail: () => {
  1597. this.commit("B_CloseBLEConnection", {
  1598. deviceId: item.deviceId
  1599. })
  1600. // state.cIndex = -1;
  1601. // state.bConnection = false;
  1602. // state.bVerifiedConnection = false;
  1603. this.commit("onResetBLEConnection");
  1604. }
  1605. });
  1606. }, 2000);
  1607. },
  1608. fail: (fail) => {
  1609. console.log("***fail:", fail);
  1610. if (fail.errCode === 10012) {
  1611. console.log("连接超时,请重试!");
  1612. uni.showToast({
  1613. title: '连接失败,开启设备后尝试重新连接!',
  1614. icon: 'none',
  1615. duration: 3000,
  1616. mask: true
  1617. })
  1618. } else if (fail.errCode === 10013) {
  1619. console.log("连接失败,蓝牙地址无效!");
  1620. uni.showToast({
  1621. title: '连接失败,蓝牙地址无效',
  1622. icon: 'none',
  1623. duration: 2000,
  1624. mask: true
  1625. })
  1626. } else if (fail.errCode === 10000) {
  1627. this.commit('initAdapter', () => {
  1628. if (getinitAdapter) {
  1629. getinitAdapter();
  1630. }
  1631. })
  1632. } else {
  1633. // err.errCode10003原因多种:蓝牙设备未开启或异常导致无法连接;蓝牙设备被占用或者上次蓝牙连接未断开导致无法连接
  1634. console.log("连接失败,请重试!", state.BLEConnectDevice);
  1635. uni.showToast({
  1636. title: '请尝试开启设备和重启app。',
  1637. icon: 'none',
  1638. duration: 2000,
  1639. mask: true
  1640. })
  1641. }
  1642. }
  1643. };
  1644. this.commit("B_CreateBLEConnection", params);
  1645. },
  1646. //devices hardware 连接后验证,这里不需要处理 bVerifiedConnection,通过mac 验证后处理
  1647. onCreateBLESuccess(state, context) {
  1648. let {
  1649. item,
  1650. getSuccess = null
  1651. } = context;
  1652. this.commit("B_CreateBLEConnection", {
  1653. item: item,
  1654. success: success => {
  1655. state.BLEConnectDevice = item;
  1656. state.bConnection = true;
  1657. if (getSuccess) {
  1658. getSuccess();
  1659. }
  1660. },
  1661. fail: fail => {
  1662. if (fail.errCode === 10012) {
  1663. console.log("连接超时,请重试!");
  1664. uni.showToast({
  1665. title: '连接超时,检查对应设备是否开启?',
  1666. icon: 'none',
  1667. duration: 2000,
  1668. mask: true
  1669. })
  1670. } else if (fail.errCode === 10013) {
  1671. console.log("连接失败,蓝牙地址无效!");
  1672. uni.showToast({
  1673. title: '蓝牙地址无效,检查设备是否正常?',
  1674. icon: 'none',
  1675. duration: 2000,
  1676. mask: true
  1677. })
  1678. } else if (fail.errCode === 10000) {
  1679. console.log("连接失败,初始化 wx.openBluetoothAdapter 调用之后使用");
  1680. uni.showToast({
  1681. title: '连接失败,检查手机蓝牙是否开启?',
  1682. icon: 'none',
  1683. duration: 2000,
  1684. mask: true
  1685. })
  1686. } else {
  1687. console.log("连接失败,请重试!");
  1688. uni.showModal({
  1689. title: '连接失败',
  1690. content: '设备未开启或被占用。请重启app和设备后重新连接。'
  1691. })
  1692. // uni.showToast({
  1693. // title: '设备未开启或被占用异常导致无法连接。',
  1694. // icon: 'none',
  1695. // duration: 2000,
  1696. // mask: true
  1697. // })
  1698. }
  1699. }
  1700. });
  1701. },
  1702. //获取蓝牙服务
  1703. onGetBLEDeviceServices(state, context) {
  1704. let {
  1705. item,
  1706. success = null,
  1707. } = context;
  1708. let retryCount = 5;
  1709. this.commit("B_GetBLEDeviceServices", {
  1710. retryCount: retryCount,
  1711. item: item,
  1712. callback: success,
  1713. getServiceList: (serviceList) => {
  1714. state.BLEGetServices = serviceList;
  1715. },
  1716. getFail: () => {
  1717. this.commit("B_CloseBLEConnection", {
  1718. deviceId: item.deviceId
  1719. })
  1720. this.commit("onResetBLEConnection");
  1721. }
  1722. })
  1723. },
  1724. //重置蓝牙连接参数
  1725. onResetBLEConnection(state) {
  1726. state.cIndex = -1;
  1727. state.BLEConnectDevice = null;
  1728. //蓝牙服务
  1729. state.BLEGetServices = null;
  1730. state.bConnection = false;
  1731. state.bVerifiedConnection = false;
  1732. },
  1733. onCloseBLEConnection(state, context) {
  1734. console.log("onCloseBLEConnection", state.BLEConnectDevice);
  1735. let {
  1736. getSuccess = null,
  1737. } = context;
  1738. if (state.BLERSSIInterval) {
  1739. clearInterval(state.BLERSSIInterval);
  1740. state.BLERSSIInterval = null;
  1741. }
  1742. this.commit("B_CloseBLEConnection", {
  1743. deviceId: state.BLEConnectDevice.deviceId,
  1744. success: () => {
  1745. state.cIndex = -1;
  1746. state.BLEConnectDevice = null;
  1747. //蓝牙服务
  1748. state.BLEGetServices = null;
  1749. if (getSuccess) {
  1750. getSuccess();
  1751. }
  1752. state.bConnection = false;
  1753. state.bVerifiedConnection = false;
  1754. uni.closeBluetoothAdapter({
  1755. success(res) {
  1756. console.log(res)
  1757. state.bOpenBluetooth = false;
  1758. }
  1759. })
  1760. }
  1761. });
  1762. },
  1763. //不关闭 adapter
  1764. onOnlyCloseBLEConnection(state, context) {
  1765. let {
  1766. getSuccess = null
  1767. } = context;
  1768. if (state.BLERSSIInterval) {
  1769. clearInterval(state.BLERSSIInterval);
  1770. state.BLERSSIInterval = null;
  1771. }
  1772. this.commit("B_CloseBLEConnection", {
  1773. deviceId: state.BLEConnectDevice.deviceId,
  1774. success: () => {
  1775. state.cIndex = -1;
  1776. state.BLEConnectDevice = null;
  1777. //蓝牙服务
  1778. state.BLEGetServices = null;
  1779. if (getSuccess) {
  1780. getSuccess();
  1781. }
  1782. state.bConnection = false;
  1783. state.bVerifiedConnection = false;
  1784. }
  1785. });
  1786. },
  1787. onWriteBLEConnectionValue(state, context) {
  1788. //#ifdef H5
  1789. console.warn("h5不支持蓝牙:");
  1790. return;
  1791. //#endif
  1792. let {
  1793. getSuccess = null,
  1794. getFail = null,
  1795. value,
  1796. bSendHex = false,
  1797. bOpen = false,
  1798. } = context;
  1799. if (!state.BLEConnectDevice && state.cIndex == -1) {
  1800. uni.showToast({
  1801. title: '蓝牙设备未连接',
  1802. icon: 'none'
  1803. })
  1804. }
  1805. // console.log(22);
  1806. //记录蓝牙盒子当前的指令
  1807. // state.currentInstruction = value;
  1808. // 发送 3 :开启原始数据
  1809. // 发送4 :关闭原始数据
  1810. // 发送 5 :开启步数
  1811. // 发送6 :关闭步数
  1812. if (value == "3") {
  1813. state.instructionState.bOpen = true;
  1814. } else if (value == "4") {
  1815. state.instructionState.bOpen = false;
  1816. } else if (value == "5") {
  1817. state.instructionState.bSteps = true;
  1818. } else if (value == "6") {
  1819. state.instructionState.bSteps = false;
  1820. } else if (bSendHex && bOpen) {
  1821. state.instructionState.bOpen = true;
  1822. } else if (bSendHex && !bOpen) {
  1823. state.instructionState.bOpen = false;
  1824. }
  1825. let retryCount = 5;
  1826. this.commit("B_WriteBLECharacteristicValue", {
  1827. value,
  1828. retryCount,
  1829. getSuccess,
  1830. getFail,
  1831. bSendHex
  1832. });
  1833. },
  1834. //获取距离
  1835. onGetRSSITransDistance(state, context) {
  1836. let {
  1837. RSSI
  1838. } = context;
  1839. BLE.getRSSITransDistance(RSSI);
  1840. },
  1841. //添加使用的前端信息
  1842. gOnAddClientInfo(state, context) {
  1843. uni.getSystemInfo({
  1844. success: (res) => {
  1845. // console.log("系统信息:", res);
  1846. let clientInfo = res;
  1847. clientInfo.clientSystem = res.system;
  1848. reqUtil.requestData(config.URL.ADDCLIENTINFO, clientInfo, 'POST').then(
  1849. res => {
  1850. console.warn(res);
  1851. },
  1852. e => {}
  1853. );
  1854. },
  1855. fail: (err) => {},
  1856. complete: () => {}
  1857. })
  1858. },
  1859. //创建快速打击对象
  1860. gCreateFilterObj(state) {
  1861. state.filter = null;
  1862. state.deviceMs = 1;
  1863. state.filter = new o0Project.Filter();
  1864. console.log("gCreateFilterObj");
  1865. },
  1866. //更新快速打击对象数据
  1867. gUpdateFilter(state, context) {
  1868. let {
  1869. data,
  1870. callback
  1871. } = context;
  1872. let {
  1873. min,
  1874. s,
  1875. ms
  1876. } = data;
  1877. var msGap = ms - state.deviceMs;
  1878. state.deviceMs = ms;
  1879. while (msGap < 0) {
  1880. msGap += 1000;
  1881. }
  1882. // console.log(data);
  1883. let {
  1884. ax,
  1885. ay,
  1886. az
  1887. } = data.acc;
  1888. let {
  1889. gx,
  1890. gy,
  1891. gz
  1892. } = data.gyro;
  1893. // console.log(ax);
  1894. state.filter.Update(new o0.Vector3(ax, ay, az), msGap, new o0.Vector3(gx, gy, gz),
  1895. callback); //我自己的更新acc的函数
  1896. },
  1897. /**
  1898. * 创建一个沙袋打击对象
  1899. * @param {Object} state
  1900. */
  1901. gCreateSandbagAlgorithm(state) {
  1902. state.sandbagAlgorithm = null;
  1903. state.sandbagAlgorithmLastTime = new Date().getTime();
  1904. state.sandbagAlgorithm = new o0ProjectRelease.SandbagAlgorithm();
  1905. console.log("gCreateSandbagAlgorithm");
  1906. },
  1907. /**
  1908. * 更新 沙袋打击对象 数据
  1909. * @param {Object} state
  1910. * @param {Object} context
  1911. */
  1912. gUpdateSandbagAlgorithm(state, context) {
  1913. let {
  1914. data,
  1915. callback = null
  1916. } = context;
  1917. let {
  1918. ax,
  1919. ay,
  1920. az
  1921. } = data.acc;
  1922. let {
  1923. gx,
  1924. gy,
  1925. gz
  1926. } = data.gyro;
  1927. /**
  1928. * ax / 10, az / 10, gz, -gx, data.ms ----- old
  1929. * ay / 10, -az / 10, gy, gz, data.msK
  1930. * let [hit, dir] = state.sandbagAlgorithm.Update(-ay, az, -gz, -gy, data.ms);
  1931. * 纠正后使用的轴向
  1932. * box["acc"] = {
  1933. ax: -ay,
  1934. ay: -ax,
  1935. az: az
  1936. };
  1937. box["gyro"] = {
  1938. gx: -gy,
  1939. gy: -gx,
  1940. gz: gz
  1941. };
  1942. */
  1943. let {
  1944. ms
  1945. } = data;
  1946. let msGap = ms - state.deviceMs;
  1947. state.deviceMs = ms;
  1948. while (msGap < 0) {
  1949. msGap += 1000;
  1950. }
  1951. let [hit, dir] = state.sandbagAlgorithm.Update(ax, az, -gz, gx, msGap); //手柄方向
  1952. if (dir != undefined) {
  1953. let temp = state.sandbagAlgorithm.getTempValue(dir);
  1954. if (callback) {
  1955. callback(temp);
  1956. }
  1957. // let hitCount = temp.hitCount;
  1958. }
  1959. },
  1960. //灯带
  1961. gIntelligentUpdateSandbagAlgorithm(state, context) {
  1962. let {
  1963. data,
  1964. callback = null
  1965. } = context;
  1966. let {
  1967. ax,
  1968. ay,
  1969. az
  1970. } = data.acc;
  1971. let {
  1972. gx,
  1973. gy,
  1974. gz
  1975. } = data.gyro;
  1976. let {
  1977. ms
  1978. } = data;
  1979. let msGap = ms - state.deviceMs;
  1980. state.deviceMs = ms;
  1981. while (msGap < 0) {
  1982. msGap += 1000;
  1983. }
  1984. let [hit, dir] = state.sandbagAlgorithm.Update(ax, az, gz, -gx, msGap); //灯带方向
  1985. if (dir != undefined) {
  1986. let temp = state.sandbagAlgorithm.getTempValue(dir);
  1987. if (callback) {
  1988. callback(temp);
  1989. }
  1990. // let hitCount = temp.hitCount;
  1991. // 打击灯带时候播放一段闪烁
  1992. // if (temp.type == 'hit') {
  1993. // console.log("onHitOpenBLELight");
  1994. // this.commit("onHitOpenBLELight");
  1995. // }
  1996. }
  1997. },
  1998. onHitOpenBLELightNew(state) {
  1999. if (state.BLEConnectDevice.deviceType != "BLEIntelligent") {
  2000. return;
  2001. }
  2002. if (state.lightTimeout != null) {
  2003. clearTimeout(state.lightTimeout);
  2004. state.lightTimeout == null;
  2005. };
  2006. this.commit('B_WriteHexToBLECharacteristic', {
  2007. value: BLERGB.getRandomThreeRGB()
  2008. });
  2009. state.lightTimeout = setTimeout(() => {
  2010. //关闭红绿蓝
  2011. this.commit('B_WriteHexToBLECharacteristic', {
  2012. // value: "5B0E0200000000000000000000000000005D"
  2013. value: BLERGB.getRandomRGB()
  2014. });
  2015. if (state.lightTimeout != null) {
  2016. clearInterval(state.lightTimeout);
  2017. state.lightTimeout == null;
  2018. };
  2019. }, 310)
  2020. },
  2021. onHitOpenBLELight(state) {
  2022. state.showLightArray = [];
  2023. let openGreen = "5B06015200470142005D";
  2024. let shutGreen = "5B06015200470242005D";
  2025. state.showLightArray.push(openGreen);
  2026. state.showLightArray.push(shutGreen);
  2027. let openBlue = "5B06015200470042015D";
  2028. let shutBlue = "5B06015200470042025D";
  2029. state.showLightArray.push(openBlue);
  2030. state.showLightArray.push(shutBlue);
  2031. // this.commit('B_WriteHexToBLECharacteristic', {
  2032. // value: "5B06015200470042005D"
  2033. // });
  2034. if (state.lightInterval != null) {
  2035. clearInterval(state.lightInterval);
  2036. state.lightInterval == null;
  2037. };
  2038. state.lightCount = 0;
  2039. let timerCount = 0;
  2040. state.lightInterval = setInterval(() => {
  2041. state.showLight = state.showLightArray[state.lightCount];
  2042. // console.log(state.showLight);
  2043. this.commit('B_WriteHexToBLECharacteristic', {
  2044. value: state.showLight
  2045. });
  2046. if (state.lightCount >= state.showLightArray.length - 1) {
  2047. state.lightCount = 0;
  2048. } else {
  2049. state.lightCount += 1;
  2050. }
  2051. timerCount++;
  2052. if (timerCount > 5) {
  2053. if (state.lightInterval != null) {
  2054. clearInterval(state.lightInterval);
  2055. state.lightInterval == null;
  2056. };
  2057. state.lightCount = 0;
  2058. //关闭红绿蓝
  2059. this.commit('B_WriteHexToBLECharacteristic', {
  2060. value: "5B06015202470242025D"
  2061. });
  2062. }
  2063. }, 100)
  2064. },
  2065. //更新一个灯光数组
  2066. onUpdateShowLightArray(state) {
  2067. state.showLightArray = [];
  2068. let openRed = "5B06015201470042005D";
  2069. let shutRed = "5B06015202470042005D";
  2070. // state.showLightArray.push(openRed);
  2071. // state.showLightArray.push(shutRed);
  2072. let openGreen = "5B06015200470142005D";
  2073. let shutGreen = "5B06015200470242005D";
  2074. state.showLightArray.push(openGreen);
  2075. state.showLightArray.push(shutGreen);
  2076. let openBlue = "5B06015200470042015D";
  2077. let shutBlue = "5B06015200470042025D";
  2078. state.showLightArray.push(openBlue);
  2079. state.showLightArray.push(shutBlue);
  2080. },
  2081. /**
  2082. * 开启加速计,陀螺仪,并且模拟ble发送
  2083. * @param {Object} state
  2084. */
  2085. gStartSimulateBLEUpdate(state) {
  2086. //todo 区分平台,目前是android 模块
  2087. if (state.globalMyAttitude == null) {
  2088. state.globalMyAttitude = uni.requireNativePlugin("MyAttitude");
  2089. let globalEvent = uni.requireNativePlugin('globalEvent');
  2090. globalEvent.addEventListener('updateAccAndGyro', function(e) {
  2091. //updateAccAndGyro{"accelerometer":[-0.178375244140625,9.327804565429688,2.6168670654296875],"gyroscope":[0.0018310546875,-0.0019989013671875,0.0027923583984375]}
  2092. //console.log('updateAccAndGyro' + JSON.stringify(e));
  2093. let _accArray = e.accelerometer;
  2094. let _gyroArray = e.gyroscope;
  2095. state.globalAccData.ax = _accArray[0];
  2096. state.globalAccData.ay = _accArray[1];
  2097. state.globalAccData.az = _accArray[2];
  2098. state.globalGyroData.gx = _gyroArray[0];
  2099. state.globalGyroData.gy = _gyroArray[1];
  2100. state.globalGyroData.gz = _gyroArray[2];
  2101. let box = {};
  2102. box["acc"] = state.globalAccData;
  2103. box["gyro"] = state.globalGyroData;
  2104. box["ms"] = e.ms;
  2105. //更新数据给webview,在game-play-web||game-play-sub绑定
  2106. //后面更新数据都用此接口
  2107. uni.$emit('updateBLEDeviceData', box);
  2108. });
  2109. }
  2110. var ret = state.globalMyAttitude.onStartAccAndGyro();
  2111. if (!ret.accelerometer || !ret.gyroscope) {
  2112. uni.showModal({
  2113. title: '提示',
  2114. content: '是否初始化,加速计:' + ret.accelerometer + ',陀螺仪:' + ret.gyroscope
  2115. })
  2116. }
  2117. console.log('gStartSimulateBLEUpdate:', ret);
  2118. },
  2119. /**
  2120. * 停止加速计,陀螺仪
  2121. * @param {Object} state
  2122. */
  2123. gStopSimulateBLEUpdate(state) {
  2124. //todo 区分平台,目前是android 模块
  2125. let globalEvent = uni.requireNativePlugin('globalEvent');
  2126. globalEvent.removeEventListener('updateAccAndGyro');
  2127. var ret = state.globalMyAttitude.onStopAccAndGyro();
  2128. console.log('gStopSimulateBLEUpdate:', ret);
  2129. state.globalMyAttitude = null;
  2130. },
  2131. /**
  2132. * 限制开始游戏
  2133. */
  2134. glimitPlayGame(state, context) {
  2135. let {
  2136. gameTags,
  2137. callback
  2138. } = context;
  2139. //没有标签直接进去
  2140. if (gameTags.length == 0) {
  2141. callback();
  2142. return;
  2143. }
  2144. let canPlay = false;
  2145. gameTags.forEach((item) => {
  2146. //如果存在普通模式
  2147. if (item.tagMode === 'normal') {
  2148. canPlay = true;
  2149. }
  2150. if (canPlay)
  2151. return;
  2152. })
  2153. if (!canPlay) {
  2154. //2.如果普通模式不存在,就判断是否连接硬件了
  2155. if (!state.BLEConnectDevice || state.cIndex == -1) {
  2156. uni.showToast({
  2157. title: "请连接标签对应的设备模式!",
  2158. icon: "none",
  2159. duration: 2000,
  2160. mask: true
  2161. })
  2162. return;
  2163. }
  2164. //3.如果连接了设备,判断但是处于什么模式
  2165. gameTags.forEach((item, index, selfArr) => {
  2166. //如果存在普通模式
  2167. if (item.tagMode === state.BLEConnectDevice.usageMode) {
  2168. canPlay = true;
  2169. }
  2170. if (canPlay)
  2171. return;
  2172. if (index == selfArr.length - 1) {
  2173. uni.showToast({
  2174. title: "游戏没有当前设备模式!",
  2175. icon: "none",
  2176. duration: 2000,
  2177. mask: true
  2178. })
  2179. }
  2180. })
  2181. }
  2182. if (canPlay) {
  2183. callback();
  2184. }
  2185. },
  2186. checkAppUpdata(state) {
  2187. //#ifdef APP-PLUS
  2188. let _temp = {
  2189. appid: plus.runtime.appid,
  2190. version: state.version,
  2191. versionCode: state.versionCode,
  2192. platform: state.platform.toLocaleLowerCase(),
  2193. }
  2194. //#endif
  2195. //#ifdef H5
  2196. //此 _temp 测试用
  2197. let _temp = {
  2198. appid: '1',
  2199. version: "2.0.0",
  2200. versionCode: "20122202",
  2201. platform: "android",
  2202. }
  2203. //#endif
  2204. reqUtil.requestData(config.URL.APPVERSIONUPDATE, _temp).then(res => {
  2205. console.log('requestData APPVERSIONUPDATE =====', res);
  2206. let _data = res.data;
  2207. if (res.code == 0 && res.data.status === 1) {
  2208. uni.showModal({ //提醒用户更新
  2209. title: "更新提示",
  2210. content: res.data.note,
  2211. success: (res) => {
  2212. if (res.confirm) {
  2213. if (state.platform.toLocaleLowerCase() == "android") {
  2214. plus.runtime.openURL(_data.url, function(res) {
  2215. plus.nativeUI.alert("本机没安装应用宝,请安装后获取新版本。");
  2216. }, 'com.tencent.android.qqdownloader');
  2217. } else {
  2218. //ios
  2219. plus.runtime.openURL(_data.url);
  2220. }
  2221. }
  2222. }
  2223. })
  2224. } else {
  2225. uni.showToast({
  2226. title: '当前为最新版本',
  2227. icon: 'none',
  2228. duration: 2000,
  2229. mask: true
  2230. })
  2231. }
  2232. },
  2233. e => {
  2234. console.log(e)
  2235. });
  2236. },
  2237. /**
  2238. * 蓝牙BLE迁移到store.js
  2239. */
  2240. // 初始化蓝牙模块适配器
  2241. B_OpenBluetoothAdapter(state, context) {
  2242. let {
  2243. success,
  2244. fail,
  2245. complete
  2246. } = context;
  2247. //#ifdef H5
  2248. console.warn('h5不加载蓝牙模块');
  2249. return;
  2250. //#endif
  2251. uni.openBluetoothAdapter({
  2252. success: res => {
  2253. if (success)
  2254. success(res);
  2255. },
  2256. fail: res => {
  2257. if (fail)
  2258. fail(res);
  2259. },
  2260. complete: res => {
  2261. if (complete)
  2262. complete(res);
  2263. }
  2264. })
  2265. },
  2266. /**
  2267. * 关闭蓝牙模块适配器
  2268. */
  2269. B_CloseBluetoothAdapter() {
  2270. //#ifdef H5
  2271. console.warn('h5不加载蓝牙模块');
  2272. return;
  2273. //#endif
  2274. uni.closeBluetoothAdapter({
  2275. success: res => {
  2276. console.log('断开蓝牙模块成功');
  2277. uni.showToast({
  2278. icon: "none",
  2279. title: "蓝牙已经断开!",
  2280. mask: false,
  2281. duration: 3000
  2282. });
  2283. }
  2284. });
  2285. },
  2286. B_OnBLEConnectionStateChange(state) {
  2287. let _self = this;
  2288. //#ifdef H5
  2289. console.warn('h5不加载蓝牙模块');
  2290. return;
  2291. //#endif
  2292. uni.onBLEConnectionStateChange(res => {
  2293. // 该方法回调中可以用于处理连接意外断开等异常情况
  2294. console.log(`蓝牙连接状态 -------------------------->`, JSON.stringify(res));
  2295. if (!res.connected) {
  2296. //要在连接的状态下 ,并且获取过匹配列表有参数的情况下,才提示重连
  2297. if (!state.bShowBLEConnectModal && state.bVerifiedConnection) {
  2298. state.bShowBLEConnectModal = true;
  2299. let _connectItem = Object.assign({}, state.BLEConnectDevice);
  2300. let _cIndex = state.cIndex;
  2301. //断开连接后reset一下参数
  2302. _self.commit("onResetBLEConnection");
  2303. let _tip = state.bGamePlaying ? "蓝牙已断开是否重新连接蓝牙?重连需要重启游戏!" : "蓝牙已断开是否重新连接蓝牙";
  2304. uni.showModal({
  2305. title: _tip,
  2306. success: (sRes) => {
  2307. state.bShowBLEConnectModal = false;
  2308. if (sRes.confirm) {
  2309. console.log("重连的_cIndex:", _cIndex);
  2310. _self.commit("onCreateBLEConnection", {
  2311. item: _connectItem,
  2312. index: _cIndex,
  2313. initItem: true,
  2314. getSuccess: () => {
  2315. //此处不检查外部设备
  2316. uni.$emit('retryConnectBLESuccess');
  2317. },
  2318. getinitAdapter: () => {}
  2319. })
  2320. }
  2321. }
  2322. })
  2323. } else {
  2324. //断开连接后reset一下参数
  2325. _self.commit("onResetBLEConnection");
  2326. }
  2327. uni.$emit('callbackCloseBLE');
  2328. }
  2329. });
  2330. },
  2331. /**
  2332. * 连接低功耗蓝牙设备。
  2333. * 若APP在之前已有搜索过某个蓝牙设备,并成功建立连接,可直接传入之前搜索获取的 deviceId 直接尝试连接该设备,无需进行搜索操作。
  2334. */
  2335. B_CreateBLEConnection(state, context) {
  2336. let {
  2337. item,
  2338. success,
  2339. fail
  2340. } = context;
  2341. this.commit('initBLEData');
  2342. state.deviceId = item.deviceId;
  2343. let timeout = 10000;
  2344. // console.log("B_CreateBLEConnection deviceId ==", state.deviceId)
  2345. uni.createBLEConnection({
  2346. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  2347. deviceId: state.deviceId,
  2348. timeout: timeout,
  2349. success: res => {
  2350. if (success) {
  2351. success(res);
  2352. }
  2353. },
  2354. fail: res => {
  2355. if (fail)
  2356. fail(res);
  2357. }
  2358. });
  2359. },
  2360. /**
  2361. * 获取设备的服务ID
  2362. */
  2363. B_GetBLEDeviceServices(state, context) {
  2364. let {
  2365. retryCount,
  2366. item,
  2367. callback,
  2368. getServiceList,
  2369. getFail,
  2370. } = context;
  2371. let serviceList = [];
  2372. let _self = this;
  2373. uni.getBLEDeviceServices({
  2374. deviceId: item.deviceId,
  2375. success: res => {
  2376. // console.log("getBLEDeviceServices==", JSON.stringify(res), item);
  2377. serviceList = res.services;
  2378. if (getServiceList) {
  2379. getServiceList(serviceList);
  2380. }
  2381. if (serviceList.length == 0) {
  2382. if (retryCount > 0) {
  2383. retryCount--;
  2384. context.retryCount = retryCount;
  2385. setTimeout(() => {
  2386. this.commit('B_GetBLEDeviceServices', context);
  2387. }, 500)
  2388. return;
  2389. }
  2390. if (getFail) {
  2391. getFail();
  2392. }
  2393. uni.hideToast();
  2394. uni.showModal({
  2395. title: '提示',
  2396. content: '1.获取服务失败,请尝试重新连接设备。\r\n2.尝试重启设备再重新连接。'
  2397. })
  2398. }
  2399. for (let i = 0; i < serviceList.length; i++) {
  2400. let service = serviceList[i];
  2401. if (service.uuid.toLocaleLowerCase() === item.PRIMARY_SERVICE
  2402. .toLocaleLowerCase()) {
  2403. state.serviceId = service.uuid;
  2404. //开始获取指定服务的特征值
  2405. _self.commit('B_GetBLEDeviceCharacteristics', {
  2406. item: item,
  2407. callback: callback
  2408. });
  2409. break;
  2410. }
  2411. }
  2412. },
  2413. fail: failRes => {
  2414. console.log('device services:', failRes.services);
  2415. uni.hideToast();
  2416. uni.showModal({
  2417. title: '连接错误',
  2418. content: '请尝试重新连接设备。'
  2419. })
  2420. if (getFail) {
  2421. getFail();
  2422. }
  2423. }
  2424. });
  2425. },
  2426. /**
  2427. * 获取指定服务的特征值
  2428. */
  2429. B_GetBLEDeviceCharacteristics(state, context) {
  2430. let {
  2431. item,
  2432. callback
  2433. } = context;
  2434. let deviceId = state.deviceId;
  2435. let serviceId = state.serviceId;
  2436. let characteristicsList = [];
  2437. uni.getBLEDeviceCharacteristics({
  2438. deviceId,
  2439. serviceId,
  2440. success: res => {
  2441. if (item.PRIMARY_NOTIFY != '') {
  2442. state.notifyCharacteristicId = item.PRIMARY_NOTIFY;
  2443. this.commit('B_NotifyBLECharacteristicValueChange', {
  2444. callback: callback
  2445. });
  2446. }
  2447. if (item.PRIMARY_WRITE != '') {
  2448. state.writeCharacteristicId = item.PRIMARY_WRITE;
  2449. }
  2450. },
  2451. fail: res => {
  2452. console.log('device getBLEDeviceCharacteristics failed:', JSON.stringify(res))
  2453. }
  2454. })
  2455. },
  2456. //启用低功耗蓝牙设备特征值变化时的 notify 功能,订阅特征值。
  2457. //注意:必须设备的特征值支持notify或者indicate才可以成功调用,具体参照 characteristic 的 properties 属性
  2458. B_NotifyBLECharacteristicValueChange(state, context) {
  2459. let {
  2460. callback
  2461. } = context;
  2462. // 启用notify功能
  2463. // console.log("启用notify功能");
  2464. uni.notifyBLECharacteristicValueChange({
  2465. state: true,
  2466. deviceId: state.deviceId,
  2467. serviceId: state.serviceId,
  2468. characteristicId: state.notifyCharacteristicId,
  2469. success: (res) => {
  2470. this.commit('B_OnBLECharacteristicValueChange', {
  2471. callback: callback
  2472. });
  2473. },
  2474. fail: (res) => {
  2475. uni.showToast({
  2476. title: 'notify启动失败',
  2477. icon: "none",
  2478. mask: true
  2479. });
  2480. }
  2481. })
  2482. },
  2483. //监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。
  2484. B_OnBLECharacteristicValueChange(state, context) {
  2485. let {
  2486. callback
  2487. } = context;
  2488. // console.log("onBLECharacteristicValueChange success");
  2489. if (callback) {
  2490. callback({
  2491. notifyCharacteristicId: state.notifyCharacteristicId,
  2492. writeCharacteristicId: state.writeCharacteristicId
  2493. })
  2494. }
  2495. uni.onBLECharacteristicValueChange(function(res) {
  2496. //如果是ota 更新服务,这里处理通知ota更新数据
  2497. if (res.serviceId.toLocaleLowerCase() === state.UUID_OTA_SERVICE) {
  2498. uni.$emit("OTAValueChange", res);
  2499. return;
  2500. }
  2501. //serviceId 0000FFF0-0000-1000-8000-00805F9B34FB characteristic 0000FFF1-0000-1000-8000-00805F9B34FB
  2502. // console.log(`store ${res.serviceId} characteristic ${res.characteristicId} has changed, now is ${res.value}`);
  2503. let box = {};
  2504. var resValue = BLE.ab2hext(res.value); //16进制字符串
  2505. if (state.currentInstruction == "V" && state.showToast) {
  2506. var resValueStr = BLE.hexToString(resValue);
  2507. let _info = {
  2508. type: 'version',
  2509. instruction: 'V',
  2510. value: resValueStr.replace(/\{|}/g, '').trim()
  2511. }
  2512. uni.$emit('listenerBLE', _info);
  2513. state.currentInstruction = "";
  2514. state.showToast = false;
  2515. return;
  2516. } else if (state.currentInstruction == 'M' && state.bListenerMac) {
  2517. var resValueStr = BLE.hexToString(resValue);
  2518. let _info = {
  2519. type: 'mac',
  2520. instruction: 'M',
  2521. value: resValueStr.replace(/\{|}/g, '').trim()
  2522. }
  2523. uni.$emit('listenerBLE', _info);
  2524. state.currentInstruction = "";
  2525. state.bListenerMac = false;
  2526. return;
  2527. }
  2528. //步数数据解析
  2529. if (state.bListenerJson) {
  2530. var resValueStr = BLE.hexToString(resValue);
  2531. console.log(resValueStr);
  2532. box["Json"] = resValueStr;
  2533. uni.$emit('updateBLEDeviceJson', box);
  2534. }
  2535. //解析4组加速计数据
  2536. if (state.bListenerAccArray) {
  2537. let ms1 = BLE.hex2int(resValue.substr(2, 4));
  2538. let min1 = BLE.hex2int(resValue.substr(6, 2));
  2539. let s1 = BLE.hex2int(resValue.substr(8, 2));
  2540. let ax1Str = resValue.substr(10, 4);
  2541. let ay1Str = resValue.substr(14, 4);
  2542. let az1Str = resValue.substr(18, 4);
  2543. let ax1 = BLE.hexToSignedInt(ax1Str) / 32768 * 16;
  2544. let ay1 = BLE.hexToSignedInt(ay1Str) / 32768 * 16;
  2545. let az1 = BLE.hexToSignedInt(az1Str) / 32768 * 16;
  2546. let ms2 = BLE.hex2int(resValue.substr(22, 4));
  2547. let min2 = BLE.hex2int(resValue.substr(26, 2));
  2548. let s2 = BLE.hex2int(resValue.substr(28, 2));
  2549. let ax2Str = resValue.substr(30, 4);
  2550. let ay2Str = resValue.substr(34, 4);
  2551. let az2Str = resValue.substr(38, 4);
  2552. let ax2 = BLE.hexToSignedInt(ax2Str) / 32768 * 16;
  2553. let ay2 = BLE.hexToSignedInt(ay2Str) / 32768 * 16;
  2554. let az2 = BLE.hexToSignedInt(az2Str) / 32768 * 16;
  2555. let ms3 = BLE.hex2int(resValue.substr(42, 4));
  2556. let min3 = BLE.hex2int(resValue.substr(46, 2));
  2557. let s3 = BLE.hex2int(resValue.substr(48, 2));
  2558. let ax3Str = resValue.substr(50, 4);
  2559. let ay3Str = resValue.substr(54, 4);
  2560. let az3Str = resValue.substr(58, 4);
  2561. let ax3 = BLE.hexToSignedInt(ax3Str) / 32768 * 16;
  2562. let ay3 = BLE.hexToSignedInt(ay3Str) / 32768 * 16;
  2563. let az3 = BLE.hexToSignedInt(az3Str) / 32768 * 16;
  2564. let ms4 = BLE.hex2int(resValue.substr(62, 4));
  2565. let min4 = BLE.hex2int(resValue.substr(66, 2));
  2566. let s4 = BLE.hex2int(resValue.substr(68, 2));
  2567. let ax4Str = resValue.substr(70, 4);
  2568. let ay4Str = resValue.substr(74, 4);
  2569. let az4Str = resValue.substr(78, 4);
  2570. let ax4 = BLE.hexToSignedInt(ax4Str) / 32768 * 16;
  2571. let ay4 = BLE.hexToSignedInt(ay4Str) / 32768 * 16;
  2572. let az4 = BLE.hexToSignedInt(az4Str) / 32768 * 16;
  2573. let accArray = [{
  2574. ax: ax1,
  2575. ay: ay1,
  2576. az: az1,
  2577. ms: ms1,
  2578. min: min1,
  2579. s: s1
  2580. }, {
  2581. ax: ax2,
  2582. ay: ay2,
  2583. az: az2,
  2584. ms: ms2,
  2585. min: min2,
  2586. s: s2
  2587. }, {
  2588. ax: ax3,
  2589. ay: ay3,
  2590. az: az3,
  2591. ms: ms3,
  2592. min: min3,
  2593. s: s3
  2594. }, {
  2595. ax: ax4,
  2596. ay: ay4,
  2597. az: az4,
  2598. ms: ms4,
  2599. min: min4,
  2600. s: s4
  2601. }]
  2602. for (let i = 0; i < accArray.length; i++) {
  2603. let _temp = accArray[i];
  2604. box["acc"] = {
  2605. ax: _temp.ax,
  2606. ay: _temp.ay,
  2607. az: _temp.az,
  2608. };
  2609. box["min"] = _temp.min;
  2610. box["s"] = _temp.s;
  2611. box["ms"] = _temp.ms;
  2612. uni.$emit('updateBLEDeviceData', box);
  2613. }
  2614. }
  2615. //原始数据解析
  2616. if (state.bListenerUpdate) {
  2617. //R/L 左手还是右手
  2618. let handle = resValue.substr(6, 2);
  2619. let axStr = resValue.substr(8, 4);
  2620. let ayStr = resValue.substr(12, 4);
  2621. let azStr = resValue.substr(16, 4);
  2622. //一个字节最大只能表示265 2个字节可以表示65536 然后你这边做一下转换 例如00 3E 3*16+14=62 ----->0.03 g
  2623. //(真实值= AD值 /32768 * 16)
  2624. //0.003 = 62 / 2768 * 16
  2625. let ax = BLE.hexToSignedInt(axStr) / 32768 * 16;
  2626. let ay = BLE.hexToSignedInt(ayStr) / 32768 * 16;
  2627. let az = BLE.hexToSignedInt(azStr) / 32768 * 16;
  2628. let gxStr = resValue.substr(20, 4);
  2629. let gyStr = resValue.substr(24, 4);
  2630. let gzStr = resValue.substr(28, 4);
  2631. //角速度(AD值/32768 * 2000) 角速度单位是 °/s 范围是 正负2000
  2632. let gx = BLE.hexToSignedInt(gxStr) / 32768 * 2000;
  2633. let gy = BLE.hexToSignedInt(gyStr) / 32768 * 2000;
  2634. let gz = BLE.hexToSignedInt(gzStr) / 32768 * 2000;
  2635. //毫秒
  2636. let ms = BLE.hex2int(resValue.substr(2, 4));
  2637. //分
  2638. let min = BLE.hex2int(resValue.substr(32, 2));
  2639. //秒
  2640. let s = BLE.hex2int(resValue.substr(34, 2));
  2641. // ax / 10, az / 10, gz, -gx, data.ms ----- old
  2642. // let [hit, dir] = state.sandbagAlgorithm.Update(-ay, az, -gz, -gy, data.ms);
  2643. box["handle"] = BLE.hexToString(handle);
  2644. /**
  2645. * 纠正手柄传感器轴向。
  2646. * 以方向键向上为 -g = y ,左右按钮向上 -g = x, 按键面向上 -g = z;
  2647. * 陀螺仪旋转方向:逆时针为负-,顺时针为正+;
  2648. */
  2649. box["acc"] = {
  2650. ax: -ay,
  2651. ay: -ax,
  2652. az: az
  2653. };
  2654. box["gyro"] = {
  2655. gx: -gy,
  2656. gy: -gx,
  2657. gz: gz
  2658. };
  2659. box["min"] = min;
  2660. box["s"] = s;
  2661. box["ms"] = ms;
  2662. //16进制参数
  2663. box["hex"] = resValue;
  2664. //更新数据给webview,在game-play-web||game-play-sub绑定
  2665. //后面更新数据都用此接口
  2666. uni.$emit('updateBLEDeviceData', box);
  2667. }
  2668. //todo 解析跳绳模式
  2669. if (state.bListenerHexUpdate) {
  2670. //报头,固定
  2671. let byte1 = resValue.substr(0, 2);
  2672. //功能码,todo
  2673. let byte2 = resValue.substr(2, 2);
  2674. // 报文类型,后续区分在这里,目前是跳绳模式类型
  2675. let byte3 = resValue.substr(4, 2);
  2676. //报文内容,长度以 2为单位 动态变化
  2677. let byteData = resValue.substr(6, resValue.length - 10)
  2678. //报文按照长度2切割
  2679. let byteArray = byteData.replace(/(\d{2})(?=(?:\d{2})+(?!\d))/g, '$1,').split(',');
  2680. console.log("byteArray:", byteArray);
  2681. // 校验
  2682. let byteVerify = resValue.substr(resValue.length - 4, 2);
  2683. // 报尾,结束
  2684. let byteEnd = resValue.substr(resValue.length - 2, 2);
  2685. //todo 暂时先这样触发
  2686. if (byteArray.length == 2 && byteArray[0] != byteArray[1]) {
  2687. if (byteArray[0] == '00') {
  2688. state.bRopeKeyOne = 1;
  2689. } else {
  2690. //'01'
  2691. state.bRopeKeyTwo = 1;
  2692. }
  2693. if (state.bRopeKeyOne == 1 && state.bRopeKeyTwo == 1) {
  2694. state.bRopeKeyOne = 0;
  2695. state.bRopeKeyTwo = 0;
  2696. box["Rope"] = 1;
  2697. uni.$emit('updateBLEDeviceData', box);
  2698. }
  2699. }
  2700. }
  2701. });
  2702. },
  2703. /**
  2704. * 开启跳绳模式
  2705. */
  2706. B_OpenRopeSkipping() {
  2707. // this.commit('onWriteBLEConnectionValue', {
  2708. // value: "5B310101FE5D",
  2709. // bSendHex: true,
  2710. // bOpen: true
  2711. // });
  2712. console.log('B_OpenRopeSkipping', 3);
  2713. this.commit('onWriteBLEConnectionValue', {
  2714. value: "3"
  2715. });
  2716. },
  2717. /**
  2718. * 关闭跳绳模式
  2719. */
  2720. B_CloseRopeSkipping() {
  2721. // this.commit('onWriteBLEConnectionValue', {
  2722. // value: "5B210100FF5D",
  2723. // bSendHex: true,
  2724. // bOpen: false
  2725. // });
  2726. this.commit('onWriteBLEConnectionValue', {
  2727. value: "4"
  2728. });
  2729. },
  2730. //向低功耗蓝牙设备特征值中写入二进制数据。注意:必须设备的特征值支持 write 才可以成功调用。
  2731. B_WriteBLECharacteristicValue(state, context) {
  2732. let {
  2733. value,
  2734. retryCount,
  2735. success,
  2736. getFail,
  2737. bSendHex,
  2738. } = context;
  2739. if (!value && value === '') {
  2740. uni.showToast({
  2741. title: "指令为空"
  2742. })
  2743. return;
  2744. }
  2745. let _sendData;
  2746. if (bSendHex) {
  2747. // state.bRopeKeyTwo = 0;
  2748. // state.bRopeKeyOne = 0;
  2749. //不用解析跳绳模式
  2750. state.bListenerHexUpdate = false;
  2751. //不用关闭原始数据更新
  2752. state.bListenerUpdate = true;
  2753. let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
  2754. return parseInt(h, 16)
  2755. }))
  2756. _sendData = typedArray.buffer;
  2757. } else {
  2758. state.bListenerHexUpdate = false;
  2759. //记录一下指令
  2760. state.currentInstruction = value;
  2761. //V 获取版本,M 获取mac 地址
  2762. if (value == "V")
  2763. state.showToast = true;
  2764. if (value == "M") {
  2765. state.showToast = true;
  2766. state.bListenerMac = true;
  2767. }
  2768. if (value == "4") {
  2769. state.bListenerUpdate = false;
  2770. }
  2771. if (value == "3") {
  2772. if (state.bListenerUpdate) {
  2773. console.warn("原始数据已开启");
  2774. }
  2775. state.bListenerUpdate = true;
  2776. }
  2777. if (value == "6") {
  2778. state.bListenerAccArray = false;
  2779. }
  2780. if (value == "5") {
  2781. if (state.bListenerAccArray) {
  2782. uni.showToast({
  2783. title: "加速计组数据已开启"
  2784. })
  2785. return;
  2786. }
  2787. state.bListenerAccArray = true;
  2788. }
  2789. _sendData = BLE.str2ab(value);
  2790. }
  2791. // console.log("currentInstruction:", state.currentInstruction, value, state.bListenerUpdate, state
  2792. // .bListenerMac,
  2793. // state.bListenerHexUpdate);
  2794. // console.log("state.deviceId:", state.deviceId, state.serviceId, state.writeCharacteristicId);
  2795. uni.writeBLECharacteristicValue({
  2796. deviceId: state.deviceId,
  2797. serviceId: state.serviceId,
  2798. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  2799. characteristicId: state.writeCharacteristicId,
  2800. // 这里的value是ArrayBuffer类型
  2801. value: _sendData,
  2802. success: (res) => {
  2803. console.log('writeBLECharacteristicValue success', res.errMsg, value,
  2804. retryCount);
  2805. if (success) {
  2806. success(res);
  2807. }
  2808. },
  2809. fail: (fail) => {
  2810. console.log(fail)
  2811. //重新写入
  2812. if (retryCount > 0) {
  2813. console.log("writeBLECharacteristicValue Rewrite ===================>" +
  2814. value + " == " + retryCount);
  2815. retryCount--;
  2816. setTimeout(() => {
  2817. this.commit("B_WriteBLECharacteristicValue", {
  2818. value,
  2819. retryCount,
  2820. success,
  2821. getFail
  2822. });
  2823. }, 300);
  2824. }
  2825. if (getFail) {
  2826. getFail(fail);
  2827. }
  2828. }
  2829. })
  2830. },
  2831. B_WriteHexToBLECharacteristic(state, context) {
  2832. let {
  2833. value,
  2834. retryCount = 5,
  2835. success = null,
  2836. getFail = null,
  2837. } = context;
  2838. if (!value && value === '') {
  2839. uni.showToast({
  2840. title: "指令为空"
  2841. })
  2842. return;
  2843. }
  2844. let typedArray = new Uint8Array(value.match(/[\da-f]{2}/gi).map(function(h) {
  2845. return parseInt(h, 16)
  2846. }))
  2847. uni.writeBLECharacteristicValue({
  2848. deviceId: state.deviceId,
  2849. serviceId: state.serviceId,
  2850. characteristicId: state.writeCharacteristicId,
  2851. value: typedArray.buffer,
  2852. success: (res) => {
  2853. console.log('B_WriteHexToBLECharacteristicSuccess', res.errMsg, value,
  2854. retryCount);
  2855. if (success) {
  2856. success(res);
  2857. }
  2858. },
  2859. fail: (fail) => {
  2860. console.log(fail)
  2861. //重新写入
  2862. if (retryCount > 0) {
  2863. console.log("B_WriteHexToBLECharacteristicRewrite =======>" +
  2864. value + " == " + retryCount);
  2865. retryCount--;
  2866. setTimeout(() => {
  2867. this.commit("B_WriteHexToBLECharacteristic", {
  2868. value,
  2869. retryCount,
  2870. success,
  2871. getFail
  2872. });
  2873. }, 300);
  2874. }
  2875. if (getFail) {
  2876. getFail(fail);
  2877. }
  2878. }
  2879. })
  2880. },
  2881. /**
  2882. * 断开蓝牙连接
  2883. */
  2884. B_CloseBLEConnection(state, context) {
  2885. let {
  2886. deviceId,
  2887. success = null
  2888. } = context;
  2889. uni.closeBLEConnection({
  2890. deviceId,
  2891. success: res => {
  2892. if (success)
  2893. success();
  2894. },
  2895. fail: (fail) => {
  2896. console.log("关闭蓝牙失败", fail);
  2897. }
  2898. });
  2899. },
  2900. //获取手机中蓝牙已匹配的设备
  2901. B_GetBondedDevices(state, context) {
  2902. // console.log("getBondedDevices ====>");
  2903. let {
  2904. success = null,
  2905. deviceId = null
  2906. } = context;
  2907. //Android
  2908. function android_bluetooth_list(deviceName, deviceId, count, callback) {
  2909. console.log("===》调用android_bluetooth_list count:", count);
  2910. var main = plus.android.runtimeMainActivity();
  2911. var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
  2912. var BAdapter = BluetoothAdapter.getDefaultAdapter();
  2913. var Context = plus.android.importClass("android.content.Context");
  2914. var lists = BAdapter.getBondedDevices();
  2915. plus.android.importClass(lists);
  2916. var len = lists.size();
  2917. // var BluetoothManager = plus.android.importClass("android.bluetooth.BluetoothManager");
  2918. // var BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice");
  2919. // var ProfileType = plus.android.importClass("android.bluetooth.ProfileType");
  2920. // plus.android.importClass(BluetoothManager);
  2921. // plus.android.importClass(BluetoothDevice);
  2922. // plus.android.importClass(ProfileType);
  2923. // var UUID = plus.android.importClass("java.util.UUID");
  2924. // var uuid = UUID.fromString("0000FFF0-0000-1000-8000-00805F9B34FB");
  2925. // var gDevice = BAdapter.getRemoteDevice("C5:5C:19:04:00:30");
  2926. // plus.android.importClass(gDevice);
  2927. // var bluetoothSocket = gDevice.createInsecureRfcommSocketToServiceRecord(uuid);
  2928. // plus.android.importClass(bluetoothSocket);
  2929. // console.log("是否连接:",bluetoothSocket.isConnected());
  2930. // var deviceLists = BluetoothManager.getConnectedDevices();
  2931. // plus.android.importClass(deviceLists);
  2932. // console.log("deviceLists.len=" + deviceLists.size());
  2933. console.log("getBondedDevices.len=", len, "deviceId:", deviceId);
  2934. //测试start===》 如果没有配对的设备,重新获取
  2935. // count--;
  2936. // if(count >0){
  2937. // setTimeout(()=>{
  2938. // android_bluetooth_list("BGBox", deviceId, count, callback);
  2939. // },1000)
  2940. // return;
  2941. // }
  2942. //测试end
  2943. if (len == 0) {
  2944. //如果没有配对的设备,重新获取
  2945. count--;
  2946. if (count > 0) {
  2947. setTimeout(() => {
  2948. android_bluetooth_list("BGBox", deviceId, count, callback);
  2949. }, 2000)
  2950. } else {
  2951. if (callback)
  2952. callback(null);
  2953. }
  2954. } else {
  2955. var iterator = lists.iterator();
  2956. let temp = null;
  2957. plus.android.importClass(iterator);
  2958. while (iterator.hasNext()) {
  2959. var d = iterator.next();
  2960. plus.android.importClass(d);
  2961. // if (d.getName().indexOf(deviceName) > -1)
  2962. // console.log(d.getAddress(), deviceId);
  2963. if (deviceId == null && d.getName().indexOf(deviceName) > -1) {
  2964. let typeEnum = {
  2965. 0: 'Unknown',
  2966. 1: 'Classic',
  2967. 2: 'Le',
  2968. 3: 'Dual'
  2969. };
  2970. let bondStateEnum = {
  2971. 10: 'None',
  2972. 11: 'Bonding',
  2973. 12: 'Bonded'
  2974. };
  2975. temp = {
  2976. name: d.getName(),
  2977. address: d.getAddress(),
  2978. type: {
  2979. 'value': d.getType(),
  2980. 'name': typeEnum[d.getType()]
  2981. },
  2982. bondState: {
  2983. 'value': d.getBondState(),
  2984. 'name': bondStateEnum[d.getBondState()]
  2985. }
  2986. }
  2987. console.log("获取到设备,并且跳出:", temp);
  2988. break;
  2989. } else if (d.getAddress() == deviceId) {
  2990. // console.log(d.getName());
  2991. // console.log(d.getAddress());
  2992. // Classic 1
  2993. // Dual 3
  2994. // Le 2
  2995. // Unknown 0
  2996. // console.log(d.getType());
  2997. // Bonded 12
  2998. // Bonding 11 Indicates bonding (pairing) is in progress with the remote device.
  2999. // None 10
  3000. // console.log(d.getBondState());
  3001. let typeEnum = {
  3002. 0: 'Unknown',
  3003. 1: 'Classic',
  3004. 2: 'Le',
  3005. 3: 'Dual'
  3006. };
  3007. let bondStateEnum = {
  3008. 10: 'None',
  3009. 11: 'Bonding',
  3010. 12: 'Bonded'
  3011. };
  3012. temp = {
  3013. name: d.getName(),
  3014. address: d.getAddress(),
  3015. type: {
  3016. 'value': d.getType(),
  3017. 'name': typeEnum[d.getType()]
  3018. },
  3019. bondState: {
  3020. 'value': d.getBondState(),
  3021. 'name': bondStateEnum[d.getBondState()]
  3022. }
  3023. }
  3024. console.log("获取到设备,并且跳出:", temp);
  3025. break;
  3026. }
  3027. }
  3028. // return temp;
  3029. if (temp == null && count > 0) {
  3030. count--;
  3031. setTimeout(() => {
  3032. android_bluetooth_list("BGBox", deviceId, count, callback);
  3033. }, 2000)
  3034. } else {
  3035. if (callback)
  3036. callback(temp);
  3037. }
  3038. }
  3039. }
  3040. function ios_bluetooth_list(deviceName, callback) {
  3041. //原生操作 首先需要通过 uni.requireNativePlugin("ModuleName") 获取 module
  3042. var SLABluetoothModule = uni.requireNativePlugin("SLABluetoothUniPlugin-SLAModule")
  3043. if (SLABluetoothModule) {
  3044. SLABluetoothModule.getConnectionDevicesAsync({
  3045. serviceUUIDs: "FFF0"
  3046. }, (res) => {
  3047. console.log("***************getConnectionDevicesAsync:", JSON.stringify(res));
  3048. if (res.data) {
  3049. console.log("获取到对应的匹配设备!");
  3050. let typeEnum = {
  3051. 0: 'Unknown',
  3052. 1: 'Classic',
  3053. 2: 'Le',
  3054. 3: 'Dual'
  3055. };
  3056. let bondStateEnum = {
  3057. 10: 'None',
  3058. 11: 'Bonding',
  3059. 12: 'Bonded'
  3060. };
  3061. let temp = {
  3062. name: res.data[0].name,
  3063. address: res.data[0].identifier,
  3064. type: {
  3065. 'value': 2,
  3066. 'name': typeEnum[2]
  3067. },
  3068. bondState: {
  3069. 'value': 12,
  3070. 'name': bondStateEnum[12]
  3071. }
  3072. }
  3073. if (callback) {
  3074. callback({
  3075. "device": temp
  3076. });
  3077. }
  3078. } else {
  3079. console.log("匹配设备数据不存在!");
  3080. if (callback) {
  3081. callback({
  3082. "device": null
  3083. });
  3084. }
  3085. }
  3086. })
  3087. } else {
  3088. console.error("不存在SLABluetoothModule ios 插件!");
  3089. if (callback) {
  3090. callback({
  3091. "device": null
  3092. });
  3093. }
  3094. }
  3095. }
  3096. let device = null;
  3097. let _count = 3;
  3098. switch (plus.os.name) {
  3099. case "Android":
  3100. // Android平台: plus.android.*
  3101. android_bluetooth_list("BGBox", deviceId, _count, (data) => {
  3102. device = data;
  3103. console.log("android getBondedDevices 匹配的对象======>", device)
  3104. if (device != null) {
  3105. state.bPhoneMatched = true;
  3106. } else {
  3107. state.bPhoneMatched = false;
  3108. }
  3109. if (success) {
  3110. success(device);
  3111. }
  3112. });
  3113. break;
  3114. case "iOS":
  3115. // iOS平台: plus.ios.*
  3116. ios_bluetooth_list("BGBox", (res) => {
  3117. device = res.device
  3118. if (success) {
  3119. success(device);
  3120. }
  3121. console.log("ios getBondedDevices 匹配的对象======>", device)
  3122. if (device != null) {
  3123. state.bPhoneMatched = true;
  3124. } else {
  3125. state.bPhoneMatched = false;
  3126. }
  3127. });
  3128. break;
  3129. default:
  3130. // 其它平台
  3131. if (success) {
  3132. success(device);
  3133. }
  3134. break;
  3135. }
  3136. // if (success) {
  3137. // success(device);
  3138. // }
  3139. },
  3140. B_OpenBLESetting() {
  3141. function android_bluetooth_setting() {
  3142. var main = plus.android.runtimeMainActivity(); //获取activity
  3143. var Intent = plus.android.importClass('android.content.Intent');
  3144. var Settings = plus.android.importClass('android.provider.Settings');
  3145. var intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); //可设置表中所有Action字段
  3146. main.startActivity(intent);
  3147. }
  3148. function ios_bluetooth_setting() {
  3149. // var UIApplication = plus.ios.import("UIApplication");
  3150. // var application2 = UIApplication.sharedApplication();
  3151. // var NSURL2 = plus.ios.import("NSURL");
  3152. // var setting2 = NSURL2.URLWithString("app-settings:");
  3153. // application2.openURL(setting2);
  3154. // plus.ios.deleteObject(setting2);
  3155. // plus.ios.deleteObject(NSURL2);
  3156. // plus.ios.deleteObject(application2);
  3157. // plus.runtime.openURL({
  3158. // action: 'App-Prefs:root=Bluetooth'
  3159. // }, function(e) {
  3160. // console.log(JSON.stringify(e));
  3161. // });
  3162. plus.runtime.launchApplication({
  3163. action: 'App-Prefs:root=Bluetooth'
  3164. }, function(e) {
  3165. console.log(JSON.stringify(e));
  3166. });
  3167. }
  3168. let device = null;
  3169. switch (plus.os.name) {
  3170. case "Android":
  3171. // Android平台: plus.android.*
  3172. android_bluetooth_setting();
  3173. break;
  3174. case "iOS":
  3175. // iOS平台: plus.ios.*
  3176. ios_bluetooth_setting();
  3177. break;
  3178. default:
  3179. // 其它平台
  3180. break;
  3181. }
  3182. },
  3183. //获取versionCode状态,用于处理特定的信息显示
  3184. getVersionCode(state) {
  3185. let self = this;
  3186. console.log("state.versionCode:" + state.versionCode);
  3187. reqUtil.requestData(config.URL.GETVERSIONCODE, {
  3188. code: state.versionCode
  3189. }).then(res => {
  3190. console.log('获取版本控制信息 =====' + JSON.stringify(res));
  3191. if (res.code == 0) {
  3192. state.versionCodeState = Object.assign({}, state.versionCodeState, res.data);
  3193. /**
  3194. * 初始化配置表方案
  3195. * 搞一个区分平台上线显示等,根据版本版本号,是否显示,平台限制等区别
  3196. */
  3197. //显示,隐藏游戏栏目
  3198. uni.setTabBarItem({
  3199. index: 2,
  3200. visible: state.versionCodeState.showGame
  3201. })
  3202. //显示,隐藏视频栏目
  3203. uni.setTabBarItem({
  3204. index: 3,
  3205. visible: state.versionCodeState.showVideo
  3206. })
  3207. }
  3208. },
  3209. e => {
  3210. console.log(e)
  3211. });
  3212. },
  3213. /**
  3214. * 任务其他操作
  3215. */
  3216. //获取关卡信息
  3217. getLevelList(state, callback) {
  3218. let self = this;
  3219. reqUtil
  3220. .requestData(config.URL.GETLEVELLIST, {}) //GETLEVELJUMPLIST
  3221. .then(
  3222. res => {
  3223. if (res.code == 0) {
  3224. // state.singlePersonList = res.data.singlePerson;
  3225. // state.multiPersonList = res.data.multiPerson;
  3226. // console.log(res.data);
  3227. let levels = res.data;
  3228. state.levels = levels;
  3229. if (1 === state.currentModeIndex) {
  3230. //关卡是跳绳
  3231. state.singlePersonList = levels.singlePersonMap[0];
  3232. state.multiPersonList = levels.multiPersonMap[0];
  3233. } else if (0 === state.currentModeIndex) {
  3234. //关卡是拳击
  3235. state.singlePersonList = levels.singlePersonMap[1];
  3236. state.multiPersonList = levels.multiPersonMap[1];
  3237. }
  3238. //获取到数据时候,重置actionJump
  3239. self.commit('resetActionJumpTask');
  3240. if (callback)
  3241. callback();
  3242. }
  3243. },
  3244. e => {
  3245. console.log(e);
  3246. }
  3247. );
  3248. },
  3249. //切换关卡列表信息K
  3250. switchLevelList(state, _levelType) {
  3251. // console.log( state.levels.multiPersonMap)
  3252. // console.log( state.levels.singlePersonMap)
  3253. if (state.levels.singlePersonMap && state.levels.singlePersonMap.length >= _levelType)
  3254. state.singlePersonList = state.levels.singlePersonMap[_levelType - 1];
  3255. else
  3256. state.singlePersonList = [];
  3257. if (state.levels.multiPersonMap && state.levels.multiPersonMap.length >= _levelType)
  3258. state.multiPersonList = state.levels.multiPersonMap[_levelType - 1];
  3259. else
  3260. state.multiPersonList = [];
  3261. if (1 === _levelType) {
  3262. //关卡是跳绳
  3263. state.currentModeIndex = 1;
  3264. } else if (2 === _levelType) {
  3265. //关卡是拳击
  3266. state.currentModeIndex = 0;
  3267. }
  3268. // console.log(state.currentModeIndex)
  3269. },
  3270. /**
  3271. * 获取钱包信息
  3272. * @param {Object} state
  3273. * @param {Object} callback
  3274. */
  3275. getUserWallets(state, callback) {
  3276. reqUtil
  3277. .requestData(config.URL.USERGETWALLETINFO, {})
  3278. .then(
  3279. res => {
  3280. if (res.code == 0) {
  3281. console.log('USERGETWALLETINFO:' + JSON.stringify(res.data));
  3282. state.cGold = res.data.gold;
  3283. state.cDiamond = res.data.diamond;
  3284. if (callback)
  3285. callback();
  3286. }
  3287. },
  3288. e => {
  3289. console.log(e);
  3290. }
  3291. );
  3292. },
  3293. setGoldAndDiamond(state, context) {
  3294. let {
  3295. gold,
  3296. diamond
  3297. } = context;
  3298. state.cGold = gold;
  3299. state.cDiamond = diamond;
  3300. },
  3301. /**
  3302. * 抽屉和弹出框
  3303. */
  3304. hideDrawerById(state, context) {
  3305. // let { id } = context;
  3306. //personal-drawer
  3307. uni.getSubNVueById('personal-drawer').hide('slide-in-left', 200);
  3308. },
  3309. showDrawerById(state, context) {
  3310. // let { id } = context;
  3311. //personal-drawer
  3312. uni.getSubNVueById('personal-drawer').show('slide-in-left', 200);
  3313. },
  3314. closeDrawerById(state, context) {
  3315. const subNVue = uni.getSubNVueById('personal-drawer');
  3316. subNVue.close();
  3317. console.log('销毁侧滑栏子窗体');
  3318. },
  3319. showPopupById(state, context) {
  3320. let {
  3321. type,
  3322. item
  3323. } = context;
  3324. console.log(type, item);
  3325. switch (type) {
  3326. case 'levelReward':
  3327. uni.$emit('reward-popup', {
  3328. title: '奖励',
  3329. content: '',
  3330. type: type,
  3331. item: {
  3332. gold: item.rewardGold,
  3333. diamond: item.rewardDiamond,
  3334. honor: item.rewardHonor
  3335. },
  3336. operationItem: item
  3337. });
  3338. break;
  3339. case 'prompt':
  3340. // 向 popup 传递消息
  3341. uni.$emit('reward-popup', {
  3342. title: '奖励',
  3343. content: '',
  3344. type: type,
  3345. item: {
  3346. gold: item.rewardGold,
  3347. diamond: item.rewardDiamond,
  3348. honor: item.rewardHonor
  3349. },
  3350. operationItem: item
  3351. });
  3352. break;
  3353. case 'unlock':
  3354. // 向 popup 传递消息
  3355. uni.$emit('reward-popup', {
  3356. title: '解锁关卡',
  3357. content: '',
  3358. type: type,
  3359. item: {
  3360. consumeGold: item.consumeGold,
  3361. consumeDiamond: item.consumeDiamond
  3362. },
  3363. operationItem: item
  3364. });
  3365. break;
  3366. case 'signIn':
  3367. this.commit("onSendSignInPopup", context);
  3368. break;
  3369. case 'pkFinish':
  3370. // 向 popup 传递消息
  3371. uni.$emit('reward-popup', {
  3372. title: 'pk完成',
  3373. content: '',
  3374. type: type,
  3375. item: item,
  3376. operationItem: item
  3377. });
  3378. break;
  3379. default:
  3380. uni.showToast({
  3381. title: 'showPopup类型为空',
  3382. icon: 'none'
  3383. })
  3384. break;
  3385. }
  3386. // #ifdef APP-PLUS
  3387. //personal-popup
  3388. const subNVue = uni.getSubNVueById('personal-popup')
  3389. subNVue.show('zoom-out', 250)
  3390. // #endif
  3391. },
  3392. closePopupById(state, context) {
  3393. const subNVue = uni.getSubNVueById('personal-popup')
  3394. subNVue.close();
  3395. console.log('销毁奖励子窗体');
  3396. },
  3397. showGuideById(state, context) {
  3398. let {
  3399. type,
  3400. item
  3401. } = context;
  3402. uni.$emit('guide-popup', {
  3403. title: 'guide',
  3404. content: '定制guide',
  3405. type: type,
  3406. item: item,
  3407. operationItem: item
  3408. });
  3409. const subNVue = uni.getSubNVueById('personal-guide')
  3410. subNVue.show('fade-in', 250)
  3411. },
  3412. closeGuideById() {
  3413. const subNVue = uni.getSubNVueById('personal-guide')
  3414. subNVue.close();
  3415. console.log('销毁新手指引子窗体');
  3416. },
  3417. /**
  3418. * 获取签到列表
  3419. * @param {Object} state
  3420. * @param {Object} callback
  3421. */
  3422. getSignInList(state, callback) {
  3423. reqUtil
  3424. .requestData(config.URL.GETSIGNINLIST, {})
  3425. .then(
  3426. res => {
  3427. if (res.code == 0) {
  3428. // console.log('GETSIGNINLIST:' + JSON.stringify(res.data));
  3429. state.signInList = res.data.signInList;
  3430. state.isSignIn = res.data.isSignIn;
  3431. if (callback)
  3432. callback(res.data);
  3433. }
  3434. },
  3435. e => {
  3436. console.log(e);
  3437. }
  3438. );
  3439. },
  3440. /**
  3441. * 签到
  3442. * @param {Object} state
  3443. * @param {Object} callback
  3444. */
  3445. onUserSignIn(state, callback) {
  3446. reqUtil
  3447. .requestData(config.URL.USERSIGNIN, {})
  3448. .then(
  3449. res => {
  3450. console.log('USERSIGNIN:' + JSON.stringify(res));
  3451. if (res.code == 0) {
  3452. state.cGold = res.data.userGold;
  3453. state.cDiamond = res.data.userDiamond;
  3454. uni.showToast({
  3455. title: '签到成功',
  3456. mask: true
  3457. })
  3458. //根据dayType 计算最近一个flag
  3459. for (let i = 0; i < state.signInList.length; i++) {
  3460. if (res.data.signIn.dayType == state.signInList[i].dayType) {
  3461. state.signInList[i] = Object.assign({}, state.signInList[i], res.data
  3462. .signIn);
  3463. break;
  3464. }
  3465. }
  3466. state.isSignIn = true;
  3467. if (callback)
  3468. callback(res.data);
  3469. } else if (res.code == 901) {
  3470. uni.showToast({
  3471. title: '今天已签到',
  3472. mask: true
  3473. })
  3474. }
  3475. },
  3476. e => {
  3477. console.log(e);
  3478. }
  3479. );
  3480. },
  3481. onSendSignInPopup(state, context) {
  3482. let {
  3483. type,
  3484. item
  3485. } = context;
  3486. let _reward = [{
  3487. name: 'gold',
  3488. width: 28,
  3489. height: 28,
  3490. url: '../../../static/common/sideBar/sGold.png',
  3491. selectedUrl: '../../../static/common/subNVue/sign/sign-grey-gold@2x.png',
  3492. explain: '',
  3493. value: 20,
  3494. isSelect: false
  3495. },
  3496. {
  3497. name: 'diamond',
  3498. width: 28,
  3499. height: 28,
  3500. url: '../../../static/common/sideBar/sDiamond.png',
  3501. selectedUrl: '../../../static/common/subNVue/sign/sign-grey-diamond@2x.png',
  3502. explain: '',
  3503. value: 20,
  3504. isSelect: false
  3505. }
  3506. ];
  3507. let list = state.signInList;
  3508. let lists = [];
  3509. for (let i = 0; i < list.length; i++) {
  3510. if (0 !== list[i].gold) {
  3511. lists.push(Object.assign({}, _reward[0], {
  3512. value: list[i].gold
  3513. }))
  3514. } else if (0 !== list[i].diamond) {
  3515. lists.push(Object.assign({}, _reward[1], {
  3516. value: list[i].diamond
  3517. }))
  3518. }
  3519. lists[i].isSelect = list[i].flag == 1 ? true : false;
  3520. }
  3521. // console.log("list:"+JSON.stringify(list));
  3522. // 向 popup 传递消息
  3523. uni.$emit('reward-popup', {
  3524. title: '每日签到',
  3525. content: '',
  3526. type: type,
  3527. lists: lists,
  3528. isSignIn: state.isSignIn
  3529. });
  3530. },
  3531. /**
  3532. * 记录沙袋打击计数
  3533. * @param {Object} state
  3534. * @param {Object} count
  3535. */
  3536. setSandbagHitCount(state, count) {
  3537. // uni.setStorageSync('sandbagHitCount', count);
  3538. state.sandbagHitCount = count;
  3539. },
  3540. addSandbagHitCount(state, context) {
  3541. let {
  3542. count
  3543. } = context;
  3544. let addCount = Number(state.sandbagHitCount) + Number(count);
  3545. // console.log("addCount:" + addCount);
  3546. state.sandbagHitCount = addCount;
  3547. uni.setStorageSync('sandbagHitCount', state.sandbagHitCount);
  3548. },
  3549. getSandbagHitCount(state) {
  3550. const value = uni.getStorageSync('sandbagHitCount');
  3551. if (value) {
  3552. state.sandbagHitCount = value;
  3553. } else {
  3554. state.sandbagHitCount = 0;
  3555. }
  3556. },
  3557. /**
  3558. * 获取用户等hitcount数据
  3559. * 同步沙袋计数
  3560. * @param {Object} state
  3561. */
  3562. getUserData_hitCount(state) {
  3563. //获取本地数据
  3564. this.commit("getSandbagHitCount");
  3565. reqUtil
  3566. .requestData(config.URL.USERDATA_GETHITCOUNT, {}, 'POST')
  3567. .then(
  3568. res => {
  3569. console.log('USERDATA_GETHITCOUNT:' + JSON.stringify(res));
  3570. if (res.code == 0) {
  3571. if (res.data.isReset) {
  3572. this.commit("setSandbagHitCount", 0);
  3573. } else {
  3574. if (res.data.hitCount > state.sandbagHitCount) {
  3575. this.commit("setSandbagHitCount", res.data.hitCount);
  3576. state.netSandbagHitCount = res.data.hitCount;
  3577. } else if (res.data.hitCount < state.sandbagHitCount) {
  3578. //获取时候,小于本地记录的,则同步到网络
  3579. this.commit("uploadUserData_hitCount");
  3580. }
  3581. }
  3582. }
  3583. },
  3584. e => {
  3585. console.log(e);
  3586. }
  3587. );
  3588. },
  3589. uploadUserData_hitCount(state) {
  3590. //如果拳击数没变化,则不用上传
  3591. if (state.netSandbagHitCount == state.sandbagHitCount) return;
  3592. reqUtil
  3593. .requestData(config.URL.USERDATA_UPLOADHITCOUNT, {
  3594. hitCount: state.sandbagHitCount
  3595. }, 'POST')
  3596. .then(
  3597. res => {
  3598. console.log('USERDATA_UPLOADHITCOUNT:' + JSON.stringify(res));
  3599. if (res.code == 0) {
  3600. this.commit("setSandbagHitCount", res.data.hitCount)
  3601. state.netSandbagHitCount = res.data.hitCount;
  3602. }
  3603. },
  3604. e => {
  3605. console.log(e);
  3606. }
  3607. );
  3608. },
  3609. onConnectSocket(state) {
  3610. // let self = this;
  3611. // uni.connectSocket({
  3612. // // #ifdef APP-PLUS
  3613. // url: 'wss://www.9527fun.cn/api_dev/websocket/APPLog/123'
  3614. // // #endif
  3615. // // #ifdef H5
  3616. // // url:'wss://www.9527fun.cn/api_dev/websocket/APPLog/123'
  3617. // url: 'ws://192.168.0.108:9090/api_dev/websocket/APPLog/123'
  3618. // // #endif
  3619. // });
  3620. // uni.onSocketMessage(function(res) {
  3621. // console.log('收到服务器内容:' + res.data);
  3622. // });
  3623. // uni.onSocketOpen(function(res) {
  3624. // console.log('WebSocket连接已打开!');
  3625. // });
  3626. // uni.onSocketError(function(res) {
  3627. // console.log('WebSocket连接打开失败,请检查!');
  3628. // });
  3629. },
  3630. onCloseSocket(state) {
  3631. // uni.onSocketClose(function(res) {
  3632. // console.log('WebSocket 已关闭!');
  3633. // });
  3634. },
  3635. onSendSocketMessage(state, msg) {
  3636. // console.log("发送数据", msg);
  3637. // uni.sendSocketMessage({
  3638. // data: JSON.stringify(msg)
  3639. // });
  3640. },
  3641. //jumpIdenModule 算法插件 start
  3642. jumpIdenModule_SearchData(state, context) {
  3643. if (uni.getSystemInfoSync().platform == "ios") {
  3644. return;
  3645. }
  3646. state.filesList = [];
  3647. let {
  3648. data,
  3649. callback = null
  3650. } = context;
  3651. let url = "http://42.192.165.168:2022/search";
  3652. let _temp = {
  3653. name: state.readDataName
  3654. }
  3655. console.log('requestData search ===== url:' + url);
  3656. reqUtil.requestData(url, _temp, 'POST').then(res => {
  3657. let strArray = res.split('\n');
  3658. console.log(strArray);
  3659. for (let i = 0; i < strArray.length - 1; i++) {
  3660. let _name = strArray[i].split('.')[0];
  3661. if (_name.Length <= 0) continue;
  3662. let item = Object.assign({}, {
  3663. cname: _name,
  3664. bRatio: false
  3665. });
  3666. state.filesList.push(item);
  3667. }
  3668. uni.showToast({
  3669. title: '获取列表成功!',
  3670. icon: 'none',
  3671. duration: 1000,
  3672. mask: true
  3673. })
  3674. },
  3675. e => {
  3676. console.log(e)
  3677. uni.showToast({
  3678. title: '请求失败!',
  3679. icon: 'none',
  3680. duration: 1000,
  3681. mask: true
  3682. })
  3683. });
  3684. },
  3685. jumpIdenModule_DownloadReadData(state, context) {
  3686. if (uni.getSystemInfoSync().platform == "ios") {
  3687. return;
  3688. }
  3689. let {
  3690. data,
  3691. callback = null
  3692. } = context;
  3693. let downloadUrl = "http://42.192.165.168:2022/download";
  3694. console.log('requestData downloadUrl ===== url:' + downloadUrl);
  3695. reqUtil.requestData(downloadUrl, {
  3696. name: data.cname
  3697. }, 'POST').then(res => {
  3698. //console.log(res);
  3699. uni.setStorageSync('readData', res);
  3700. if (callback)
  3701. callback(res);
  3702. //读取的数据传入android端
  3703. let _temp = jumpIdenModule.onJumpInitInputData({
  3704. data: res
  3705. })
  3706. uni.showToast({
  3707. title: '' + _temp.msg,
  3708. icon: 'none',
  3709. duration: 1000,
  3710. mask: true
  3711. })
  3712. },
  3713. e => {
  3714. console.log(e)
  3715. uni.showToast({
  3716. title: '请求失败!',
  3717. icon: 'none',
  3718. duration: 1000,
  3719. mask: true
  3720. })
  3721. });
  3722. },
  3723. jumpIdenModule_onJumpInit() {
  3724. if (uni.getSystemInfoSync().platform == "ios") {
  3725. return;
  3726. }
  3727. let res = jumpIdenModule.onJumpInit();
  3728. uni.showToast({
  3729. title: '' + res.code,
  3730. icon: 'none',
  3731. duration: 1000,
  3732. mask: true
  3733. })
  3734. },
  3735. jumpIdenModule_onJumpInitLocalData() {
  3736. if (uni.getSystemInfoSync().platform == "ios") {
  3737. return;
  3738. }
  3739. let res = jumpIdenModule.onJumpInitLocalData();
  3740. uni.showToast({
  3741. title: '' + res.code,
  3742. icon: 'none',
  3743. duration: 1000,
  3744. mask: true
  3745. })
  3746. },
  3747. jumpIdenModule_onTestJump6AxisDataUpdate() {
  3748. let box = {};
  3749. box["acc"] = {
  3750. ax: 11,
  3751. ay: 22,
  3752. az: 33,
  3753. };
  3754. box["gyro"] = {
  3755. gx: 111,
  3756. gy: 222,
  3757. gz: 333,
  3758. };
  3759. box["ms"] = 33;
  3760. jumpIdenModule.onJump6AxisDataUpdate(box)
  3761. },
  3762. jumpIdenModule_onTestUpdate() {
  3763. jumpIdenModule.onTestUpdate();
  3764. },
  3765. jumpIdenModule_onJump6AxisDataUpdate(state, context) {
  3766. let {
  3767. data,
  3768. callback = null
  3769. } = context;
  3770. let res = jumpIdenModule.onJump6AxisDataUpdate({
  3771. hex: data.hex
  3772. });
  3773. if (callback)
  3774. callback(res);
  3775. },
  3776. onGetReadDataName(state) {
  3777. state.readDataName = uni.getStorageSync('readDataName');
  3778. },
  3779. onSetReadDataName(state, value) {
  3780. uni.setStorageSync('readDataName', value);
  3781. state.readDataName = value;
  3782. },
  3783. //jumpIdenModule 算法插件 end
  3784. //读取灯光存储的ble
  3785. onGetReadBLELight(state) {
  3786. let _readBLELight = uni.getStorageSync('readBLELight');
  3787. if (_readBLELight) {
  3788. state.readBLELight = _readBLELight;
  3789. }
  3790. },
  3791. onSetReadBLELight(state, value) {
  3792. uni.setStorageSync('readBLELight', value);
  3793. state.readBLELight = value;
  3794. },
  3795. }
  3796. })
  3797. export default store