device.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="content">
  3. <view class="dbox">
  4. <button @click="addDevice">添加设备</button>
  5. <!-- <button @click="getPlayInfo">获取播放信息</button> -->
  6. <button @click="getDeviceInfo">获取设备信息</button>
  7. </view>
  8. <view class="dbox">
  9. <device-card
  10. v-for="(device, index) in deviceList"
  11. :key="index"
  12. :device="device"
  13. ></device-card>
  14. <!-- <text v-for="(device, index) in deviceList" :key="index" space="ensp"
  15. >{{ device.name }} {{ device.online }}</text
  16. > -->
  17. </view>
  18. <view class="play-info">
  19. <image class="play-thmub" :src="playInfo.albumURI" mode="aspectFit" />
  20. <text style="margin-top: 30rpx">{{ playInfo.title }}</text>
  21. <text style="margin-top: 30rpx">{{ playInfo.artist }}</text>
  22. </view>
  23. <view class="play-ctrl">
  24. <image src="../../static/image/play/previous.png" class="next-icon" @click="previous"/>
  25. <image
  26. v-if="playInfo.PlayState != 1"
  27. src="../../static/image/play/play.png"
  28. class="next-icon"
  29. @click="play"
  30. />
  31. <image
  32. v-if="playInfo.PlayState == 1"
  33. src="../../static/image/play/pause.png"
  34. class="next-icon"
  35. @click="pause"
  36. />
  37. <image src="../../static/image/play/next.png" class="next-icon" @click="next"/>
  38. </view>
  39. <text style="margin-top: 30rpx; margin-left:50rpx">音量</text>
  40. <slider value="20" class="progress" min="0" max="100" step="1" @change="setVolume" show-value></slider>
  41. <text style="margin-top: 30rpx; margin-left:50rpx">频道</text>
  42. <slider :value="playInfo.channel" class="progress" min="0" max="11" step="1" @change="setChannel" show-value></slider>
  43. </view>
  44. </template>
  45. <script>
  46. import deviceCard from "../../components/deviceCard/deviceCard.vue";
  47. import { mapState } from "vuex";
  48. export default {
  49. components: { deviceCard },
  50. data() {
  51. return {
  52. //deviceList:[]
  53. };
  54. },
  55. onLoad() {
  56. //this.deviceList = this.$store.state.moduleMqtt.deviceList;
  57. uni.$on("mqtt_onoffline", this.onofflineCallback);
  58. },
  59. onUnload() {
  60. uni.$off("mqtt_onoffline", this.onofflineCallback);
  61. },
  62. methods: {
  63. onofflineCallback(value) {
  64. //console.log("onofflineCallback");
  65. },
  66. //测试添加设备
  67. addDevice() {
  68. //添加设备
  69. this.$store.dispatch({
  70. type: "moduleMqtt/addDevice",
  71. clientId: "wx_650633",
  72. device: {
  73. name: "MW-M3",
  74. uuid: "89860474192070498495",
  75. },
  76. });
  77. },
  78. //获取播放信息
  79. getPlayInfo() {
  80. this.$store
  81. .dispatch({
  82. type: "moduleMqtt/publishWithType",
  83. mqttType: "get_position",
  84. })
  85. .then((result) => {})
  86. .catch((err) => {
  87. console.warn(err);
  88. });
  89. },
  90. //获取设备信息
  91. getDeviceInfo() {
  92. this.$store
  93. .dispatch({
  94. type: "moduleMqtt/publishWithType",
  95. mqttType: "get_dev_info",
  96. })
  97. .then((result) => {})
  98. .catch((err) => {
  99. console.warn(err);
  100. });
  101. },
  102. //下一曲
  103. next() {
  104. this.$store
  105. .dispatch({
  106. type: "moduleMqtt/publishWithType",
  107. mqttType: "next",
  108. })
  109. .then((result) => {})
  110. .catch((err) => {
  111. console.warn(err);
  112. });
  113. },
  114. //上一曲
  115. previous() {
  116. this.$store
  117. .dispatch({
  118. type: "moduleMqtt/publishWithType",
  119. mqttType: "previous",
  120. })
  121. .then((result) => {})
  122. .catch((err) => {
  123. console.warn(err);
  124. });
  125. },
  126. //播放
  127. play() {
  128. this.$store
  129. .dispatch({
  130. type: "moduleMqtt/publishWithType",
  131. mqttType: "play",
  132. })
  133. .then((result) => {})
  134. .catch((err) => {
  135. console.warn(err);
  136. });
  137. },
  138. //暂停
  139. pause() {
  140. this.$store
  141. .dispatch({
  142. type: "moduleMqtt/publishWithType",
  143. mqttType: "pause",
  144. })
  145. .then((result) => {})
  146. .catch((err) => {
  147. console.warn(err);
  148. });
  149. },
  150. //设置音量
  151. setVolume(event){
  152. console.log(event.target.value);
  153. this.$store
  154. .dispatch({
  155. type: "moduleMqtt/publishWithType",
  156. mqttType: "volume_set",
  157. other:{
  158. 'volume':event.target.value
  159. }
  160. })
  161. .then((result) => {})
  162. .catch((err) => {
  163. console.warn(err);
  164. });
  165. },
  166. //设置频道
  167. setChannel(event){
  168. console.log(event.target.value);
  169. this.$store
  170. .dispatch({
  171. type: "moduleMqtt/publishWithType",
  172. mqttType: "play",
  173. other:{
  174. 'user_id':'650633',
  175. 'timestamp':'1560652541',
  176. 'channel_id':event.target.value+''
  177. }
  178. })
  179. .then((result) => {})
  180. .catch((err) => {
  181. console.warn(err);
  182. });
  183. },
  184. godoBle() {
  185. //添加设备
  186. // #ifdef MP-WEIXIN||APP-PLUS
  187. uni.navigateTo({
  188. url: "../ble/ScanBleDevice",
  189. });
  190. // #endif
  191. // #ifdef H5
  192. uni.navigateTo({
  193. url: "../ble/ConnectBleDevice",
  194. });
  195. // uni.showToast({
  196. // title:'H5页面不支持扫描设备',
  197. // icon:'none'
  198. // })
  199. // #endif
  200. },
  201. },
  202. computed: {
  203. // deviceList() {
  204. // return this.$store.state.moduleMqtt.deviceList;
  205. // },
  206. ...mapState({
  207. deviceList: (state) => state.moduleMqtt.deviceList,
  208. playInfo: (state) => state.moduleMqtt.playInfo,
  209. }),
  210. },
  211. };
  212. </script>
  213. <style>
  214. .content {
  215. margin: 10rpx;
  216. display: flex;
  217. flex-direction: column;
  218. }
  219. .play-info {
  220. display: flex;
  221. flex-direction: column;
  222. align-items: center;
  223. }
  224. .dbox {
  225. display: flex;
  226. flex-direction: row;
  227. }
  228. .text1 {
  229. width: 150px;
  230. word-break: break-all;
  231. /* text-overflow:ellipsis;
  232. overflow: hidden;
  233. white-space: nowrap; */
  234. }
  235. .play-thmub {
  236. display: flex;
  237. align-self: center;
  238. width: 300rpx;
  239. height: 300rpx;
  240. margin-top: 30rpx;
  241. }
  242. .play-ctrl {
  243. display: flex;
  244. flex-direction: row;
  245. justify-content: space-around;
  246. margin-top: 40rpx;
  247. }
  248. .next-icon {
  249. width: 54rpx;
  250. height: 60rpx;
  251. }
  252. .progress{
  253. align-self: center;
  254. width: 80vw;
  255. }
  256. </style>