| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <template>
- <div class="wrapper">
- <div class="info">
- <div
- v-for="item in items"
- :key="item.id"
- class="item"
- >
- <div class="label">{{ item.label }}</div>
- <div class="value">{{ device[item.key] }}</div>
- </div>
- </div>
- <div class="buttons">
- <el-button
- class="o-button"
- icon="el-icon-switch-button"
- @click="onSwitch(true)"
- >开机</el-button>
- <el-button
- class="o-button"
- icon="el-icon-switch-button"
- @click="onSwitch(false)"
- >关机</el-button>
- <el-button
- :loading="rebooting"
- class="o-button"
- icon="el-icon-refresh-right"
- @click="invoke"
- >重启</el-button>
- </div>
- </div>
- </template>
- <script>
- import { publish } from '@/utils/mqtt'
- import { send } from '../../monitor'
- export default {
- props: {
- device: {
- type: Object,
- required: true
- },
- online: {
- type: Boolean,
- required: true
- }
- },
- data () {
- return {
- rebooting: false,
- openFunctionKey: 'bootDevice',
- closeFunctionKey: 'shutdownDevice',
- items: [
- {
- label: '名称',
- key: 'name'
- },
- {
- label: 'MAC',
- key: 'mac'
- },
- {
- label: '序列号',
- key: 'serialNumber'
- },
- {
- label: '分辨率',
- key: 'resolutionRatio'
- }
- ]
- }
- },
- watch: {
- online () {
- this.rebooting = false
- }
- },
- methods: {
- onSwitch (open) {
- if (!this.online) {
- this.$message({
- type: 'warning',
- message: '设备未上线,请稍后再试'
- })
- return
- }
- this.$confirm(`立即${open ? '开机' : '关机'}?`, {
- type: 'warning'
- }).then(() => {
- this.sendTopic(open ? this.openFunctionKey : this.closeFunctionKey)
- })
- },
- invoke () {
- if (this.rebooting) {
- return
- }
- if (!this.online) {
- this.$message({
- type: 'warning',
- message: '设备未上线,请稍后再试'
- })
- return
- }
- this.$confirm(`重启 ${this.device.name} ?`, { type: 'warning' }).then(
- () => {
- send('/restart/ask').then(
- () => {
- this.rebooting = true
- },
- () => {
- this.$message({
- type: 'warning',
- message: '正在连接,请稍后再试'
- })
- }
- )
- }
- )
- },
- sendTopic (invoke, inputs = []) {
- console.log(invoke, inputs)
- publish(
- `${this.device.productId}/${this.deviceId}/function/invoke`,
- JSON.stringify({
- timestamp: Date.now(),
- function: invoke,
- inputs
- }),
- true
- ).then(
- () => {
- this.$message({
- type: 'success',
- message: '执行成功'
- })
- },
- () => {
- this.$message({
- type: 'warning',
- message: '正在连接,请稍后再试'
- })
- }
- )
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .wrapper {
- width: 100%;
- display: flex;
- align-items: center;
- .info {
- display: flex;
- align-items: center;
- background-color: #232b45;
- line-height: 40px;
- margin-right: 16px;
- flex: 1;
- .item {
- display: flex;
- flex: 1;
- align-items: center;
- .label {
- text-align: center;
- flex: 1;
- color: #9ea9cd;
- }
- .value {
- text-align: center;
- flex: 1;
- color: #fff;
- }
- }
- }
- .buttons {
- ::v-deep.el-button+.el-button{
- margin-left: 16px;
- }
- }
- }
- </style>
|