PLC.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <schema-table
  3. ref="table"
  4. :schema="schema"
  5. >
  6. <confirm-dialog
  7. ref="editDialog"
  8. :title="dialogTitle"
  9. :append-to-body="true"
  10. @confirm="onConfirm"
  11. >
  12. <div class="c-grid-form u-align-self--center">
  13. <span class="c-grid-form__label required">名称:</span>
  14. <el-input
  15. v-model.trim="plc.name"
  16. placeholder="最多50个字符"
  17. maxlength="50"
  18. clearable
  19. />
  20. <span class="c-grid-form__label required">地址:</span>
  21. <el-input
  22. v-model.trim="plc.identifier"
  23. placeholder="最多50个字符"
  24. maxlength="50"
  25. clearable
  26. />
  27. <span class="c-grid-form__label">备注:</span>
  28. <el-input
  29. v-model.trim="plc.remark"
  30. type="textarea"
  31. maxlength="100"
  32. :rows="3"
  33. show-word-limit
  34. />
  35. </div>
  36. </confirm-dialog>
  37. </schema-table>
  38. </template>
  39. <script>
  40. import {
  41. getPLCs,
  42. addPLC,
  43. updatePLC,
  44. deletePLC
  45. } from '@/api/external'
  46. export default {
  47. name: 'PLCList',
  48. props: {
  49. gateway: {
  50. type: Object,
  51. required: true
  52. }
  53. },
  54. data () {
  55. return {
  56. plc: {},
  57. schema: {
  58. list: this.getPLCs,
  59. buttons: [
  60. { type: 'add', on: this.onAdd }
  61. ],
  62. cols: [
  63. { prop: 'name', label: '名称' },
  64. { prop: 'identifier', label: '地址' },
  65. { prop: 'remark', label: '备注' },
  66. { type: 'invoke', render: [
  67. { label: '编辑', on: this.onEdit },
  68. { label: '删除', on: this.onDel }
  69. ] }
  70. ]
  71. }
  72. }
  73. },
  74. computed: {
  75. dialogTitle () {
  76. return this.plc.id ? '编辑PLC' : '新增PLC'
  77. }
  78. },
  79. methods: {
  80. getPLCs (params) {
  81. return getPLCs({
  82. gatewayId: this.gateway.id,
  83. ...params
  84. })
  85. },
  86. onAdd () {
  87. this.plc = {
  88. name: '',
  89. identifier: '',
  90. remark: ''
  91. }
  92. this.$refs.editDialog.show()
  93. },
  94. onEdit ({ id, name, identifier, remark }) {
  95. this.plc = { id, name, identifier, remark }
  96. this.$refs.editDialog.show()
  97. },
  98. onConfirm (done) {
  99. if (!this.plc.name) {
  100. this.$message({
  101. type: 'warning',
  102. message: '请填写PLC名称'
  103. })
  104. return
  105. }
  106. if (!this.plc.identifier) {
  107. this.$message({
  108. type: 'warning',
  109. message: '请填写PLC标识'
  110. })
  111. return
  112. }
  113. if (this.plc.id) {
  114. this.onConfirmEdit(this.plc, done)
  115. } else {
  116. this.onConfirmAdd(this.plc, done)
  117. }
  118. },
  119. onConfirmAdd (plc, done) {
  120. addPLC({
  121. gatewayId: this.gateway.id,
  122. ...plc
  123. }).then(() => {
  124. done()
  125. this.$refs.table.resetCondition()
  126. })
  127. },
  128. onConfirmEdit (plc, done) {
  129. updatePLC(plc).then(() => {
  130. done()
  131. this.$refs.table.pageTo()
  132. })
  133. },
  134. onDel (plc) {
  135. deletePLC(plc).then(() => {
  136. this.$refs.table.decrease(1)
  137. })
  138. }
  139. }
  140. }
  141. </script>