store.js 87 KB

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