store.js 106 KB

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