|
|
@@ -0,0 +1,226 @@
|
|
|
+<template>
|
|
|
+ <c-dialog
|
|
|
+ ref="dialog"
|
|
|
+ title="配电箱"
|
|
|
+ @closed="onClose"
|
|
|
+ >
|
|
|
+ <template #default>
|
|
|
+ <div class="l-flex--row c-sibling-item--v">
|
|
|
+ <div class="c-sibling-item u-bold">设备编号</div>
|
|
|
+ <div class="l-flex--row c-sibling-item far">
|
|
|
+ <el-input
|
|
|
+ v-model="identifier"
|
|
|
+ class="c-sibling-item"
|
|
|
+ placeholder="请输入设备编号"
|
|
|
+ controls-position="right"
|
|
|
+ />
|
|
|
+ <button
|
|
|
+ class="c-sibling-item near o-button"
|
|
|
+ @click="onApply"
|
|
|
+ >
|
|
|
+ 应用
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="l-flex--row c-sibling-item--v has-bottom-padding has-bottom-border">
|
|
|
+ <div class="c-sibling-item u-bold">当前模式</div>
|
|
|
+ <el-radio
|
|
|
+ v-model="mode"
|
|
|
+ class="c-sibling-item far"
|
|
|
+ label="manual"
|
|
|
+ @change="onModeChange"
|
|
|
+ >手动</el-radio>
|
|
|
+ <el-radio
|
|
|
+ v-model="mode"
|
|
|
+ label="timer"
|
|
|
+ @change="onModeChange"
|
|
|
+ >定时</el-radio>
|
|
|
+ </div>
|
|
|
+ <schema-table
|
|
|
+ ref="table"
|
|
|
+ class="c-sibling-item--v"
|
|
|
+ :schema="schema"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </c-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { parseTime } from '@/utils'
|
|
|
+import {
|
|
|
+ getThirdPartyElectricBox,
|
|
|
+ updateThirdPartyElectricBox,
|
|
|
+ electricRead,
|
|
|
+ electricQuery,
|
|
|
+ electricControl
|
|
|
+} from '../api'
|
|
|
+
|
|
|
+const ELECTRIC_ID = 1
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: 'PowerBoxConfigDialog',
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ identifier: '',
|
|
|
+ switchKey: 'S10',
|
|
|
+ allSwitch: false,
|
|
|
+ mode: '',
|
|
|
+ strategies: [],
|
|
|
+ schema: {
|
|
|
+ nonPagination: true,
|
|
|
+ autoRefresh: true,
|
|
|
+ list: this.getPorts,
|
|
|
+ buttons: [
|
|
|
+ { label: '一键开启', on: this.onSwitchOpen },
|
|
|
+ { label: '一键关闭', on: this.onSwitchClose }
|
|
|
+ ],
|
|
|
+ cols: [
|
|
|
+ { prop: 'portIndex', label: '端口' },
|
|
|
+ { prop: 'portKey', label: '' },
|
|
|
+ { prop: 'stateTag', type: 'tag' },
|
|
|
+ { prop: 'timestamp', label: '同步时间', width: 160, align: 'center' },
|
|
|
+ { type: 'invoke', render: [
|
|
|
+ { label: ({ state }) => ['开启', '关闭'][state], on: this.onSwitchPort }
|
|
|
+ ] }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ this.$timer = -1
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onClose () {
|
|
|
+ clearInterval(this.$timer)
|
|
|
+ },
|
|
|
+ show () {
|
|
|
+ const loading = this.$showLoading()
|
|
|
+ // 查询设备编号
|
|
|
+ getThirdPartyElectricBox(ELECTRIC_ID)
|
|
|
+ .then(data => {
|
|
|
+ this.identifier = data.data.identifier
|
|
|
+ })
|
|
|
+ .then(this.initPowerBox)
|
|
|
+ .then(() => {
|
|
|
+ this.$refs.dialog.show()
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.$closeLoading(loading)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ initPowerBox () {
|
|
|
+ return electricRead({
|
|
|
+ electricId: ELECTRIC_ID,
|
|
|
+ commandKey: 6
|
|
|
+ })
|
|
|
+ .then(() => electricRead({
|
|
|
+ electricId: ELECTRIC_ID,
|
|
|
+ commandKey: 7
|
|
|
+ }))
|
|
|
+ .then(() => electricQuery({
|
|
|
+ electricId: ELECTRIC_ID,
|
|
|
+ commandKey: 12,
|
|
|
+ queryMode: 1
|
|
|
+ }))
|
|
|
+ .then(({ data }) => {
|
|
|
+ if (data[0]) {
|
|
|
+ this.mode = data[0].mode
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ type: 'warning',
|
|
|
+ message: '模式同步中,请稍后再试'
|
|
|
+ })
|
|
|
+ this.mode = ''
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getPorts () {
|
|
|
+ return electricQuery({
|
|
|
+ electricId: ELECTRIC_ID,
|
|
|
+ commandKey: 13,
|
|
|
+ queryMode: 1
|
|
|
+ }).then(({ data }) => {
|
|
|
+ const outputArr = []
|
|
|
+ if (data[0]) {
|
|
|
+ const timestamp = parseTime(data[0].timestamp, '{y}-{m}-{d} {h}:{i}:{s}')
|
|
|
+ for (const key in data[0]) {
|
|
|
+ if (key.includes('output')) {
|
|
|
+ const index = Number(key.replace('output', ''))
|
|
|
+ const state = data[0][key]
|
|
|
+ outputArr.push({
|
|
|
+ portIndex: `开关${index + 1}`,
|
|
|
+ portKey: `S${index}`,
|
|
|
+ state,
|
|
|
+ stateTag: {
|
|
|
+ type: ['danger', 'success'][state],
|
|
|
+ label: ['关闭', '开启'][state]
|
|
|
+ },
|
|
|
+ timestamp
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return { data: outputArr }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onApply () {
|
|
|
+ updateThirdPartyElectricBox({
|
|
|
+ id: ELECTRIC_ID,
|
|
|
+ identifier: this.identifier
|
|
|
+ }).then(this.initPowerBox).then(() => {
|
|
|
+ this.$refs.table.pageTo(1)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onModeChange (mode) {
|
|
|
+ electricControl({
|
|
|
+ electricId: ELECTRIC_ID,
|
|
|
+ commandKey: 1,
|
|
|
+ mode
|
|
|
+ }).then(
|
|
|
+ () => {
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '变更成功'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ this.mode = mode === 'timer' ? 'manual' : 'timer'
|
|
|
+ }
|
|
|
+ )
|
|
|
+ },
|
|
|
+ onSwitchOpen () {
|
|
|
+ this.onSwitch(true)
|
|
|
+ },
|
|
|
+ onSwitchClose () {
|
|
|
+ this.onSwitch(false)
|
|
|
+ },
|
|
|
+ onSwitch (bool) {
|
|
|
+ electricControl({
|
|
|
+ commandKey: 2,
|
|
|
+ electricId: 1,
|
|
|
+ plcSwitch: this.switchKey,
|
|
|
+ status: bool ? 1 : 0
|
|
|
+ }).then(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '触发成功,同步中...'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 单个开关S0-S9
|
|
|
+ onSwitchPort ({ portKey, state }) {
|
|
|
+ electricControl({
|
|
|
+ commandKey: 2,
|
|
|
+ electricId: 1,
|
|
|
+ plcSwitch: portKey,
|
|
|
+ status: state ? 0 : 1
|
|
|
+ }).then(() => {
|
|
|
+ this.$message({
|
|
|
+ type: 'success',
|
|
|
+ message: '触发成功,同步中...'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|