最近需要使用vue开发XixunPlayer的功能,记录一下.实现设备的开关机
实现设备的开关机
/**
* @Author: 858834013@qq.com
* @Name: onOff
* @Date: 2022-01-18
* @Desc: XixunPlayer实现设备的开关机
*/
<template>
<div class="status">
<div v-if="status=='on'" @click="toTurnItOff(false)">
<el-button class="mb20" size="mini" type="danger">关机</el-button>
</div>
<div v-else @click="toTurnItOff(true)">
<el-button class="mb20" size="mini" type="primary">开机</el-button>
</div>
</div>
</template>
<script>
import { getdata } from '@/api/led/led'
export default {
components: {},
data () {
return {
result: false,
}
},
mounted: function () {
},
props: {
id: {
type: String,
default () {
return ''
}
},
status: {
type: String,
default () {
return 'off'
}
},
},
methods: {
getdata () {
var that = this
getdata(that.id, {
'type': 'callCardService',
'fn': 'isScreenOpen'
}).then(function (res) {
that.result = res.result
that.$emit('getdata', that.result)
})
},
// 开关机
toTurnItOff (arg) {
var that = this
getdata(that.id, {
'type': 'callCardService',
'fn': 'setScreenOpen',
'arg1': arg
}).then(function (res) {
that.getdata()
if (res.arg1) {
that.$message({
message: '开机成功',
type: 'success'
})
} else {
that.$message({
message: '关机成功',
type: 'success'
})
}
})
},
},
}
</script>
<style lang='scss' scoped>
.status {
display: flex;
justify-content: flex-start;
align-items: center;
flex-wrap: nowrap;
flex-direction: row;
align-content: flex-start;
}
</style>