PduConfigDialog.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <confirm-dialog
  3. ref="dialog"
  4. title="新增PDU"
  5. @confirm="onConfirm"
  6. >
  7. <div class="c-grid-form u-align-self--center">
  8. <span class="c-grid-form__label u-required">
  9. 厂商
  10. </span>
  11. <schema-select
  12. ref="manufacturer"
  13. v-model="item.manufacturerKey"
  14. class="u-width"
  15. placeholder="请选择厂商"
  16. :schema="manufacturerSelectSchema"
  17. />
  18. <span class="c-grid-form__label u-required">
  19. 型号
  20. </span>
  21. <el-input
  22. v-model.trim="item.model"
  23. placeholder="最多50个字符"
  24. maxlength="50"
  25. clearable
  26. />
  27. <span class="c-grid-form__label u-required">
  28. PDU地址
  29. </span>
  30. <el-input
  31. v-model.trim="item.ip"
  32. placeholder="10.180.88.84"
  33. clearable
  34. />
  35. <span class="c-grid-form__label u-required">
  36. 唯一标识
  37. </span>
  38. <el-input
  39. v-model.trim="item.identifier"
  40. placeholder="设备mac,例:18d79350592b"
  41. maxlength="50"
  42. clearable
  43. />
  44. </div>
  45. </confirm-dialog>
  46. </template>
  47. <script>
  48. import { ThirdPartyDevice } from '@/constant'
  49. import {
  50. getManufacturersByType,
  51. addPdu
  52. } from '@/api/external'
  53. export default {
  54. name: 'PduConfigDialog',
  55. data () {
  56. return {
  57. manufacturerSelectSchema: {
  58. remote: this.getManufacturersByType,
  59. value: 'manufacturerKey',
  60. label: 'manufacturerName'
  61. },
  62. item: {}
  63. }
  64. },
  65. methods: {
  66. show () {
  67. this.item = {
  68. identifier: '',
  69. manufacturerKey: '',
  70. model: '',
  71. ip: ''
  72. }
  73. this.$refs.dialog.show()
  74. },
  75. getManufacturersByType () {
  76. return getManufacturersByType(ThirdPartyDevice.PDU)
  77. },
  78. onConfirm (done) {
  79. if (!this.item.manufacturerKey) {
  80. this.$message({
  81. type: 'warning',
  82. message: '请选择厂商'
  83. })
  84. return
  85. }
  86. if (!this.item.model) {
  87. this.$message({
  88. type: 'warning',
  89. message: '请填写型号'
  90. })
  91. return
  92. }
  93. if (!this.item.identifier) {
  94. this.$message({
  95. type: 'warning',
  96. message: '请填写唯一标识'
  97. })
  98. return
  99. }
  100. if (!this.item.ip) {
  101. this.$message({
  102. type: 'warning',
  103. message: '请填写网关服务器地址'
  104. })
  105. return
  106. }
  107. const key = this.item.manufacturerKey
  108. addPdu({
  109. manufacturerName: this.$refs.manufacturer.getOptions().find(({ value }) => value === key).label,
  110. ...this.item
  111. }).then(() => {
  112. done()
  113. this.$emit('confirm', this.item)
  114. })
  115. }
  116. }
  117. }
  118. </script>