cuikaidong
2025-08-08 cf63322e29d1dcb619214172b2ce6ff029800fd0
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<template>
  <a-spin :spinning='load'>
    <a-card :bordered='false'>
      <!-- 查询区域 -->
      <div class='table-page-search-wrapper'>
        <a-form layout='inline' @keyup.enter.native='searchQuery'>
          <a-row :gutter='24'>
            <a-col :md='5' :sm='8'>
              <a-form-item label='参数编号'>
                <a-input v-model='queryParam.parameterCode' placeholder='请输入参数编号'></a-input>
              </a-form-item>
            </a-col>
            <a-col :md='5' :sm='8'>
              <a-form-item label='参数名称'>
                <a-input v-model='queryParam.parameterName' placeholder='请输入参数名称'></a-input>
              </a-form-item>
            </a-col>
 
            <a-col :md='5' :sm='8'>
            <span class='table-page-search-submitButtons' style='float: left;overflow: hidden;'>
              <a-button icon='search' type='primary' @click='searchQuery'>查询</a-button>
              <a-button icon='reload' style='margin-left: 8px' type='primary' @click='searchReset'>重置</a-button>
              <a-button icon='plus' style='margin-left: 8px' type='primary' @click='handleAdd'>新增</a-button>
              <a-button icon='file-sync' style='margin-left: 8px' type='primary' @click='canonicalParameter'>标准参数</a-button>
          <a-upload :action='importExcelUrl' :beforeUpload='beforeUpload' :data='extraParams' :headers='tokenHeader'
                    :multiple='false' :showUploadList='false'
                    accept='.csv'
                    name='file' @change='handleImportExcel'>
            <a-button icon='import' style='margin-left: 8px' type='primary'>导入</a-button>
          </a-upload>
               <a-button icon='download' style='margin-left: 8px' type='primary'
                         @click="handleExportXls('设备参数')">导出</a-button>
          <a-button icon='area-chart' style='margin-left: 8px' type='primary'
                    @click="collectData()">实时数据</a-button>
 
 
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div>
        <!-- 操作按钮区域 -->
        <div class='table-operator' style='border-top: 5px'>
          <template v-if='toggleSearchStatus'>
            <a-button icon='download' type='primary'
                      @click="handleExportXls('设备参数')">导出
            </a-button>
            <a-button icon='file-sync' type='primary'
                      @click='canonicalParameter'>标准参数
            </a-button>
          </template>
        </div>
 
        <!--        <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>-->
        <!--          <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a-->
        <!--          style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项-->
        <!--          <a style='margin-left: 24px' @click='onClearSelected'>清空</a>-->
        <!--        </div>-->
        <a-table
          ref='table'
          :columns='columns'
          :customRow='clickThenSelect'
          :dataSource='dataSource'
          :loading='loading'
          :pagination='ipagination'
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
          bordered
          class='j-table-force-nowrap'
          rowKey='id'
          size='small'
          @change='handleTableChange'
        >
          <!--状态栏个性展示-->
          <span  slot='action' slot-scope='text, record'>
          <a href='javascript:' @click='handleEdit(record)'>编辑</a>
          <a-divider type='vertical' />
           <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
           </a-popconfirm>
        </span>
        </a-table>
      </div>
      <!-- table区域-end -->
 
      <!-- 表单区域 -->
      <parameter-group-model ref='modalForm' :server-id='serverId' @ok='modalFormOk' />
      <!-- 实时数据 -->
      <parameter-address ref='modalAddress' @ok='modalFormOk' :server-id='server' />
    </a-card>
  </a-spin>
</template>
 
<script>
import { downFile, getAction } from '@/api/manage'
import ParameterGroupModel from './SolidParameterModel'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JInput from '@/components/jeecg/JInput'
import JEllipsis from '@/components/jeecg/JEllipsis'
import ParameterAddress from '../../collectData/ParameterAddress'
 
