123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- <template>
- <view class="content">
- <!-- <view class="dbox">
- <button @click="addDevice">添加设备</button>
- <button @click="getPlayInfo">获取播放信息</button>
- <button @click="getDeviceInfo">获取设备信息</button>
- </view> -->
- <view class="dbox">
- <button @click="addDevice" class="btn">+</button>
- <device-card v-for="(device, index) in deviceList" :key="index" :device="device"></device-card>
- <!-- <device-card v-if="currentDevice" :device="currentDevice"/> -->
- </view>
- <view class="play-info">
- <image class="play-thmub" :src="playInfo.albumURI" mode="aspectFit" />
- <text style="margin-top: 20rpx">{{ playInfo.title }}</text>
- <text style="margin-top: 20rpx">{{ playInfo.artist }}</text>
- </view>
- <view class="play-ctrl">
- <image src="../../../static/demo/previous.png" class="next-icon" @click="previous" />
- <image v-if="playInfo.PlayState != 1" src="../../../static/demo/play.png" class="next-icon" @click="play" />
- <image v-if="playInfo.PlayState == 1" src="../../../static/demo/pause.png" class="next-icon"
- @click="pause" />
- <image src="../../../static/demo/next.png" class="next-icon" @click="next" />
- </view>
- <text style="margin-top: 20rpx; margin-left: 50rpx">音量</text>
- <slider :value="currentDevice && currentDevice.Volume ? currentDevice.Volume : 0" class="progress" min="0"
- max="100" step="1" @change="setVolume" show-value></slider>
- <text style="margin-top: 10rpx; margin-left: 50rpx">频道</text>
- <slider :value="playInfo.channel" class="progress" min="0" max="11" step="1" @change="setChannel" show-value>
- </slider>
- </view>
- </template>
- <script>
- import deviceCard from "../../../components/demo/deviceCard.vue";
- import {
- mapState
- } from "vuex";
- export default {
- components: {
- deviceCard
- },
- data() {
- return {
- //deviceList:[]
- };
- },
- onLoad() {
- //this.deviceList = this.$store.state.moduleMqtt.deviceList;
- uni.$on("mqtt_onoffline", this.onofflineCallback);
- },
- onUnload() {
- uni.$off("mqtt_onoffline", this.onofflineCallback);
- },
- methods: {
- onofflineCallback(value) {
- //console.log("onofflineCallback");
- },
- //测试添加设备
- addDevice() {
- if (getApp().globalData.uid) {
- //添加设备
- // this.$store.dispatch({
- // type: "moduleMqtt/addDevice",
- // clientId: `wx_${getApp().globalData.uid}`,
- // device: {
- // devName: "MW-V",
- // uuid: "89860474192070498495",
- // },
- // });
- uni.navigateTo({
- url:'../../addDevice/selectDevice/selectDevice'
- })
- }else{
- uni.showModal({
- title:"温馨提示",
- content:"请登录!",
- success() {
- uni.navigateTo({
- url:'../../login/login'
- })
- }
- })
- }
- },
- //获取播放信息
- getPlayInfo() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "get_position",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //获取设备信息
- getDeviceInfo() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "get_dev_info",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //下一曲
- next() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "next",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //上一曲
- previous() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "previous",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //播放
- play() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "play",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //暂停
- pause() {
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "pause",
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //设置音量
- setVolume(event) {
- console.log(event.target.value);
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "volume_set",
- other: {
- volume: event.target.value,
- },
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- //设置频道
- setChannel(event) {
- console.log(event.target.value);
- this.$store
- .dispatch({
- type: "moduleMqtt/publishWithType",
- mqttType: "play",
- other: {
- user_id: "650633",
- timestamp: "", //暂时没有时间戳,先不填
- channel_id: event.target.value + "",
- url: "",
- media_data: "",
- order: "",
- resource_from: "",
- },
- })
- .then((result) => {})
- .catch((err) => {
- console.warn(err);
- });
- },
- goDeviceInfo() {
- //console.log("goDeviceInfo");
- uni.navigateTo({
- url: "./deviceInfo",
- complete(res) {
- console.warn(res);
- }
- });
- },
- godoBle() {
- //添加设备
- // #ifdef MP-WEIXIN||APP-PLUS
- uni.navigateTo({
- url: "../ble/ScanBleDevice",
- });
- // #endif
- // #ifdef H5
- uni.navigateTo({
- url: "../ble/ConnectBleDevice",
- });
- // uni.showToast({
- // title:'H5页面不支持扫描设备',
- // icon:'none'
- // })
- // #endif
- },
- },
- computed: {
- // deviceList() {
- // return this.$store.state.moduleMqtt.deviceList;
- // },
- ...mapState({
- deviceList: (state) => state.moduleMqtt.deviceList,
- playInfo: (state) => state.moduleMqtt.playInfo,
- currentDevice: (state) => state.moduleMqtt.currentDevice,
- }),
- },
- };
- </script>
- <style>
- .content {
- display: flex;
- flex-direction: column;
- }
- .play-info {
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .dbox {
- display: flex;
- flex-direction: row;
- width: 100vw;
- justify-content: flex-start;
- }
- .btn {
- margin-left: 0rpx;
- margin-right: 10rpx;
- width: 160rpx;
- height: 25vw;
- /* display: flex; */
- /* justify-content: center;
- align-items: center; */
- line-height: 25vw;
- border: 1rpx solid #333333;
- font-size: 120rpx;
- }
- .text1 {
- width: 150px;
- word-break: break-all;
- /* text-overflow:ellipsis;
- overflow: hidden;
- white-space: nowrap; */
- }
- .play-thmub {
- display: flex;
- align-self: center;
- width: 300rpx;
- height: 300rpx;
- margin-top: 30rpx;
- }
- .play-ctrl {
- display: flex;
- flex-direction: row;
- justify-content: space-around;
- margin-top: 40rpx;
- }
- .next-icon {
- width: 54rpx;
- height: 60rpx;
- }
- .progress {
- align-self: center;
- width: 80vw;
- }
- </style>
|