connecting.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <div>
  3. <van-row class="padding">
  4. <van-col span="5">
  5. <div class="device_bg flex flex-direction align-center justify-center">
  6. <img
  7. src="https://img.shuimuai.com/web/phone.png"
  8. alt=""
  9. class="device_phone"
  10. >
  11. <text class="text-gray device_text"> 我的手机</text>
  12. </div>
  13. </van-col>
  14. <van-col
  15. span="3"
  16. offset="1"
  17. >
  18. <div class="dot_container flex align-center">
  19. <div class="dot_wait">
  20. <img
  21. src="https://img.shuimuai.com/m_sign_gou%402x.png"
  22. alt=""
  23. class="moving_dot"
  24. >
  25. </div>
  26. </div>
  27. </van-col>
  28. <van-col
  29. span="5"
  30. offset="0"
  31. >
  32. <div class="device_bg flex flex-direction align-center justify-center">
  33. <img
  34. src="https://img.shuimuai.com/web/sign_green.png"
  35. alt=""
  36. class="sign_green"
  37. v-if="device_bg == true"
  38. >
  39. <img
  40. src="https://img.shuimuai.com/web/sign_red.png"
  41. class="sign_green"
  42. alt=""
  43. v-else
  44. >
  45. <img
  46. src="https://img.shuimuai.com/web/brain.png"
  47. alt=""
  48. class="device_brain"
  49. >
  50. <text class="text-gray device_text second_device_text"> 已连接({{device_power}}%)</text>
  51. </div>
  52. </van-col>
  53. <van-col
  54. span="3"
  55. offset="1"
  56. >
  57. <div class="dot_container flex align-center">
  58. <div class="dot_wait">
  59. <img
  60. v-if="connect_toy == 1"
  61. src="https://img.shuimuai.com/web/dot.png"
  62. alt=""
  63. class="moving_dot"
  64. :class="{moving:connect_toy==1}"
  65. />
  66. <img
  67. v-if="connect_toy == 2"
  68. src="https://img.shuimuai.com/m_sign_gou%402x.png"
  69. alt=""
  70. class="moving_dot"
  71. >
  72. <img
  73. v-if="connect_toy == 3"
  74. src="https://img.shuimuai.com/fail.png"
  75. alt=""
  76. class="moving_dot"
  77. >
  78. </div>
  79. </div>
  80. </van-col>
  81. <van-col
  82. span="5"
  83. offset="0"
  84. >
  85. <div class="device_bg flex flex-direction align-center justify-center">
  86. <img
  87. :src="toy['img']"
  88. alt=""
  89. class="uav_toy"
  90. >
  91. <text class="text-gray device_text">
  92. <template v-if="connect_toy == 1 || connect_toy == 3">
  93. {{ toy['name'] }}
  94. </template>
  95. <template v-if="connect_toy == 2 || connect_toy == 4">
  96. {{ toy_sn }}
  97. </template>
  98. </text>
  99. </div>
  100. </van-col>
  101. </van-row>
  102. <!-- 按钮组合-->
  103. <van-row gutter="6">
  104. <van-col span="8">
  105. <button
  106. class="cu-btn bg-red lg text-white"
  107. @click="change_status"
  108. >
  109. <img
  110. src="https://img.shuimuai.com/m_duankainaohuan.png"
  111. class="cut_brain_icon"
  112. alt=""
  113. >
  114. <text class=" cut_text">断开脑环</text>
  115. </button>
  116. </van-col>
  117. <van-col
  118. span="12"
  119. offset="1"
  120. v-if="connect_toy == 1"
  121. >
  122. <van-row class="text-center">
  123. <text class="text-gray text-lg">
  124. 连接中...
  125. </text>
  126. </van-row>
  127. </van-col>
  128. <!-- 已经连接玩具-->
  129. <div v-if="connect_toy == 2">
  130. <van-col span="8">
  131. <button
  132. class="cu-btn bg-red lg cu-btn-primary"
  133. @click="open_choose_toy"
  134. >
  135. <img
  136. src="https://img.shuimuai.com/m_xuanzewanju.png"
  137. alt=""
  138. class="cut_brain_icon"
  139. >
  140. <text class=" cut_text">选择玩具</text>
  141. </button>
  142. </van-col>
  143. <van-col span="8">
  144. <button
  145. class="cu-btn bg-red lg cu-btn-primary"
  146. @click="choose_pay_window"
  147. >
  148. <img
  149. src="https://img.shuimuai.com/web/start_game_icon.png"
  150. alt=""
  151. class="cut_start_game_icon"
  152. >
  153. <text
  154. class=" cut_text"
  155. style="padding: 0px;"
  156. >开始训练</text>
  157. </button>
  158. </van-col>
  159. </div>
  160. <!-- 玩具连接失败-->
  161. <div v-if="connect_toy == 3">
  162. <van-col span="8">
  163. <button
  164. class="cu-btn bg-red lg cu-btn-primary"
  165. @click="open_choose_toy"
  166. >
  167. <img
  168. src="https://img.shuimuai.com/m_xuanzewanju.png"
  169. alt=""
  170. class="cut_brain_icon"
  171. >
  172. <text class=" cut_text">选择玩具</text>
  173. </button>
  174. </van-col>
  175. <van-col span="8">
  176. <van-row class="text-center">
  177. <text class="text-gray text-lg">
  178. 连接失败
  179. </text>
  180. </van-row>
  181. </van-col>
  182. </div>
  183. <!-- 玩具连接中-->
  184. <div v-if="connect_toy == 4">
  185. <!-- <van-col span="8" style="visibility: hidden">-->
  186. <!-- <button class="cu-btn bg-red lg cu-btn-primary" @click="open_choose_toy">-->
  187. <!-- <img src="https://img.shuimuai.com/m_xuanzewanju.png" alt="" class="cut_brain_icon">-->
  188. <!-- <text class=" cut_text">选择玩具</text>-->
  189. <!-- </button>-->
  190. <!-- </van-col>-->
  191. <van-col span="16">
  192. <button
  193. class="cu-btn bg-green lg "
  194. @click="to_playing"
  195. style="width: 100%"
  196. >
  197. <img
  198. src="https://img.shuimuai.com/web/start_game_icon.png"
  199. alt=""
  200. class="cut_start_game_icon"
  201. >
  202. <text
  203. class=" cut_text"
  204. style="padding: 0px;"
  205. >游戏中</text>
  206. </button>
  207. </van-col>
  208. </div>
  209. </van-row>
  210. <!-- 选择消费方式的窗口 -->
  211. <van-overlay
  212. :show="pay_window"
  213. @click="onClickHide"
  214. z-index="5"
  215. >
  216. <div class="pay_type_window">
  217. <div class="pay_type_title padding">
  218. <text class="text-bold pay_type_title_text">选择消费方式</text>
  219. </div>
  220. <van-row gutter="11">
  221. <van-col
  222. span="11"
  223. offset="1"
  224. >
  225. <div
  226. class="pay_type_item flex flex-direction justify-center align-center"
  227. @click.prevent="choose_pay(2)"
  228. >
  229. <view class="text-xl padding">
  230. <text class="text-white text-bold">消费时间</text>
  231. </view>
  232. </div>
  233. </van-col>
  234. <van-col span="11">
  235. <div
  236. class="pay_type_item flex flex-direction justify-center align-center"
  237. @click.prevent="choose_pay(1)"
  238. >
  239. <view class="text-xl padding">
  240. <text class="text-white text-bold">消费次卡</text>
  241. </view>
  242. <view class="text-sm">
  243. <text class="text-white">次卡时间为10分钟</text>
  244. </view>
  245. </div>
  246. </van-col>
  247. </van-row>
  248. </div>
  249. <img
  250. src="https://img.shuimuai.com/web/boy2.png"
  251. alt=""
  252. class="connected_boy2"
  253. >
  254. </van-overlay>
  255. <van-toast id="van-toast" />
  256. <van-popup
  257. :show="start_show"
  258. closeable
  259. position="bottom"
  260. custom-style="height: 100%"
  261. >
  262. <view>
  263. <text>游戏中界面</text>
  264. </view>
  265. </van-popup>
  266. </div>
  267. </template>
  268. <script>
  269. import { timestamp } from "@/requests/user";
  270. import { gameStart } from "@/requests/game";
  271. import Toast from "../../../../static/vant/toast/toast";
  272. import game_store from "../../../store/game";
  273. let $this;
  274. export default {
  275. name: "connected",
  276. props: [
  277. "connect_toy",
  278. "toy_id",
  279. "toy",
  280. "device_bg",
  281. "device_power",
  282. "toy_power",
  283. "toy_sn",
  284. ],
  285. data() {
  286. return {
  287. pay_window: false,
  288. // 使用类型 1次数 2时间 0未选择
  289. pay_type: 0,
  290. start_show: false,
  291. };
  292. },
  293. methods: {
  294. open_choose_toy() {
  295. $this.$emit("open_choose_toy", true);
  296. },
  297. //打开选择消费的选项框
  298. choose_pay_window() {
  299. if (!$this.device_bg) {
  300. Toast.fail("请佩戴好脑环开始训练");
  301. return false;
  302. }
  303. if(wx.getStorageSync("userinfo").level == 11){
  304. $this.choose_pay(2)
  305. }else{
  306. $this.pay_window = true;
  307. }
  308. },
  309. //选择消费的时间或者次数
  310. choose_pay($event) {
  311. if (!$this.device_bg) {
  312. Toast.fail("请佩戴好脑环开始训练");
  313. return false;
  314. }
  315. $this.pay_type = $event;
  316. let $params = {
  317. type: $event,
  318. device_id: $this.toy_id,
  319. access_token: wx.getStorageSync("token"),
  320. };
  321. gameStart($params).then(
  322. (res) => {
  323. // 重置断开脑环的状态
  324. game_store.setters.setGameCloseStatus(0);
  325. let $data = res.data;
  326. let $res = $data.data;
  327. if ($data.code == 0) {
  328. // 设置游戏中
  329. // 设置游戏模式
  330. game_store.setters.setMode($event);
  331. // 设置游戏状态为游戏中
  332. // game_store.setters.setGameStatus(1);
  333. // 设置游戏记录id
  334. game_store.setters.setGameRecordId($res["game_record_id"]);
  335. //打开脑控
  336. $this.$bluetooth.sendControl();
  337. Toast.success($data.errmsg);
  338. game_store.setters.setPlayTime($res["play_time"]);
  339. game_store.setters.setOverPlayTime($res["play_time"]);
  340. // setTimeout(() => {
  341. // mpvue.navigateTo({
  342. // url: "/pages/start/main",
  343. // success() {
  344. // // 记录消费方式 选择时间卡还是次卡
  345. // $this.$emit("gameStart", true);
  346. // },
  347. // });
  348. // }, 800);
  349. } else {
  350. Toast.fail($data.errmsg);
  351. }
  352. },
  353. (err) => {
  354. console.log(err);
  355. }
  356. );
  357. },
  358. //点击隐藏
  359. onClickHide() {
  360. $this.pay_window = false;
  361. },
  362. // 前往正在玩的波动时间界面
  363. to_playing() {
  364. $this.$emit("gameStart", true);
  365. mpvue.navigateTo({
  366. url: "/pages/start/main",
  367. });
  368. },
  369. //修改连接状态
  370. change_toy_connect_status($status) {
  371. $this.$emit("change_toy_connect_status", $status);
  372. },
  373. change_status() {
  374. $this.$emit("change_status", 0);
  375. },
  376. },
  377. created() {
  378. $this = this;
  379. },
  380. };
  381. </script>
  382. <style scoped>
  383. .uav_toy {
  384. width: 47px;
  385. height: 47px;
  386. }
  387. .cut_text {
  388. padding: 0px 5px;
  389. font-size: 11px;
  390. }
  391. .cut_start_game_icon {
  392. width: 21px;
  393. height: 23px;
  394. }
  395. /*消费类型窗口*/
  396. .pay_type_window {
  397. width: 95%;
  398. height: 180px;
  399. background-image: url("https://img.shuimuai.com/web/dialog.png");
  400. background-position: center;
  401. background-size: 100% 100%;
  402. position: absolute;
  403. bottom: 225px;
  404. right: 10px;
  405. }
  406. .pay_type_title_text {
  407. color: #6b6b6b;
  408. font-size: 12px;
  409. }
  410. .pay_type_item {
  411. width: 100%;
  412. height: 100px;
  413. background-image: url("https://img.shuimuai.com/web/pay_type_bg.png");
  414. background-position: center;
  415. background-size: 100% 100%;
  416. }
  417. .connected_boy2 {
  418. width: 60px;
  419. height: 82px;
  420. position: absolute;
  421. right: 0px;
  422. bottom: 160px;
  423. }
  424. </style>