store.js 105 KB

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