Ver código fonte

feat: power box debug

Casper Dai 2 anos atrás
pai
commit
7fadb88aab

+ 4 - 133
README.md

@@ -1,137 +1,8 @@
-### 组件介绍
+### 分支说明
 
-#### 根组件
-```
-{
-    name: "大屏",
-    width: 1920,
-    height: 1080,
-    backgroundColor: "#000000",
-    backgroundImage: [],
-    widgets: [],
-    bgm: []
-}
-```
+- master 稳定版
 
-#### 文本
+- develop 开发分支,所有开发基于该分支进行
 
-```
-{
-	type: "CText",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-    text: "文本",
-    textAlign: "center",
-    color: #FFFFFF",
-    fontSize: 48,
-    fontWeight: "normal",
-    backgroundColor: "#00000000"
-}
-```
-
-#### 跑马灯
-
-​		垂直居中。
-
-```
-{
-	type: "CMarquee",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-    text: "文本",
-    color: #FFFFFF",
-    fontSize: 48,
-    fontWeight: "normal",
-    backgroundColor: "#00000000"
-}
-```
-
-#### 图片
-
-```
-{
-	type: "CImage",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-    radius: 0,
-    interval: 10, // 切换间隔,单位秒
-    toggleType: "cycle", // 切换方式,cycle 循环、random 随机
-    animation: "none", // 动画,none 无、slide 幻灯片、fade 渐隐渐现、flip 翻转、section-flip 百叶窗
-    sources: []
-}
-```
-
-#### 视频
-
-​		多个视频存在时至多只有一个有音频输出。
-
-```
-{
-    type: "CVideo",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-    radius: 0,
-    mute: 1, // 静音
-    toggleType: "cycle", // 切换方式,cycle 循环、random 随机
-    sources: []
-}
-```
-
-#### 时间
-
-​		垂直居中。
-
-```
-{
-    type: "CTime",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-	color: "#FFFFFF",
-	fontSize: 48,
-    fontWeight: "normal",
-    textAlign: "center",
-    format: 'yyyy-MM-dd hh:mm'
-}
-```
-
-#### 天气
-
-​		垂直居中。
-
-```
-{
-    type: "CWeather",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-	color: "#FFFFFF",
-	fontSize: 48,
-    fontWeight: "normal",
-    textAlign: "center"
-}
-```
-
-#### 网页
-
-```
-{
-    type: "CWeb",
-    top: 0,
-    left: 0,
-    width: 200,
-    height: 80,
-    href: ""
-}
-```
+- rc 预发布版,rc分支push后会自动部署至71测试服务器供测试验证
 

+ 44 - 1
src/views/platform/settings/api.js

@@ -1,7 +1,8 @@
 import request from '@/utils/request'
 import {
   update,
-  send
+  send,
+  messageSend
 } from '@/api/base'
 
 export function getTimeTask (functionKey) {
@@ -53,3 +54,45 @@ export function getTaskHistory (query) {
     }
   })
 }
+
+export function getThirdPartyElectricBox (id) {
+  return request({
+    url: '/device/thirdPartyElectricBox',
+    method: 'GET',
+    params: { id }
+  })
+}
+
+export function updateThirdPartyElectricBox (data) {
+  return messageSend({
+    url: '/device/thirdPartyElectricBox',
+    method: 'PUT',
+    data
+  }, '变更')
+}
+
+export function electricQuery (data) {
+  return request({
+    url: '/device/electric/query',
+    method: 'GET',
+    params: data
+  })
+}
+
+export function electricRead (data, options) {
+  return request({
+    url: '/device/electric/read',
+    method: 'POST',
+    data,
+    ...options
+  })
+}
+
+export function electricControl (data, options) {
+  return send({
+    url: '/device/electric/control',
+    method: 'POST',
+    data,
+    ...options
+  })
+}

+ 226 - 0
src/views/platform/settings/components/PowerBoxConfigDialog.vue

@@ -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>

+ 16 - 1
src/views/platform/settings/index.vue

@@ -20,17 +20,29 @@
         自助广告统计
       </button>
     </div>
+    <span class="c-sibling-item--v u-font-size--sm u-bold">配电箱</span>
+    <div class="c-sibling-item--v l-grid--info mini">
+      <button
+        class="o-button"
+        @click="onPowerBoxConfig"
+      >
+        开关操控
+      </button>
+    </div>
     <time-task-dialog ref="timeTaskDialog" />
+    <power-box-config-dialog ref="powerBoxConfigDialog" />
   </wrapper>
 </template>
 
 <script>
 import TimeTaskDialog from './components/TimeTaskDialog.vue'
+import PowerBoxConfigDialog from './components/PowerBoxConfigDialog.vue'
 
 export default {
   name: 'PlatformSettings',
   components: {
-    TimeTaskDialog
+    TimeTaskDialog,
+    PowerBoxConfigDialog
   },
   methods: {
     onOnlineDurationTask () {
@@ -38,6 +50,9 @@ export default {
     },
     onAdTask () {
       this.$refs.timeTaskDialog.show('advertisement_statistic')
+    },
+    onPowerBoxConfig () {
+      this.$refs.powerBoxConfigDialog.show()
     }
   }
 }