doum
7 天以前 e46bfa3ff94a8a1b4daf37c7fcb79c2fab22a72c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
  <TableLayout :permissions="['business:ywconditioneractions:query']">
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="操作类型" prop="actionType">
        <el-select v-model="searchForm.actionType" clearable placeholder="全部" style="min-width: 160px">
          <el-option v-for="item in actionTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="设备信息" prop="devKeyword">
        <el-input v-model="searchForm.devKeyword" placeholder="设备名称" clearable @keypress.enter.native="search" />
      </el-form-item>
      <el-form-item label="网关MAC" prop="wgMac">
        <el-input v-model="searchForm.wgMac" placeholder="网关MAC" clearable @keypress.enter.native="search" />
      </el-form-item>
      <el-form-item label="操作时间" prop="operateTimeRange">
        <el-date-picker
          v-model="searchForm.operateTimeRange"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          style="width: 360px"
        />
      </el-form-item>
      <section>
        <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
        <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
      </section>
    </el-form>
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <li>
          <el-button
            @click="exportExcel"
            :loading="isWorking.export"
            v-permissions="['business:ywconditioneractions:exportExcel']"
          >导出</el-button>
        </li>
      </ul>
      <el-table v-loading="isWorking.search" :data="tableData.list" stripe>
        <el-table-column prop="id" label="ID" min-width="70" align="center" />
        <el-table-column prop="devName" label="设备名称" min-width="140" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.devName || '-' }}</template>
        </el-table-column>
        <el-table-column prop="wgMac" label="网关MAC" min-width="140" align="center" show-overflow-tooltip>
          <template slot-scope="{ row }">{{ row.wgMac || '-' }}</template>
        </el-table-column>
        <el-table-column label="操作类型" min-width="100" align="center">
          <template slot-scope="{ row }">{{ formatActionType(row.actionType) }}</template>
        </el-table-column>
        <el-table-column prop="actionContent" label="操作描述" min-width="180" align="center" show-overflow-tooltip />
        <el-table-column label="结果" min-width="80" align="center">
          <template slot-scope="{ row }">
            <span :class="row.resultStatus === 1 ? 'green' : 'red'">{{ formatResult(row.resultStatus) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="resultMsg" label="说明" min-width="140" align="center" show-overflow-tooltip />
        <el-table-column prop="createDate" label="操作时间" min-width="160" align="center" />
        <el-table-column label="请求报文" min-width="90" align="center">
          <template slot-scope="{ row }">
            <el-button type="text" :disabled="!row.requestBody" @click="openJson('请求报文', row.requestBody)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column label="响应报文" min-width="90" align="center">
          <template slot-scope="{ row }">
            <el-button type="text" :disabled="!row.responseBody" @click="openJson('响应报文', row.responseBody)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      />
    </template>
    <OperaInterfaceLogWindow ref="jsonWindow" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaInterfaceLogWindow from '@/components/business/OperaInterfaceLogWindow'
import * as actionsApi from '@/api/business/ywconditioneractions'
 
const ACTION_TYPE_MAP = {
  1: '开关',
  2: '模式',
  3: '风速',
  4: '温度',
  5: '锁定',
  6: '查电量',
  7: '查功率'
}
 
export default {
  name: 'YwConditionerActions',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaInterfaceLogWindow },
  data () {
    return {
      searchForm: {
        actionType: null,
        devKeyword: '',
        wgMac: '',
        operateTimeRange: []
      },
      actionTypeOptions: Object.keys(ACTION_TYPE_MAP).map(key => ({
        value: Number(key),
        label: ACTION_TYPE_MAP[key]
      }))
    }
  },
  created () {
    this.api = actionsApi
    this.module = '空调控制记录'
    this.configData['field.id'] = 'id'
    this.configData['field.main'] = 'id'
    this.search()
  },
  methods: {
    buildSearchModel () {
      const model = {}
      if (this.searchForm.actionType !== null && this.searchForm.actionType !== '' && this.searchForm.actionType !== undefined) {
        model.actionType = this.searchForm.actionType
      }
      if (this.searchForm.devKeyword) model.devKeyword = this.searchForm.devKeyword
      if (this.searchForm.wgMac) model.wgMac = this.searchForm.wgMac
      if (this.searchForm.operateTimeRange && this.searchForm.operateTimeRange.length === 2) {
        model.operateTimeBegin = this.searchForm.operateTimeRange[0]
        model.operateTimeEnd = this.searchForm.operateTimeRange[1]
      }
      return model
    },
    handlePageChange (pageIndex) {
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      actionsApi.fetchList({
        page: this.tableData.pagination.pageIndex,
        capacity: this.tableData.pagination.pageSize,
        model: this.buildSearchModel(),
        sorts: this.tableData.sorts
      })
        .then(data => {
          this.tableData.list = data.records || []
          this.tableData.pagination.total = data.total || 0
        })
        .catch(() => {})
        .finally(() => { this.isWorking.search = false })
    },
    reset () {
      this.searchForm = { actionType: null, devKeyword: '', wgMac: '', operateTimeRange: [] }
      if (this.$refs.searchForm) {
        this.$refs.searchForm.resetFields()
      }
      this.search()
    },
    formatActionType (val) {
      return ACTION_TYPE_MAP[val] || val || '-'
    },
    formatResult (val) {
      if (val === 1 || val === '1') return '成功'
      if (val === 0 || val === '0') return '失败'
      return val == null ? '-' : String(val)
    },
    openJson (title, content) {
      if (!content) return
      this.$refs.jsonWindow.open(title, { content })
    },
    exportExcel () {
      this.$dialog.exportConfirm('确认导出吗?')
        .then(() => {
          this.isWorking.export = true
          actionsApi.exportExcel({
            page: 1,
            capacity: 1000000,
            model: this.buildSearchModel(),
            sorts: this.tableData.sorts
          })
            .then(response => { this.download(response) })
            .catch(e => this.$tip.apiFailed(e))
            .finally(() => { this.isWorking.export = false })
        })
        .catch(() => {})
    }
  }
}
</script>
 
<style scoped>
.green { color: #67c23a; }
.red { color: #f56c6c; }
</style>