export default {
  name: 'SolidParameter',
  mixins: [JeecgListMixin],
  components: {
    ParameterAddress,
    ParameterGroupModel,
    JDictSelectTag,
    JInput,
    JEllipsis
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  data() {
    return {
      items: [
        "ssb_1934877025252777985",
      ],
      server:'1934863338148306945',
      /* 排序参数 */
      isorter: {
        column: 'parameterCode',
        order: 'desc'
      },
      extraParams: {
        param1: this.serverId // 参数组编号
      },
      columns: [
        {
          title: '参数编号',
          align: 'center',
          dataIndex: 'parameterCode'
        },
        {
          title: '参数名称',
          align: 'center',
          dataIndex: 'parameterName'
        },
        {
          title: '描述',
          align: 'center',
          dataIndex: 'parameterDescribe'
        },
        {
          title: '数据类型',
          align: 'center',
          dataIndex: 'parameterType'
        },
        {
          title: '地址',
          align: 'center',
          dataIndex: 'address'
        },
        {
          title: '读写类型',
          align: 'center',
          dataIndex: 'readWriteType'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      load: false,
      url: {
        list: '/real/parameter/list',
        delete: '/real/parameter/delete',
        exportXlsUrl: '/real/parameter/exportXls',
        importExcelUrl: '/real/parameter/importExcel',
        canonicalParameter: '/real/parameter/canonicalParameter'
      }
    }
  },
  props: ['serverId', 'tree'],
  watch: {
    serverId: {
      handler() {
        this.loadData()
      }
    }
  },
  methods: {
    collectData() {
      var that = this
      if (this.dataSource == null) {
        that.$message.warning('当前参数组暂无参数')
      } else {
        this.server = this.dataSource[0].serverId
        this.$refs.modalAddress.openMqtt()
        this.$refs.modalAddress.onSelect(['ssb_'+ this.dataSource[0].parameterGroupId])
      }
    },
    // 标准参数
    canonicalParameter() {
      var that = this
      // 根据服务器id获取mqtt连接参数
      getAction(this.url.canonicalParameter, { id: this.serverId }).then((res) => {
        if (res.success && res.result != null) {
          that.$message.success(res.message)
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    beforeUpload(file) {
      this.loading = true
      return true
    },
    /* 导入 */
    handleImportExcel(info) {
      if (info.file.status !== 'uploading') {
        console.log(info.file, info.fileList)
      }
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          // this.$message.success(`${info.file.name} 文件上传成功`);
          if (info.file.response.code === 201) {
            let { message, result: { msg, fileUrl, fileName } } = info.file.response
            let href = window._CONFIG['domianURL'] + fileUrl
            this.$warning({
              title: message,
              content: (
                <div>
                  <span>{msg}</span><br />
                  <span>具体详情请 <a href={href} target='_blank' download={fileName}>点击下载</a> </span>
                </div>
              )
            })
          } else {
            this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
          }
          this.loadData()
        } else {
          this.$message.error(`${info.file.name} ${info.file.response.message}.`)
        }
      } else if (info.file.status === 'error') {
        this.loading = false
        this.$message.error(`文件上传失败: ${info.file.msg} `)
      }
    },
    /* 导出 */
    handleExportXls(fileName) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '导出文件'
      }
      let param = { ...this.queryParam }
      param.parameterGroupId = this.extraParams.param1
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.csv')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    // 查询终端列表
    loadData(arg) {
      this.extraParams.param1 = this.serverId
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      this.onClearSelected()
      var params = this.getQueryParams()//查询条件
      params.parameterGroupId = this.serverId
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
 
    },
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(','), [record])
          }
        }
      }
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    modalFormOk(val) {
      // 调用父组件方法
      this.$emit('tree')
      // 新增/修改 成功时,重载列表
      this.loadData()
      this.selectedRowKeys = [val.id]
    },
    searchQuery() {
      this.loadData()
      this.onClearSelected()
    },
    searchReset() {
      this.queryParam = {}
      this.loadData()
      this.onClearSelected()
    },
    handleEdit(record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '编辑'
      this.$refs.modalForm.disableSubmit = false
    }
  }
}
</script>
<style>
</style>