device.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div id="device_container" class="padding-lr">
  3. <div class="device">
  4. <div class="head flex justify-between">
  5. <div>
  6. <div class="line"></div>
  7. <div class="title">我的设备</div>
  8. </div>
  9. <div class="my_msg">
  10. <text class="cuIcon-mark"></text>
  11. <text class="under_line">消息中心</text>
  12. </div>
  13. </div>
  14. <div v-if="connect_toy==0">
  15. <!-- 未连接部分-->
  16. <div class="connect_box" v-if="status == 0">
  17. <device_unconnect @open_scan="open_scan"></device_unconnect>
  18. </div>
  19. <!-- 连接中-->
  20. <div class="connecting_box" v-if="status != 0 && connect_show == false">
  21. <device_connecting :status="status"></device_connecting>
  22. </div>
  23. <!-- 已链接 -->
  24. <div class="connected_box" v-if="connect_show">
  25. <device_connected @open_choose_toy="open_choose_toy"></device_connected>
  26. </div>
  27. </div>
  28. <div v-else>
  29. <!-- 玩具模块-->
  30. <!-- 玩具连接中-->
  31. <div class="connecting_toy">
  32. <toy_connecting :connect_toy="connect_toy" @open_choose_toy="open_choose_toy" @change_toy_connect_status="change_toy_connect_status"></toy_connecting>
  33. </div>
  34. </div>
  35. </div>
  36. <!-- 选择玩具-->
  37. <van-popup :show="choose_toy_window.show" @close="on_close"
  38. position="bottom"
  39. round
  40. closeable
  41. safe-area-inset-bottom
  42. >
  43. <div class="head padding">
  44. <div>
  45. <div class="line"></div>
  46. <div class="title">选择玩具</div>
  47. </div>
  48. </div>
  49. <div class="padding toy_list">
  50. <van-row gutter="8">
  51. <van-col span="8" v-for="(toy,index) in toy_list" :key="index">
  52. <div class="toy_item flex flex-direction justify-center align-center"
  53. @click="choose_toy(index)"
  54. :class="toy_action == toy.id?'toy_item_action_bg':'toy_item_normal_bg'">
  55. <img :src="toy.img" alt="" class="toy_img">
  56. <text class="toy_text padding-top">{{ toy.name }}</text>
  57. </div>
  58. </van-col>
  59. </van-row>
  60. </div>
  61. <div class="toy_actions padding text-center">
  62. <view class="text-gray toy_action_text padding">选择你最感兴趣的项目,点击“选好了”以后将会自动连接</view>
  63. <button class="cu-btn lg cu-btn-primary text-white text-center padding" @click="choose_ok">选好了</button>
  64. </div>
  65. </van-popup>
  66. </div>
  67. </template>
  68. <script>
  69. //蓝牙未连接
  70. import device_unconnect from "@/components/device/unconnect";
  71. //蓝牙连接中
  72. import device_connecting from "@/components/device/connecting";
  73. //蓝牙完成链接
  74. import device_connected from '@/components/device/connected';
  75. //连接玩具
  76. import toy_connecting from '@/components/device/toy/connecting'
  77. let $this;
  78. export default {
  79. name: "device",
  80. components: {
  81. device_unconnect, device_connecting, device_connected, toy_connecting
  82. },
  83. data() {
  84. return {
  85. //设备状态 0为未连接,1:连接中,2:已连接 3:连接失败
  86. status: 0,
  87. choose_toy_window: {
  88. show: false
  89. },
  90. toy_list: [
  91. {
  92. id: 1,
  93. name: "智能喷泉",
  94. img: "https://img.shuimuai.com/web/toy_car.png"
  95. },
  96. {
  97. id: 2,
  98. name: "智能喷雾恐龙",
  99. img: "https://img.shuimuai.com/web/toy_dinasour.png"
  100. },
  101. {
  102. id: 3,
  103. name: "智能喷雾恐龙2",
  104. img: "https://img.shuimuai.com/web/toy_dinasour.png"
  105. },
  106. {
  107. id: 4,
  108. name: "智能轨道车",
  109. img: "https://img.shuimuai.com/web/toy_car_roat.png"
  110. },
  111. {
  112. id: 5,
  113. name: "智能越野车",
  114. img: "https://img.shuimuai.com/web/toy_car.png"
  115. },
  116. {
  117. id: 6,
  118. name: "智能越野车2",
  119. img: "https://img.shuimuai.com/web/toy_car.png"
  120. },
  121. ],
  122. toy_action: 1,
  123. connect_show: false,
  124. //连接玩具 0:未连接 1:连接中 2:已连接 3:连接失败 4:游戏中
  125. connect_toy: 0
  126. }
  127. },
  128. watch: {
  129. status(newStatus, oldStatus) {
  130. if (oldStatus == 0 && newStatus == 1) {
  131. setTimeout(() => {
  132. $this.success_connected()
  133. }, 2000)
  134. }
  135. },
  136. connect_toy($new, $old) {
  137. if ($old == 0 && $new == 1) {
  138. setTimeout(() => {
  139. $this.connect_toy = 2
  140. }, 2000)
  141. }
  142. }
  143. },
  144. methods: {
  145. //打开 扫描二维码
  146. open_scan() {
  147. let $this = this
  148. wx.scanCode({
  149. success: (res) => {
  150. let $data = res
  151. if ($data.result) {
  152. $this.status = 1
  153. }
  154. }
  155. })
  156. },
  157. //成功连接的方法
  158. success_connected() {
  159. $this.status = 2
  160. setTimeout(() => {
  161. $this.connect_show = true
  162. }, 2000)
  163. },
  164. //关闭窗口的方法
  165. on_close() {
  166. $this.choose_toy_window.show = false
  167. },
  168. //选择玩具
  169. choose_toy($index) {
  170. $this.toy_action = $this.toy_list[$index].id
  171. },
  172. // 打开选择玩具窗口
  173. open_choose_toy() {
  174. $this.choose_toy_window.show = true
  175. },
  176. // 选好玩具
  177. choose_ok() {
  178. $this.on_close()
  179. $this.change_toy_connect_status(1)
  180. },
  181. change_toy_connect_status($status = 0) {
  182. $this.connect_toy = $status
  183. }
  184. },
  185. created() {
  186. $this = this
  187. }
  188. }
  189. </script>
  190. <style scoped>
  191. @import "../static/device.css";
  192. </style>