store.js 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528
  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. console.warn("原始数据已开启");
  2561. // return;
  2562. }
  2563. state.bListenerUpdate = true;
  2564. }
  2565. if (value == "6") {
  2566. // state.bListenerJson = false;
  2567. state.bListenerAccArray = false;
  2568. }
  2569. if (value == "5") {
  2570. // if (state.bListenerJson) {
  2571. // uni.showToast({
  2572. // title: "步数数据已开启"
  2573. // })
  2574. // return;
  2575. // }
  2576. // state.bListenerJson = true;
  2577. if (state.bListenerAccArray) {
  2578. uni.showToast({
  2579. title: "加速计组数据已开启"
  2580. })
  2581. return;
  2582. }
  2583. state.bListenerAccArray = true;
  2584. }
  2585. _sendData = BLE.str2ab(value);
  2586. }
  2587. console.log("currentInstruction:", state.currentInstruction, value, state.bListenerUpdate, state
  2588. .bListenerMac,
  2589. state.bListenerHexUpdate);
  2590. console.log("state.deviceId:", state.deviceId, state.serviceId, state.writeCharacteristicId);
  2591. uni.writeBLECharacteristicValue({
  2592. deviceId: state.deviceId,
  2593. serviceId: state.serviceId,
  2594. // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
  2595. characteristicId: state.writeCharacteristicId,
  2596. // 这里的value是ArrayBuffer类型
  2597. value: _sendData,
  2598. success: (res) => {
  2599. console.log('writeBLECharacteristicValue success', res.errMsg, value,
  2600. retryCount);
  2601. if (success) {
  2602. success(res);
  2603. }
  2604. },
  2605. fail: (fail) => {
  2606. console.log(fail)
  2607. //重新写入
  2608. if (retryCount > 0) {
  2609. console.log("writeBLECharacteristicValue Rewrite ===================>" +
  2610. value + " == " + retryCount);
  2611. retryCount--;
  2612. setTimeout(() => {
  2613. this.commit("B_WriteBLECharacteristicValue", {
  2614. value,
  2615. retryCount,
  2616. success,
  2617. getFail
  2618. });
  2619. }, 300);
  2620. }
  2621. if (getFail) {
  2622. getFail(fail);
  2623. }
  2624. }
  2625. })
  2626. },
  2627. /**
  2628. * 断开蓝牙连接
  2629. */
  2630. B_CloseBLEConnection(state, context) {
  2631. let {
  2632. deviceId,
  2633. success = null
  2634. } = context;
  2635. uni.closeBLEConnection({
  2636. deviceId,
  2637. success: res => {
  2638. if (success)
  2639. success();
  2640. },
  2641. fail: (fail) => {
  2642. console.log("关闭蓝牙失败", fail);
  2643. }
  2644. });
  2645. },
  2646. //获取手机中蓝牙已匹配的设备
  2647. B_GetBondedDevices(state, context) {
  2648. // console.log("getBondedDevices ====>");
  2649. let {
  2650. success = null,
  2651. deviceId = null
  2652. } = context;
  2653. //Android
  2654. function android_bluetooth_list(deviceName, deviceId, count, callback) {
  2655. console.log("===》调用android_bluetooth_list count:", count);
  2656. var main = plus.android.runtimeMainActivity();
  2657. var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
  2658. var BAdapter = BluetoothAdapter.getDefaultAdapter();
  2659. var Context = plus.android.importClass("android.content.Context");
  2660. var lists = BAdapter.getBondedDevices();
  2661. plus.android.importClass(lists);
  2662. var len = lists.size();
  2663. // var BluetoothManager = plus.android.importClass("android.bluetooth.BluetoothManager");
  2664. // var BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice");
  2665. // var ProfileType = plus.android.importClass("android.bluetooth.ProfileType");
  2666. // plus.android.importClass(BluetoothManager);
  2667. // plus.android.importClass(BluetoothDevice);
  2668. // plus.android.importClass(ProfileType);
  2669. // var UUID = plus.android.importClass("java.util.UUID");
  2670. // var uuid = UUID.fromString("0000FFF0-0000-1000-8000-00805F9B34FB");
  2671. // var gDevice = BAdapter.getRemoteDevice("C5:5C:19:04:00:30");
  2672. // plus.android.importClass(gDevice);
  2673. // var bluetoothSocket = gDevice.createInsecureRfcommSocketToServiceRecord(uuid);
  2674. // plus.android.importClass(bluetoothSocket);
  2675. // console.log("是否连接:",bluetoothSocket.isConnected());
  2676. // var deviceLists = BluetoothManager.getConnectedDevices();
  2677. // plus.android.importClass(deviceLists);
  2678. // console.log("deviceLists.len=" + deviceLists.size());
  2679. console.log("getBondedDevices.len=", len, "deviceId:", deviceId);
  2680. //测试start===》 如果没有配对的设备,重新获取
  2681. // count--;
  2682. // if(count >0){
  2683. // setTimeout(()=>{
  2684. // android_bluetooth_list("BGBox", deviceId, count, callback);
  2685. // },1000)
  2686. // return;
  2687. // }
  2688. //测试end
  2689. if (len == 0) {
  2690. //如果没有配对的设备,重新获取
  2691. count--;
  2692. if (count > 0) {
  2693. setTimeout(() => {
  2694. android_bluetooth_list("BGBox", deviceId, count, callback);
  2695. }, 2000)
  2696. } else {
  2697. if (callback)
  2698. callback(null);
  2699. }
  2700. } else {
  2701. var iterator = lists.iterator();
  2702. let temp = null;
  2703. plus.android.importClass(iterator);
  2704. while (iterator.hasNext()) {
  2705. var d = iterator.next();
  2706. plus.android.importClass(d);
  2707. // if (d.getName().indexOf(deviceName) > -1)
  2708. // console.log(d.getAddress(), deviceId);
  2709. if (deviceId == null && d.getName().indexOf(deviceName) > -1) {
  2710. let typeEnum = {
  2711. 0: 'Unknown',
  2712. 1: 'Classic',
  2713. 2: 'Le',
  2714. 3: 'Dual'
  2715. };
  2716. let bondStateEnum = {
  2717. 10: 'None',
  2718. 11: 'Bonding',
  2719. 12: 'Bonded'
  2720. };
  2721. temp = {
  2722. name: d.getName(),
  2723. address: d.getAddress(),
  2724. type: {
  2725. 'value': d.getType(),
  2726. 'name': typeEnum[d.getType()]
  2727. },
  2728. bondState: {
  2729. 'value': d.getBondState(),
  2730. 'name': bondStateEnum[d.getBondState()]
  2731. }
  2732. }
  2733. console.log("获取到设备,并且跳出:", temp);
  2734. break;
  2735. } else if (d.getAddress() == deviceId) {
  2736. // console.log(d.getName());
  2737. // console.log(d.getAddress());
  2738. // Classic 1
  2739. // Dual 3
  2740. // Le 2
  2741. // Unknown 0
  2742. // console.log(d.getType());
  2743. // Bonded 12
  2744. // Bonding 11 Indicates bonding (pairing) is in progress with the remote device.
  2745. // None 10
  2746. // console.log(d.getBondState());
  2747. let typeEnum = {
  2748. 0: 'Unknown',
  2749. 1: 'Classic',
  2750. 2: 'Le',
  2751. 3: 'Dual'
  2752. };
  2753. let bondStateEnum = {
  2754. 10: 'None',
  2755. 11: 'Bonding',
  2756. 12: 'Bonded'
  2757. };
  2758. temp = {
  2759. name: d.getName(),
  2760. address: d.getAddress(),
  2761. type: {
  2762. 'value': d.getType(),
  2763. 'name': typeEnum[d.getType()]
  2764. },
  2765. bondState: {
  2766. 'value': d.getBondState(),
  2767. 'name': bondStateEnum[d.getBondState()]
  2768. }
  2769. }
  2770. console.log("获取到设备,并且跳出:", temp);
  2771. break;
  2772. }
  2773. }
  2774. // return temp;
  2775. if (temp == null && count > 0) {
  2776. count--;
  2777. setTimeout(() => {
  2778. android_bluetooth_list("BGBox", deviceId, count, callback);
  2779. }, 2000)
  2780. } else {
  2781. if (callback)
  2782. callback(temp);
  2783. }
  2784. }
  2785. }
  2786. function ios_bluetooth_list(deviceName, callback) {
  2787. //原生操作 首先需要通过 uni.requireNativePlugin("ModuleName") 获取 module
  2788. var SLABluetoothModule = uni.requireNativePlugin("SLABluetoothUniPlugin-SLAModule")
  2789. if (SLABluetoothModule) {
  2790. SLABluetoothModule.getConnectionDevicesAsync({
  2791. serviceUUIDs: "FFF0"
  2792. }, (res) => {
  2793. console.log("***************getConnectionDevicesAsync:", JSON.stringify(res));
  2794. if (res.data) {
  2795. console.log("获取到对应的匹配设备!");
  2796. let typeEnum = {
  2797. 0: 'Unknown',
  2798. 1: 'Classic',
  2799. 2: 'Le',
  2800. 3: 'Dual'
  2801. };
  2802. let bondStateEnum = {
  2803. 10: 'None',
  2804. 11: 'Bonding',
  2805. 12: 'Bonded'
  2806. };
  2807. let temp = {
  2808. name: res.data[0].name,
  2809. address: res.data[0].identifier,
  2810. type: {
  2811. 'value': 2,
  2812. 'name': typeEnum[2]
  2813. },
  2814. bondState: {
  2815. 'value': 12,
  2816. 'name': bondStateEnum[12]
  2817. }
  2818. }
  2819. if (callback) {
  2820. callback({
  2821. "device": temp
  2822. });
  2823. }
  2824. } else {
  2825. console.log("匹配设备数据不存在!");
  2826. if (callback) {
  2827. callback({
  2828. "device": null
  2829. });
  2830. }
  2831. }
  2832. })
  2833. } else {
  2834. console.error("不存在SLABluetoothModule ios 插件!");
  2835. if (callback) {
  2836. callback({
  2837. "device": null
  2838. });
  2839. }
  2840. }
  2841. }
  2842. let device = null;
  2843. let _count = 3;
  2844. switch (plus.os.name) {
  2845. case "Android":
  2846. // Android平台: plus.android.*
  2847. android_bluetooth_list("BGBox", deviceId, _count, (data) => {
  2848. device = data;
  2849. console.log("android getBondedDevices 匹配的对象======>", device)
  2850. if (device != null) {
  2851. state.bPhoneMatched = true;
  2852. } else {
  2853. state.bPhoneMatched = false;
  2854. }
  2855. if (success) {
  2856. success(device);
  2857. }
  2858. });
  2859. break;
  2860. case "iOS":
  2861. // iOS平台: plus.ios.*
  2862. ios_bluetooth_list("BGBox", (res) => {
  2863. device = res.device
  2864. if (success) {
  2865. success(device);
  2866. }
  2867. console.log("ios getBondedDevices 匹配的对象======>", device)
  2868. if (device != null) {
  2869. state.bPhoneMatched = true;
  2870. } else {
  2871. state.bPhoneMatched = false;
  2872. }
  2873. });
  2874. break;
  2875. default:
  2876. // 其它平台
  2877. if (success) {
  2878. success(device);
  2879. }
  2880. break;
  2881. }
  2882. // if (success) {
  2883. // success(device);
  2884. // }
  2885. },
  2886. B_OpenBLESetting() {
  2887. function android_bluetooth_setting() {
  2888. var main = plus.android.runtimeMainActivity(); //获取activity
  2889. var Intent = plus.android.importClass('android.content.Intent');
  2890. var Settings = plus.android.importClass('android.provider.Settings');
  2891. var intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); //可设置表中所有Action字段
  2892. main.startActivity(intent);
  2893. }
  2894. function ios_bluetooth_setting() {
  2895. // var UIApplication = plus.ios.import("UIApplication");
  2896. // var application2 = UIApplication.sharedApplication();
  2897. // var NSURL2 = plus.ios.import("NSURL");
  2898. // var setting2 = NSURL2.URLWithString("app-settings:");
  2899. // application2.openURL(setting2);
  2900. // plus.ios.deleteObject(setting2);
  2901. // plus.ios.deleteObject(NSURL2);
  2902. // plus.ios.deleteObject(application2);
  2903. // plus.runtime.openURL({
  2904. // action: 'App-Prefs:root=Bluetooth'
  2905. // }, function(e) {
  2906. // console.log(JSON.stringify(e));
  2907. // });
  2908. plus.runtime.launchApplication({
  2909. action: 'App-Prefs:root=Bluetooth'
  2910. }, function(e) {
  2911. console.log(JSON.stringify(e));
  2912. });
  2913. }
  2914. let device = null;
  2915. switch (plus.os.name) {
  2916. case "Android":
  2917. // Android平台: plus.android.*
  2918. android_bluetooth_setting();
  2919. break;
  2920. case "iOS":
  2921. // iOS平台: plus.ios.*
  2922. ios_bluetooth_setting();
  2923. break;
  2924. default:
  2925. // 其它平台
  2926. break;
  2927. }
  2928. },
  2929. //获取versionCode状态,用于处理特定的信息显示
  2930. getVersionCode(state) {
  2931. let self = this;
  2932. reqUtil.requestData(config.URL.GETVERSIONCODE, {
  2933. code: state.versionCode
  2934. }).then(res => {
  2935. console.log('获取GETVERSIONCODE =====', res);
  2936. if (res.code == 0) {
  2937. state.versionCodeState = res.data;
  2938. }
  2939. },
  2940. e => {
  2941. console.log(e)
  2942. });
  2943. },
  2944. /**
  2945. * 任务其他操作
  2946. */
  2947. //获取关卡信息
  2948. getLevelList(state, callback) {
  2949. let self = this;
  2950. reqUtil
  2951. .requestData(config.URL.GETLEVELJUMPLIST, {})
  2952. .then(
  2953. res => {
  2954. if (res.code == 0) {
  2955. // console.log('GETLEVELJUMPLIST:' + JSON.stringify(res.data.singlePerson));
  2956. state.singlePersonList = res.data.singlePerson;
  2957. state.multiPersonList = res.data.multiPerson;
  2958. //获取到数据时候,重置actionJump
  2959. self.commit('resetActionJumpTask');
  2960. if (callback)
  2961. callback();
  2962. }
  2963. },
  2964. e => {
  2965. console.log(e);
  2966. }
  2967. );
  2968. },
  2969. /**
  2970. * 获取钱包信息
  2971. * @param {Object} state
  2972. * @param {Object} callback
  2973. */
  2974. getUserWallets(state, callback) {
  2975. reqUtil
  2976. .requestData(config.URL.USERGETWALLETINFO, {})
  2977. .then(
  2978. res => {
  2979. if (res.code == 0) {
  2980. console.log('USERGETWALLETINFO:' + JSON.stringify(res.data));
  2981. state.cGold = res.data.gold;
  2982. state.cDiamond = res.data.diamond;
  2983. if (callback)
  2984. callback();
  2985. }
  2986. },
  2987. e => {
  2988. console.log(e);
  2989. }
  2990. );
  2991. },
  2992. setGoldAndDiamond(state, context) {
  2993. let {
  2994. gold,
  2995. diamond
  2996. } = context;
  2997. state.cGold = gold;
  2998. state.cDiamond = diamond;
  2999. },
  3000. /**
  3001. * 抽屉和弹出框
  3002. */
  3003. hideDrawerById(state, context) {
  3004. // let { id } = context;
  3005. //personal-drawer
  3006. uni.getSubNVueById('personal-drawer').hide('slide-in-left', 200);
  3007. },
  3008. showDrawerById(state, context) {
  3009. // let { id } = context;
  3010. //personal-drawer
  3011. uni.getSubNVueById('personal-drawer').show('slide-in-left', 200);
  3012. },
  3013. showPopupById(state, context) {
  3014. let {
  3015. type,
  3016. item
  3017. } = context;
  3018. console.log(type, item);
  3019. switch (type) {
  3020. case 'levelReward':
  3021. uni.$emit('reward-popup', {
  3022. title: '奖励',
  3023. content: '',
  3024. type: type,
  3025. item: {
  3026. gold: item.rewardGold,
  3027. diamond: item.rewardDiamond,
  3028. honor: item.rewardHonor
  3029. },
  3030. operationItem: item
  3031. });
  3032. break;
  3033. case 'prompt':
  3034. // 向 popup 传递消息
  3035. uni.$emit('reward-popup', {
  3036. title: '奖励',
  3037. content: '',
  3038. type: type,
  3039. item: {
  3040. gold: item.rewardGold,
  3041. diamond: item.rewardDiamond,
  3042. honor: item.rewardHonor
  3043. },
  3044. operationItem: item
  3045. });
  3046. break;
  3047. case 'unlock':
  3048. // 向 popup 传递消息
  3049. uni.$emit('reward-popup', {
  3050. title: '解锁关卡',
  3051. content: '',
  3052. type: type,
  3053. item: {
  3054. consumeGold: item.consumeGold,
  3055. consumeDiamond: item.consumeDiamond
  3056. },
  3057. operationItem: item
  3058. });
  3059. break;
  3060. case 'signIn':
  3061. this.commit("onSendSignInPopup", context);
  3062. break;
  3063. case 'pkFinish':
  3064. // 向 popup 传递消息
  3065. uni.$emit('reward-popup', {
  3066. title: 'pk完成',
  3067. content: '',
  3068. type: type,
  3069. item: item,
  3070. operationItem: item
  3071. });
  3072. break;
  3073. default:
  3074. uni.showToast({
  3075. title: 'showPopup类型为空',
  3076. icon: 'none'
  3077. })
  3078. break;
  3079. }
  3080. // #ifdef APP-PLUS
  3081. //personal-popup
  3082. const subNVue = uni.getSubNVueById('personal-popup')
  3083. subNVue.show('zoom-out', 250)
  3084. // #endif
  3085. },
  3086. showGuideById(state, context) {
  3087. let {
  3088. type,
  3089. item
  3090. } = context;
  3091. uni.$emit('guide-popup', {
  3092. title: 'guide',
  3093. content: '定制guide',
  3094. type: type,
  3095. item: item,
  3096. operationItem: item
  3097. });
  3098. const subNVue = uni.getSubNVueById('personal-guide')
  3099. subNVue.show('fade-in', 250)
  3100. },
  3101. getSignInList(state, callback) {
  3102. reqUtil
  3103. .requestData(config.URL.GETSIGNINLIST, {})
  3104. .then(
  3105. res => {
  3106. if (res.code == 0) {
  3107. console.log('GETSIGNINLIST:' + JSON.stringify(res.data));
  3108. state.signInList = res.data.signInList;
  3109. state.isSignIn = res.data.isSignIn;
  3110. if (callback)
  3111. callback(res.data);
  3112. }
  3113. },
  3114. e => {
  3115. console.log(e);
  3116. }
  3117. );
  3118. },
  3119. onUserSignIn(state, callback) {
  3120. reqUtil
  3121. .requestData(config.URL.USERSIGNIN, {})
  3122. .then(
  3123. res => {
  3124. console.log('USERSIGNIN:' + JSON.stringify(res));
  3125. if (res.code == 0) {
  3126. state.cGold = res.data.userGold;
  3127. state.cDiamond = res.data.userDiamond;
  3128. uni.showToast({
  3129. title: '签到成功',
  3130. mask: true
  3131. })
  3132. //根据dayType 计算最近一个flag
  3133. for (let i = 0; i < state.signInList.length; i++) {
  3134. if (res.data.signIn.dayType == state.signInList[i].dayType) {
  3135. state.signInList[i] = Object.assign({}, state.signInList[i], res.data
  3136. .signIn);
  3137. break;
  3138. }
  3139. }
  3140. state.isSignIn = true;
  3141. if (callback)
  3142. callback(res.data);
  3143. } else if (res.code == 901) {
  3144. uni.showToast({
  3145. title: '今天已签到',
  3146. mask: true
  3147. })
  3148. }
  3149. },
  3150. e => {
  3151. console.log(e);
  3152. }
  3153. );
  3154. },
  3155. onSendSignInPopup(state, context) {
  3156. let {
  3157. type,
  3158. item
  3159. } = context;
  3160. let _reward = [{
  3161. name: 'gold',
  3162. width: 28,
  3163. height: 28,
  3164. url: '../../../static/common/sideBar/sGold.png',
  3165. selectedUrl: '../../../static/common/subNVue/sign/sign-grey-gold@2x.png',
  3166. explain: '',
  3167. value: 20,
  3168. isSelect: false
  3169. },
  3170. {
  3171. name: 'diamond',
  3172. width: 28,
  3173. height: 28,
  3174. url: '../../../static/common/sideBar/sDiamond.png',
  3175. selectedUrl: '../../../static/common/subNVue/sign/sign-grey-diamond@2x.png',
  3176. explain: '',
  3177. value: 20,
  3178. isSelect: false
  3179. }
  3180. ];
  3181. let list = state.signInList;
  3182. let lists = [];
  3183. for (let i = 0; i < list.length; i++) {
  3184. if (0 !== list[i].gold) {
  3185. lists.push(Object.assign({}, _reward[0], {
  3186. value: list[i].gold
  3187. }))
  3188. } else if (0 !== list[i].diamond) {
  3189. lists.push(Object.assign({}, _reward[1], {
  3190. value: list[i].diamond
  3191. }))
  3192. }
  3193. lists[i].isSelect = list[i].flag == 1 ? true : false;
  3194. }
  3195. // 向 popup 传递消息
  3196. uni.$emit('reward-popup', {
  3197. title: '每日签到',
  3198. content: '',
  3199. type: type,
  3200. lists: lists,
  3201. isSignIn: state.isSignIn
  3202. });
  3203. }
  3204. }
  3205. })
  3206. export default store