Selaa lähdekoodia

fix: some bugs

Casper Dai 1 vuosi sitten
vanhempi
sitoutus
7e3ea5dc23

+ 7 - 16
src/views/platform/remote-log/api.js

@@ -1,25 +1,24 @@
 import request from '@/utils/request'
 import {
   send,
-  messageSend,
-  addTenant
+  messageSend
 } from '@/api/base'
 
 // 开启抓取日志
 export function startRemoteLog (data) {
   return messageSend({
-    url: `/device/remoteLog`,
+    url: '/device/remoteLog',
     method: 'POST',
-    data: addTenant(data)
+    data
   }, '开始')
 }
 
 // 停止抓取日志
 export function stopRemoteLog (data) {
   return messageSend({
-    url: `/device/remoteLog`,
+    url: '/device/remoteLog',
     method: 'POST',
-    data: addTenant(data)
+    data
   }, '停止')
 }
 
@@ -38,10 +37,10 @@ export function getRemoteLogs (query) {
   return request({
     url: '/device/remoteLog/record/pageQuery',
     method: 'GET',
-    params: addTenant({
+    params: {
       pageIndex, pageSize,
       ...params
-    })
+    }
   })
 }
 
@@ -64,11 +63,3 @@ export function getHeartbeats (params, single) {
     return { data: data.map(JSON.parse).sort((a, b) => b.timestamp - a.timestamp) }
   })
 }
-
-export function getDownloadUrl (recordId) {
-  return send({
-    url: `/device/remoteLog/download`,
-    method: 'GET',
-    params: { recordId }
-  })
-}

+ 8 - 3
src/views/platform/remote-log/index.vue

@@ -156,6 +156,7 @@ export default {
         ]
       },
       curDeviceId: null,
+      currDeviceTenant: null,
       title: '',
       sn: ''
     }
