device.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="content">
  3. <button @click="addDevice">添加设备</button>
  4. <button @click="getPlayInfo">获取播放信息</button>
  5. <button @click="getDeviceInfo">获取设备信息</button>
  6. <view class="dbox">
  7. <device-card
  8. v-for="(device, index) in deviceList"
  9. :key="index"
  10. :device="device"
  11. ></device-card>
  12. <!-- <text v-for="(device, index) in deviceList" :key="index" space="ensp"
  13. >{{ device.name }} {{ device.online }}</text
  14. > -->
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import deviceCard from "../../components/deviceCard/deviceCard.vue";
  20. import { mapState } from "vuex";
  21. export default {
  22. components: { deviceCard },
  23. data() {
  24. return {
  25. //deviceList:[]
  26. };
  27. },
  28. onLoad() {
  29. //this.deviceList = this.$store.state.moduleMqtt.deviceList;
  30. uni.$on("mqtt_onoffline", this.onofflineCallback);
  31. },
  32. onUnload() {
  33. uni.$off("mqtt_onoffline", this.onofflineCallback);
  34. },
  35. methods: {
  36. onofflineCallback(value) {
  37. console.log("onofflineCallback");
  38. },
  39. //测试添加设备
  40. addDevice() {
  41. //添加设备
  42. this.$store.dispatch({
  43. type: "moduleMqtt/addDevice",
  44. clientId: "wx_18126447015",
  45. device: {
  46. name: "MW-M3",
  47. uuid: "89860474192070498495",
  48. },
  49. });
  50. },
  51. //获取播放信息
  52. getPlayInfo() {
  53. this.$store.dispatch({
  54. type: "moduleMqtt/publishWithType",
  55. mqttType: "get_position",
  56. }).then((result) => {
  57. }).catch((err) => {
  58. console.warn(err);
  59. });
  60. },
  61. //获取播放信息
  62. getDeviceInfo() {
  63. this.$store.dispatch({
  64. type: "moduleMqtt/publishWithType",
  65. mqttType: "get_dev_info",
  66. }).then((result) => {
  67. }).catch((err) => {
  68. console.warn(err);
  69. });
  70. },
  71. godoBle() {
  72. //添加设备
  73. // #ifdef MP-WEIXIN||APP-PLUS
  74. uni.navigateTo({
  75. url: "../ble/ScanBleDevice",
  76. });
  77. // #endif
  78. // #ifdef H5
  79. uni.navigateTo({
  80. url: "../ble/ConnectBleDevice",
  81. });
  82. // uni.showToast({
  83. // title:'H5页面不支持扫描设备',
  84. // icon:'none'
  85. // })
  86. // #endif
  87. },
  88. },
  89. computed: {
  90. // deviceList() {
  91. // return this.$store.state.moduleMqtt.deviceList;
  92. // },
  93. ...mapState({
  94. deviceList: (state) => state.moduleMqtt.deviceList,
  95. }),
  96. },
  97. };
  98. </script>
  99. <style>
  100. .content {
  101. margin: 20rpx;
  102. }
  103. .dbox {
  104. display: flex;
  105. flex-direction: row;
  106. }
  107. .text1 {
  108. width: 150px;
  109. word-break: break-all;
  110. /* text-overflow:ellipsis;
  111. overflow: hidden;
  112. white-space: nowrap; */
  113. }
  114. </style>