|
|
@@ -0,0 +1,348 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <div class="l-flex--row c-sibling-item--v u-color--black u-font-size--sm u-bold">
|
|
|
+ <div class="c-sibling-item">状态</div>
|
|
|
+ <i
|
|
|
+ class="c-sibling-item el-icon-refresh u-font-size has-active"
|
|
|
+ @click="onRefresh"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <schema-table
|
|
|
+ ref="powerTable"
|
|
|
+ class="c-sibling-item--v near"
|
|
|
+ :schema="powerSchema"
|
|
|
+ />
|
|
|
+ <template v-if="hasMulti">
|
|
|
+ <div class="c-sibling-item--v u-color--black u-font-size--sm u-bold">多功能卡定时任务</div>
|
|
|
+ <schema-table
|
|
|
+ ref="multiTable"
|
|
|
+ class="c-sibling-item--v near"
|
|
|
+ :schema="multiTaskSchema"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template v-if="hasRelay">
|
|
|
+ <div class="c-sibling-item--v u-color--black u-font-size--sm u-bold">播控盒定时任务</div>
|
|
|
+ <schema-table
|
|
|
+ ref="relayTable"
|
|
|
+ class="c-sibling-item--v near"
|
|
|
+ :schema="relayTaskSchema"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { toDate } from '@/utils/event'
|
|
|
+import {
|
|
|
+ send,
|
|
|
+ addListener,
|
|
|
+ removeListener
|
|
|
+} from '../../../monitor'
|
|
|
+import { Freq } from '../../DeviceInvoke/mixins/TaskDialog'
|
|
|
+
|
|
|
+const GET_POWER_STATUS = 'GetRealtimePowerSwitchStatusAsync' // 9.2.2.1、获取电源实时状态获取
|
|
|
+const GET_MULTI_POWER_TIMING = 'GetPowerInfoPolicyAsync' // 9.29.1.2、获取多功能卡电源定时控制任务
|
|
|
+const GET_RELAY_POWER_TIMING = 'GetRelayPowerPolicyAsync' // 9.29.1.6、获取本板电源定时控制任务
|
|
|
+
|
|
|
+const ErrorMessage = {
|
|
|
+ TIMEOUT: '暂未获取到操作反馈,请稍后重试',
|
|
|
+ BUSY: '终端被他人占用',
|
|
|
+ PASSWORD: '登录密码错误,请联系管理员',
|
|
|
+ [GET_POWER_STATUS]: '获取电源状态异常,请稍后重试',
|
|
|
+ [GET_MULTI_POWER_TIMING]: '获取多功能卡定时数据异常,请回读查看',
|
|
|
+ [GET_RELAY_POWER_TIMING]: '获取播控盒定时数据异常,请回读查看'
|
|
|
+}
|
|
|
+const RELAY_KEY = -1
|
|
|
+const FOREVER = '4016-06-06'
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'Power',
|
|
|
+ props: {
|
|
|
+ device: {
|
|
|
+ type: Object,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ actionInfo: ['开启', '关闭'],
|
|
|
+ hasMulti: false,
|
|
|
+ hasRelay: false,
|
|
|
+ powerSchema: {
|
|
|
+ singlePage: true,
|
|
|
+ list: this.getPowers,
|
|
|
+ cols: [
|
|
|
+ { label: '设备', render: ({ portIndex }) => portIndex === RELAY_KEY ? '播控盒' : `多功能卡${portIndex}` },
|
|
|
+ { prop: 'powerIndex', label: '电源端口' },
|
|
|
+ { prop: 'type', label: '电源类型' },
|
|
|
+ { type: 'tag', render: ({ action }) => action
|
|
|
+ ? { type: 'danger', label: this.actionInfo[action] }
|
|
|
+ : { type: 'success', label: this.actionInfo[action] } }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ multiTaskSchema: {
|
|
|
+ singlePage: true,
|
|
|
+ list: this.getMultiTasks,
|
|
|
+ cols: [
|
|
|
+ { label: '电源类型', render: ({ typeKey, type }) => this.$typeMap[typeKey]?.label || type },
|
|
|
+ { label: '执行动作', render: ({ action }) => this.actionInfo[action] },
|
|
|
+ { prop: 'executeTime', label: '执行时间' },
|
|
|
+ { prop: 'freqInfo', label: '执行方式' },
|
|
|
+ { label: '生效日期', render: ({ freq, startTime, endTime }) => {
|
|
|
+ switch (freq) {
|
|
|
+ case Freq.ONCE:
|
|
|
+ return startTime
|
|
|
+ default:
|
|
|
+ return endTime === FOREVER ? '永久有效' : `${startTime} 至 ${endTime}`
|
|
|
+ }
|
|
|
+ }, 'min-width': 120 },
|
|
|
+ { type: 'tag', render: task => this.isExpired(task)
|
|
|
+ ? { type: 'warning', label: '已过期' }
|
|
|
+ : task.enable
|
|
|
+ ? { type: 'success', label: '启用' }
|
|
|
+ : { type: 'danger', label: '停用' } }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ relayTaskSchema: {
|
|
|
+ singlePage: true,
|
|
|
+ list: this.getRelayTasks,
|
|
|
+ cols: [
|
|
|
+ { label: '电源类型', render: ({ typeKey, type }) => this.$typeMap[typeKey]?.label || type },
|
|
|
+ { label: '执行动作', render: ({ action }) => this.actionInfo[action] },
|
|
|
+ { prop: 'executeTime', label: '执行时间' },
|
|
|
+ { prop: 'freqInfo', label: '执行方式' },
|
|
|
+ { label: '生效日期', render: ({ freq, startTime, endTime }) => {
|
|
|
+ switch (freq) {
|
|
|
+ case Freq.ONCE:
|
|
|
+ return startTime
|
|
|
+ default:
|
|
|
+ return endTime === FOREVER ? '永久有效' : `${startTime} 至 ${endTime}`
|
|
|
+ }
|
|
|
+ }, 'min-width': 120 },
|
|
|
+ { type: 'tag', render: task => this.isExpired(task)
|
|
|
+ ? { type: 'warning', label: '已过期' }
|
|
|
+ : task.enable
|
|
|
+ ? { type: 'success', label: '启用' }
|
|
|
+ : { type: 'danger', label: '停用' } }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created () {
|
|
|
+ addListener('power', this.onMessage)
|
|
|
+ this.$tableData = {}
|
|
|
+ this.$tableStatus = {}
|
|
|
+ },
|
|
|
+ beforeDestroy () {
|
|
|
+ removeListener('power', this.onMessage)
|
|
|
+ Object.keys(this.$tableStatus).forEach(key => {
|
|
|
+ clearTimeout(this.$tableStatus[key].timer)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onRefresh () {
|
|
|
+ this.$tableData = {}
|
|
|
+ this.$tableStatus = {}
|
|
|
+ this.hasMulti = false
|
|
|
+ this.hasRelay = false
|
|
|
+ this.$refs.powerTable.pageTo()
|
|
|
+ },
|
|
|
+ sendTopic (invoke, inputs) {
|
|
|
+ console.log('invoke', invoke, inputs)
|
|
|
+ const timestamp = `${Date.now()}`
|
|
|
+ const messageId = `${invoke}_${timestamp}`
|
|
|
+ return send(
|
|
|
+ '/multifunctionCard/invoke',
|
|
|
+ {
|
|
|
+ messageId,
|
|
|
+ timestamp,
|
|
|
+ 'function': invoke,
|
|
|
+ inputs: inputs || []
|
|
|
+ }
|
|
|
+ ).then(
|
|
|
+ () => messageId,
|
|
|
+ () => {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '正在连接,请稍后再试'
|
|
|
+ })
|
|
|
+ return Promise.reject()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ getData (key) {
|
|
|
+ if (this.$tableData[key]) {
|
|
|
+ return Promise.resolve({
|
|
|
+ data: this.$tableData[key] || []
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ this.sendTopic(
|
|
|
+ key,
|
|
|
+ JSON.stringify({ sn: this.device.serialNumber }),
|
|
|
+ ErrorMessage[key]
|
|
|
+ ).then(
|
|
|
+ messageId => {
|
|
|
+ const timer = setTimeout(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: ErrorMessage.TIMEOUT
|
|
|
+ })
|
|
|
+ this.$tableStatus[messageId].reject()
|
|
|
+ delete this.$tableStatus[messageId]
|
|
|
+ }, 10000)
|
|
|
+ this.$tableStatus[messageId] = { key, timer, resolve, reject }
|
|
|
+ },
|
|
|
+ reject
|
|
|
+ )
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onMessage (message) {
|
|
|
+ if (!this.$tableStatus[message.messageId]) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const status = this.$tableStatus[message.messageId]
|
|
|
+ delete this.$tableStatus[message.messageId]
|
|
|
+ clearTimeout(status.timer)
|
|
|
+
|
|
|
+ if (message.code !== 0) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: `${ErrorMessage[status.key]}【${message.data}】`
|
|
|
+ })
|
|
|
+ status.reject()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const data = message.data
|
|
|
+ ? JSON.parse(message.data.replaceAll("'", '"'))
|
|
|
+ : {}
|
|
|
+ if (data.logined === false) {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: data.validition ? ErrorMessage.BUSY : ErrorMessage.PASSWORD
|
|
|
+ })
|
|
|
+ status.reject()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let tableData = []
|
|
|
+ switch (message.function) {
|
|
|
+ case GET_POWER_STATUS:
|
|
|
+ tableData = this.setPowerStatus(data)
|
|
|
+ break
|
|
|
+ case GET_MULTI_POWER_TIMING:
|
|
|
+ tableData = this.setMultiPowerTasks(data.data)
|
|
|
+ break
|
|
|
+ case GET_RELAY_POWER_TIMING:
|
|
|
+ tableData = this.setRelayPowerTasks(data)
|
|
|
+ break
|
|
|
+ default:
|
|
|
+ break
|
|
|
+ }
|
|
|
+ this.$tableData[status.key] = tableData
|
|
|
+ status.resolve({ data: tableData })
|
|
|
+ },
|
|
|
+ getPowers () {
|
|
|
+ return this.getData(GET_POWER_STATUS)
|
|
|
+ },
|
|
|
+ setPowerStatus ({ current_status_info }) {
|
|
|
+ const map = {}
|
|
|
+ const powers = []
|
|
|
+ let hasMulti = false
|
|
|
+ let hasRelay = false
|
|
|
+ current_status_info.forEach(({ portIndex, connectIndex, updatePowerIndexStates }) => {
|
|
|
+ updatePowerIndexStates.forEach(({ powerIndex, type, action }) => {
|
|
|
+ const key = portIndex === RELAY_KEY ? RELAY_KEY : `${portIndex}_${connectIndex}_${type}`
|
|
|
+ if (!map[key]) {
|
|
|
+ map[key] = {
|
|
|
+ portIndex,
|
|
|
+ connectIndex,
|
|
|
+ type,
|
|
|
+ label: portIndex === RELAY_KEY ? '' : `${portIndex} ${type}`
|
|
|
+ }
|
|
|
+ if (portIndex === RELAY_KEY) {
|
|
|
+ hasRelay = true
|
|
|
+ } else {
|
|
|
+ hasMulti = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ powers.push({
|
|
|
+ portIndex, connectIndex, powerIndex, type, action,
|
|
|
+ powerKey: `${portIndex}_${powerIndex}`
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.$typeMap = map
|
|
|
+ this.hasMulti = hasMulti
|
|
|
+ this.hasRelay = !hasMulti && hasRelay
|
|
|
+ this.$hasRelay = hasRelay
|
|
|
+ return powers
|
|
|
+ },
|
|
|
+ getMultiTasks () {
|
|
|
+ return this.getData(GET_MULTI_POWER_TIMING)
|
|
|
+ },
|
|
|
+ setMultiPowerTasks (data) {
|
|
|
+ console.log('GET_MULTI_POWER_TIMING', data)
|
|
|
+ const tasks = []
|
|
|
+ data.forEach(({ portIndex, connectIndex, enable, conditions }) => {
|
|
|
+ if (enable) {
|
|
|
+ conditions.forEach(task => {
|
|
|
+ tasks.push({
|
|
|
+ from: { portIndex, connectIndex },
|
|
|
+ typeKey: `${portIndex}_${connectIndex}_${task.type}`,
|
|
|
+ action: task.action,
|
|
|
+ ...this.transfromDataToTask(task)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (this.$hasRelay) {
|
|
|
+ this.hasRelay = true
|
|
|
+ }
|
|
|
+ return tasks
|
|
|
+ },
|
|
|
+ getRelayTasks () {
|
|
|
+ return this.getData(GET_RELAY_POWER_TIMING)
|
|
|
+ },
|
|
|
+ setRelayPowerTasks (data) {
|
|
|
+ console.log('GET_RELAY_POWER_TIMING', data)
|
|
|
+ const tasks = []
|
|
|
+ data.relayPolicyTask.forEach(task => {
|
|
|
+ tasks.push({
|
|
|
+ action: task.status ^ 1,
|
|
|
+ ...this.transfromDataToTask(task)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ return tasks
|
|
|
+ },
|
|
|
+ transfromDataToTask ({ type, flag, powerIndex, enable, startTime, endTime, cron }) {
|
|
|
+ const strArr = cron[0].split(' ')
|
|
|
+ const freq = strArr[3] === '*' && strArr[5] === '?'
|
|
|
+ ? Freq.DAILY
|
|
|
+ : strArr[5] === '?'
|
|
|
+ ? Freq.ONCE
|
|
|
+ : Freq.WEEKLY
|
|
|
+ return {
|
|
|
+ type, flag, powerIndex, enable, startTime, endTime,
|
|
|
+ freq,
|
|
|
+ freqInfo: this.getFreqInfo(freq, strArr[5]),
|
|
|
+ dayOfWeek: freq === Freq.WEEKLY ? strArr[5] : '',
|
|
|
+ executeTime: `${strArr[2].padStart(2, '0')}:${strArr[1].padStart(2, '0')}:${strArr[0].padStart(2, '0')}`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getFreqInfo (freq, val = '') {
|
|
|
+ switch (freq) {
|
|
|
+ case Freq.ONCE:
|
|
|
+ return '单次'
|
|
|
+ case Freq.DAILY:
|
|
|
+ return '每天'
|
|
|
+ default:
|
|
|
+ return `每周${val.split(',').map(val => ['', '一', '二', '三', '四', '五', '六', '日'][val])}`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ isExpired ({ endTime, executeTime }) {
|
|
|
+ return endTime !== FOREVER && toDate(`${endTime} ${executeTime}`) <= Date.now()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|