device.vue 7.0 KB

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