store.js 87 KB

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