store.js 105 KB

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