@@ -193,7 +194,7 @@ export default {
       return {
         list: getRemoteLogs,
         autoRefresh: true,
-        condition: { deviceId: this.curDeviceId },
+        condition: { tenant: this.currDeviceTenant, deviceId: this.curDeviceId },
         cols: [
           { prop: 'settingId', label: '事件' },
           { label: '执行状态', type: 'tag', render: ({ status }) => {
@@ -246,10 +247,11 @@ export default {
       this.$heartbeats = []
       this.$refs.heartbeatDialog.show()
     },
-    onStop ({ id }) {
+    onStop ({ tenant, id }) {
       stopRemoteLog({
-        duration: 60,
+        tenant,
         deviceId: id,
+        duration: 60,
         activate: false
       })
     },
@@ -266,6 +268,7 @@ export default {
         } else {
           this.logSetting = { ...defaultLogSettingForm }
         }
+        this.currDeviceTenant = device.tenant
         this.curDeviceId = device.id
         this.$refs.editDialog.show()
       })
@@ -281,6 +284,7 @@ export default {
       }
 
       await startRemoteLog({
+        tenant: this.currDeviceTenant,
         deviceId: this.curDeviceId,
         duration,
         activate: true,
@@ -291,6 +295,7 @@ export default {
     },
     onResult (device) {
       this.$deviceName = device.name
+      this.currDeviceTenant = device.tenant
       this.curDeviceId = device.id
       this.$refs.resultDialog.show()
     },

+ 58 - 19
src/views/platform/settings/components/PowerBoxConfigDialog.vue

@@ -3,11 +3,12 @@
     ref="dialog"
     title="配电箱"
     size="lg fixed"
-    @closed="onClose"
   >
     <template #default>
       <div class="l-flex--row c-sibling-item--v">
-        <div class="c-sibling-item u-bold">设备编号</div>
+        <div class="c-sibling-item u-bold">
+          设备编号
+        </div>
         <div class="l-flex--row c-sibling-item far">
           <el-input
             v-model="identifier"
@@ -24,20 +25,31 @@
         </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>
+        <div class="c-sibling-item u-bold">
+          当前模式
+        </div>
         <el-radio
           v-model="mode"
           class="c-sibling-item far"
           label="manual"
+          :disabled="!connectedDevice"
           @change="onModeChange"
-        >手动</el-radio>
+        >
+          手动
+        </el-radio>
         <el-radio
           v-model="mode"
           label="timer"
+          :disabled="!connectedDevice"
           @change="onModeChange"
-        >定时</el-radio>
+        >
+          定时
+        </el-radio>
       </div>
-      <div class="l-flex l-flex__self c-sibling-item--v c-step">
+      <div
+        v-if="connectedDevice"
+        class="l-flex l-flex__self c-sibling-item--v c-step"
+      >
         <schema-table
           ref="reportTable"
           class="l-flex__none c-step__column u-width--lg"
@@ -61,7 +73,7 @@ import {
   electricRead,
   electricQuery,
   electricControl
-} from '../api'
+} from '../api.js'
 
 const ELECTRIC_ID = 1
 
@@ -72,6 +84,7 @@ export default {
   data () {
     return {
       identifier: '',
+      connectedDevice: '',
       mode: '',
       reoirtSchema: {
         nonPagination: true,
@@ -102,29 +115,27 @@ export default {
       }
     }
   },
-  mounted () {
-    this.$timer = -1
-  },
   methods: {
-    onClose () {
-      clearInterval(this.$timer)
-    },
     show () {
       const loading = this.$showLoading()
       // 查询设备编号
       getThirdPartyElectricBox(ELECTRIC_ID)
         .then(data => {
-          this.identifier = data.data.identifier
+          this.identifier = data.data?.identifier || ''
+          this.connectedDevice = this.identifier
         })
-        .then(this.initPowerBox)
         .then(() => {
           this.$refs.dialog.show()
         })
+        .then(this.initPowerBox)
         .finally(() => {
           this.$closeLoading(loading)
         })
     },
     initPowerBox () {
+      if (!this.connectedDevice) {
+        return Promise.reject()
+      }
       return electricRead({
         electricId: ELECTRIC_ID,
         commandKey: 6
@@ -211,15 +222,36 @@ export default {
       })
     },
     onApply () {
+      if (!this.identifier) {
+        this.$message({
+          type: 'warning',
+          message: '请填写设备编号'
+        })
+        return
+      }
+      const pre = this.connectedDevice
+      this.connectedDevice = null
       updateThirdPartyElectricBox({
         id: ELECTRIC_ID,
         identifier: this.identifier
-      }).then(this.initPowerBox).then(() => {
-        this.$refs.reportTable.pageTo(1)
-        this.$refs.table.pageTo(1)
-      })
+      }).then(
+        () => {
+          this.connectedDevice = this.identifier
+        },
+        () => {
+          this.connectedDevice = pre
+        }
+      ).then(this.initPowerBox)
     },
     onModeChange (mode) {
+      if (!this.connectedDevice) {
+        this.$message({
+          type: 'warning',
+          message: '请先连接设备'
+        })
+        this.mode = ''
+        return
+      }
       electricControl({
         electricId: ELECTRIC_ID,
         commandKey: 1,
@@ -243,6 +275,13 @@ export default {
       this.onSwitch(false)
     },
     onSwitch (bool) {
+      if (!this.connectedDevice) {
+        this.$message({
+          type: 'warning',
+          message: '请先连接设备'
+        })
+        return
+      }
       electricControl({
         commandKey: 2,
         electricId: 1,

+ 46 - 16
src/views/platform/settings/components/TimingControlDialog.vue

@@ -3,11 +3,12 @@
     ref="dialog"
     title="配电箱"
     size="lg fixed"
-    @closed="onClose"
   >
     <template #default>
       <div class="l-flex--row c-sibling-item--v">
-        <div class="c-sibling-item u-bold">设备编号</div>
+        <div class="c-sibling-item u-bold">
+          设备编号
+        </div>
         <div class="l-flex--row c-sibling-item far">
           <el-input
             v-model="identifier"
@@ -24,11 +25,14 @@
         </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>
+        <div class="c-sibling-item u-bold">
+          当前模式
+        </div>
         <el-radio
           v-model="mode"
           class="c-sibling-item far"
           label="manual"
+          :disabled="!connectedDevice"
           @change="onModeChange"
         >
           手动
@@ -36,6 +40,7 @@
         <el-radio
           v-model="mode"
           label="timer"
+          :disabled="!connectedDevice"
           @change="onModeChange"
         >
           定时
@@ -143,7 +148,7 @@ import {
   electricRead,
   electricQuery,
   electricControl
-} from '../api'
+} from '../api.js'
 const ELECTRIC_ID = 1
 
 export default {
@@ -151,6 +156,7 @@ export default {
   data () {
     return {
       identifier: '',
+      connectedDevice: '',
       mode: '',
       data: [],
       timeCofig: '',
@@ -159,29 +165,32 @@ export default {
       status: null
     }
   },
-  mounted () {
-    this.$timer = -1
+  computed: {
+    loading () {
+      return this.identifier && !this.connectedDevice
+    }
   },
   methods: {
-    onClose () {
-      clearInterval(this.$timer)
-    },
     show () {
       const loading = this.$showLoading()
       // 查询设备编号
       getThirdPartyElectricBox(ELECTRIC_ID)
         .then(data => {
-          this.identifier = data.data.identifier
+          this.identifier = data.data?.identifier || ''
+          this.connectedDevice = this.identifier
         })
-        .then(this.initPowerBox)
         .then(() => {
           this.$refs.dialog.show()
         })
+        .then(this.initPowerBox)
         .finally(() => {
           this.$closeLoading(loading)
         })
     },
     initPowerBox () {
+      if (!this.connectedDevice) {
+        return Promise.reject()
+      }
       return electricRead({
         electricId: ELECTRIC_ID,
         commandKey: 6
@@ -196,14 +205,15 @@ export default {
           queryMode: 1
         }))
         .then(({ data }) => {
-          this.getPorts()
           if (data[0]) {
+            this.getPorts()
             this.mode = data[0].mode
           } else {
             this.$message({
               type: 'warning',
               message: '模式同步中,请稍后重试'
             })
+            this.data = []
             this.mode = ''
           }
         })
@@ -271,15 +281,35 @@ export default {
       this.data = outputArr
     },
     onApply () {
+      if (!this.identifier) {
+        this.$message({
+          type: 'warning',
+          message: '请填写设备编号'
+        })
+        return
+      }
+      const pre = this.connectedDevice
+      this.connectedDevice = null
       updateThirdPartyElectricBox({
         id: ELECTRIC_ID,
         identifier: this.identifier
-      }).then(this.initPowerBox).then(() => {
-        this.$refs.reportTable.pageTo(1)
-        this.$refs.table.pageTo(1)
-      })
+      }).then(
+        () => {
+          this.connectedDevice = this.identifier
+        },
+        () => {
+          this.connectedDevice = pre
+        }
+      ).then(this.initPowerBox)
     },
     onModeChange (mode) {
+      if (!this.identifier) {
+        this.$message({
+          type: 'warning',
+          message: '请先连接设备'
+        })
+        return
+      }
       electricControl({
         electricId: ELECTRIC_ID,
         commandKey: 1,

+ 7 - 3
src/views/platform/settings/components/TimingTaskDialog.vue

@@ -7,7 +7,9 @@
   >
     <template #default>
       <div class="l-flex--row c-sibling-item--v">
-        <span class="c-sibling-item">启用</span>
+        <span class="c-sibling-item">
+          启用
+        </span>
         <el-switch
           v-model="config.status"
           class="c-sibling-item"
@@ -16,7 +18,9 @@
           active-color="#13ce66"
           inactive-color="#ff4949"
         />
-        <span class="c-sibling-item farther u-required">触发时间</span>
+        <span class="c-sibling-item farther u-required">
+          触发时间
+        </span>
         <el-time-picker
           v-model="config.executeTime"
           class="c-sibling-item"
@@ -39,7 +43,7 @@ import {
   updateTimeTask,
   addTimeTask,
   getTaskHistory
-} from '../api'
+} from '../api.js'
 
 export default {
   name: 'TimingTaskDialog',

+ 8 - 4
src/views/platform/settings/index.vue

@@ -5,7 +5,9 @@
     padding
     background
   >
-    <span class="c-sibling-item--v u-font-size--sm u-bold">定时任务</span>
+    <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"
@@ -20,7 +22,9 @@
         自助广告统计
       </button>
     </div>
-    <span class="c-sibling-item--v u-font-size--sm u-bold">配电箱</span>
+    <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"
@@ -30,7 +34,7 @@
       </button>
       <button
         class="o-button"
-        @click="ontimeControlConfig"
+        @click="onTimeControlConfig"
       >
         定时控制
       </button>
@@ -63,7 +67,7 @@ export default {
     onPowerBoxConfig () {
       this.$refs.powerBoxConfigDialog.show()
     },
-    ontimeControlConfig () {
+    onTimeControlConfig () {
       this.$refs.timingControlDialog.show()
     }
   }