store.js 87 KB

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