RemoteOpc.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <a-card :bordered="false">
  3. <div v-show="visible">
  4. <div class="table-page-search-wrapper" @keyup.enter="handleEnter">
  5. <a-form layout="inline">
  6. <a-row :gutter="48" v-show="advanced">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="关键字">
  9. <a-input v-model="queryParam.keyword" placeholder="请输入名称/类型名称" />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="是否模拟量">
  14. <a-select v-model="queryParam.avFlag" placeholder="请选择">
  15. <a-select-option
  16. v-for="(label,value) in yesNoMap"
  17. :key="value"
  18. :label="label"
  19. :value="parseInt(value)">{{ label }}
  20. </a-select-option>
  21. </a-select>
  22. </a-form-item>
  23. </a-col>
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="opc服务端是否创建">
  26. <a-select v-model="queryParam.createdFlag" placeholder="请选择">
  27. <a-select-option
  28. v-for="(label,value) in yesNoMap"
  29. :key="value"
  30. :label="label"
  31. :value="parseInt(value)">{{ label }}
  32. </a-select-option>
  33. </a-select>
  34. </a-form-item>
  35. </a-col>
  36. </a-row>
  37. <a-row :gutter="48">
  38. <a-col :md="24 || 24" :sm="24" style="text-align: right">
  39. <span class="table-page-search-submitButtons">
  40. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  41. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  42. <a @click="()=>{ this.advanced = !this.advanced}" style="margin-left: 8px">
  43. {{ advanced ? '收起' : '展开' }}
  44. <a-icon :type="advanced ? 'up' : 'down'" />
  45. </a>
  46. </span>
  47. </a-col>
  48. </a-row>
  49. </a-form>
  50. </div>
  51. <div class="table-operator" style="margin-bottom: 8px;">
  52. <a-row>
  53. <a-col :md="16">
  54. <a-button v-if="$auth('remote-opcs-add')" type="primary" icon="plus" @click="handleAdd()">新增</a-button>
  55. <a-button
  56. style="margin-left: 8px"
  57. v-if="$auth('remote-opcs-export')"
  58. type="primary"
  59. icon="download"
  60. @click="doExport">导出
  61. </a-button>
  62. <a-button style="margin-left:8px;" type="primary" @click="doImport">
  63. <a-icon type="upload" />
  64. 新增导入
  65. </a-button>
  66. <a-button
  67. style="margin-left: 8px"
  68. v-if="$auth('remote-opcs-add')"
  69. type="primary"
  70. icon="download"
  71. @click="doAddAll">全部采集
  72. </a-button>
  73. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('remote-opcs-del')">
  74. <a-menu slot="overlay">
  75. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  76. <a-menu-item key="1">
  77. <a-icon type="delete" />
  78. <a>删除</a>
  79. </a-menu-item>
  80. </a-popconfirm>
  81. <a-popconfirm title="是否要删除所选数据?" @confirm="update(1, 1)">
  82. <a-menu-item key="1">
  83. <a-icon />
  84. <a>模拟量</a>
  85. </a-menu-item>
  86. </a-popconfirm>
  87. <a-popconfirm title="是否要删除所选数据?" @confirm="update(1, 0)">
  88. <a-menu-item key="1">
  89. <a-icon />
  90. <a>数字量</a>
  91. </a-menu-item>
  92. </a-popconfirm>
  93. <a-popconfirm title="是否要删除所选数据?" @confirm="update(2, 1)">
  94. <a-menu-item key="1">
  95. <a-icon />
  96. <a>OPC server已配置</a>
  97. </a-menu-item>
  98. </a-popconfirm>
  99. <a-popconfirm title="是否要删除所选数据?" @confirm="update(2, 0)">
  100. <a-menu-item key="1">
  101. <a-icon />
  102. <a>OPC server未配置</a>
  103. </a-menu-item>
  104. </a-popconfirm>
  105. </a-menu>
  106. <a-button style="margin-left: 8px">
  107. 批量操作
  108. <a-icon type="down" />
  109. </a-button>
  110. </a-dropdown>
  111. </a-col>
  112. </a-row>
  113. </div>
  114. <s-table
  115. ref="table"
  116. size="default"
  117. rowKey="id"
  118. :columns="columns"
  119. :data="loadData"
  120. :alert="options.alert"
  121. :rowSelection="options.rowSelection"
  122. showPagination="auto"
  123. >
  124. <span slot="action" slot-scope="record">
  125. <template>
  126. <a @click="handleView(record)">查看</a>
  127. <operation-button
  128. v-if="$auth('remote-opcs-edit')"
  129. @click="handleEdit(record)"
  130. >修改</operation-button>
  131. <operation-button
  132. v-if="$auth('remote-opcs-del')"
  133. :type="2"
  134. title="是否要删除该条数据?"
  135. @confirm="batchDelete(record.id)">删除</operation-button>
  136. <a-divider
  137. v-if="record.type == 2"
  138. type="vertical" />
  139. <a
  140. v-if="record.type == 2"
  141. @click="handleAddFetch(record)">就地点位
  142. </a>
  143. <!-- <a
  144. style="margin-left: 8px"
  145. @click="doTestAdd(record)">测试写入
  146. </a>
  147. <a-divider type="vertical" />
  148. <a
  149. style="margin-left: 8px"
  150. @click="doTestAddBatch(record)">测试批量写入
  151. </a>
  152. <a-divider type="vertical" />
  153. <a
  154. style="margin-left: 8px"
  155. @click="doTestSelect(record)">测试查询
  156. </a>-->
  157. </template>
  158. </span>
  159. </s-table>
  160. </div>
  161. <import-form-add ref="importModal" @ok="handleOk" />
  162. <base-form ref="baseModal" @ok="handleOk" />
  163. <detail ref="detailModal" @ok="handleOk" />
  164. </a-card>
  165. </template>
  166. <script>
  167. import { STable, Ellipsis } from '@/components'
  168. import BaseForm from './modules/BaseForm'
  169. import Detail from './modules/Detail'
  170. import {
  171. getRemoteOpcPage,
  172. deleteRemoteOpcs,
  173. updateRemoteOpcs,
  174. addToServerRemoteOpcs,
  175. fetchRemoteOpc,
  176. exportRemoteOpc
  177. } from '@/api/remote/opc'
  178. import ImportFormAdd from './modules/ImportFormAdd'
  179. import { updateInfluxDB, updateInfluxDBBatch, queryInfluxDBHistory } from '@/api/influxDB/influxDB'
  180. export default {
  181. name: 'RemoteOpcList',
  182. components: {
  183. STable,
  184. Ellipsis,
  185. ImportFormAdd,
  186. BaseForm,
  187. Detail
  188. },
  189. props: {
  190. createdFlag: {
  191. type: Number,
  192. default: 1
  193. }
  194. },
  195. data () {
  196. return {
  197. advanced: false,
  198. visible: true,
  199. map: {},
  200. // 查询参数
  201. queryParam: {
  202. createdFlag: this.createdFlag
  203. },
  204. // 表头
  205. columns: [
  206. {
  207. title: '序号',
  208. dataIndex: 'index',
  209. customRender: (text, record, index) => {
  210. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  211. }
  212. },
  213. {
  214. title: '点位',
  215. dataIndex: 'positionNum'
  216. },
  217. {
  218. title: '类型',
  219. dataIndex: 'type',
  220. customRender: (text, record, index) => {
  221. return this.BaseTool.Object.getField(this.map, text)
  222. }
  223. },
  224. {
  225. title: '是否模拟量',
  226. dataIndex: 'avFlag',
  227. customRender: (text, record, index) => {
  228. return this.BaseTool.Object.getField(this.yesNoMap, text)
  229. }
  230. },
  231. {
  232. title: 'opc服务中心是否配置',
  233. dataIndex: 'createdFlag',
  234. customRender: (text, record, index) => {
  235. return this.BaseTool.Object.getField(this.yesNoMap, text)
  236. }
  237. },
  238. {
  239. title: '量程下限',
  240. dataIndex: 'low'
  241. },
  242. {
  243. title: '量程上限',
  244. dataIndex: 'high'
  245. },
  246. {
  247. title: '单位',
  248. dataIndex: 'unit'
  249. },
  250. {
  251. title: '系数',
  252. dataIndex: 'ratio',
  253. customRender: (text, record, index) => {
  254. return this.BaseTool.Amount.formatter(text)
  255. }
  256. },
  257. {
  258. title: '描述',
  259. dataIndex: 'description'
  260. },
  261. {
  262. title: '备注',
  263. dataIndex: 'remark'
  264. },
  265. {
  266. title: '操作',
  267. key: 'action',
  268. width: '200px',
  269. align: 'center',
  270. scopedSlots: { customRender: 'action' }
  271. }
  272. ],
  273. // 下拉框map
  274. // 加载数据方法 必须为 Promise 对象
  275. loadData: parameter => {
  276. parameter = {
  277. ...parameter,
  278. ...this.queryParam,
  279. dataScope: {
  280. sortBy: 'desc',
  281. sortName: 'created_time'
  282. }
  283. }
  284. return getRemoteOpcPage(Object.assign(parameter, this.queryParam))
  285. .then(res => {
  286. return res.data
  287. })
  288. },
  289. selectedRowKeys: [],
  290. selectedRows: [],
  291. yesNoMap: {},
  292. options: {
  293. alert: {
  294. show: true,
  295. clear: () => {
  296. this.selectedRowKeys = []
  297. }
  298. },
  299. rowSelection: {
  300. selectedRowKeys: this.selectedRowKeys,
  301. onChange: this.onSelectChange
  302. }
  303. },
  304. optionAlertShow: false
  305. }
  306. },
  307. created () {
  308. // 下拉框map
  309. this.tableOption()
  310. this.map = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REMOTE_OPC)
  311. this.yesNoMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  312. },
  313. methods: {
  314. tableOption () {
  315. if (!this.optionAlertShow) {
  316. this.options = {
  317. alert: {
  318. show: true,
  319. clear: () => {
  320. this.selectedRowKeys = []
  321. }
  322. },
  323. rowSelection: {
  324. selectedRowKeys: this.selectedRowKeys,
  325. onChange: this.onSelectChange,
  326. getCheckboxProps: record => ({
  327. props: {
  328. disabled: false,
  329. name: record.id
  330. }
  331. })
  332. }
  333. }
  334. this.optionAlertShow = true
  335. } else {
  336. this.options = {
  337. alert: false,
  338. rowSelection: null
  339. }
  340. this.optionAlertShow = false
  341. }
  342. },
  343. batchDelete (id) {
  344. let ids = []
  345. if (this.BaseTool.String.isBlank(id)) {
  346. const length = this.selectedRows.length
  347. if (length === 0) {
  348. this.$message.info('请选择要删除的记录')
  349. return
  350. }
  351. ids = this.selectedRows.map(item => item.id)
  352. } else {
  353. ids = [id]
  354. }
  355. deleteRemoteOpcs(ids).then(res => {
  356. this.$message.info('删除成功')
  357. this.handleOk()
  358. this.$refs.table.clearSelected()
  359. })
  360. },
  361. update (updateType, value) {
  362. let ids = []
  363. const length = this.selectedRows.length
  364. if (length === 0) {
  365. this.$message.info('请选择要修改的数据')
  366. return
  367. }
  368. ids = this.selectedRows.map(item => item.id)
  369. updateRemoteOpcs({ updateType: updateType, value: value, ids: ids }).then(res => {
  370. this.handleOk()
  371. })
  372. },
  373. handleAdd () {
  374. const modal = this.$refs.baseModal
  375. modal.base({
  376. ...this.$route.query
  377. })
  378. },
  379. handleAddFetch (record) {
  380. fetchRemoteOpc({ id: record.id }).then(res => {
  381. const modal = this.$refs.baseModal
  382. const data = res.data
  383. data.id = null
  384. data.positionNum = null
  385. data.sbName = null
  386. data.description = null
  387. data.fetchFlag = 0
  388. data.remark = null
  389. modal.base(data)
  390. })
  391. },
  392. handleEdit (record) {
  393. fetchRemoteOpc({ id: record.id }).then(res => {
  394. const modal = this.$refs.baseModal
  395. modal.base(res.data)
  396. })
  397. },
  398. handleView (record) {
  399. // this.visible = false
  400. fetchRemoteOpc({ id: record.id }).then(res => {
  401. const modal = this.$refs.detailModal
  402. modal.base(res.data)
  403. })
  404. },
  405. doAddAll () {
  406. const parameter = {
  407. ...this.queryParam,
  408. sbIds: this.selectedRowKeys
  409. }
  410. addToServerRemoteOpcs(parameter).then(res => {
  411. this.$message.info('已添加,100秒后自动采集')
  412. })
  413. },
  414. doTestAdd (record) {
  415. updateInfluxDB(record).then(res => {
  416. this.$message.info('已添加')
  417. })
  418. },
  419. doTestAddBatch (record) {
  420. updateInfluxDBBatch(record).then(res => {
  421. this.$message.info('已批量添加')
  422. })
  423. },
  424. doTestSelect (record) {
  425. const parameter = {}
  426. parameter.id = record.id
  427. parameter.type = 1
  428. queryInfluxDBHistory(parameter).then(res => {
  429. console.log(res.data)
  430. this.$message.info('已查询')
  431. })
  432. },
  433. handleOk () {
  434. this.visible = true
  435. this.$refs.table.refresh()
  436. },
  437. onSelectChange (selectedRowKeys, selectedRows) {
  438. this.selectedRowKeys = selectedRowKeys
  439. this.selectedRows = selectedRows
  440. },
  441. resetSearchForm () {
  442. this.queryParam = {
  443. createdFlag: this.createdFlag
  444. }
  445. this.$refs.table.refresh(true)
  446. },
  447. doExport () {
  448. const parameter = {
  449. ...this.queryParam,
  450. ids: this.selectedRowKeys,
  451. dataScope: {
  452. sortBy: 'asc',
  453. sortName: 'no'
  454. }
  455. }
  456. exportRemoteOpc(parameter).then(file => {
  457. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  458. })
  459. },
  460. doImport () {
  461. this.$refs.importModal.base()
  462. },
  463. handleEnter () {
  464. this.$refs.table.refresh(true)
  465. }
  466. }
  467. }
  468. </script>