DeviceInfo.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="c-info">
  3. <div class="l-flex--row has-bottom-padding u-bold">
  4. <span class="c-sibling-item">设备信息</span>
  5. <span
  6. v-if="hasEditPermission"
  7. class="c-sibling-item c-info__edit u-pointer"
  8. @click="toEdit"
  9. >
  10. <i class="el-icon-edit" />
  11. 编辑
  12. </span>
  13. </div>
  14. <div class="l-flex--row c-info__block">
  15. <div class="l-flex--row l-flex__fill c-info__item">
  16. <div class="l-flex__none c-info__title">设备名称</div>
  17. <div class="l-flex__fill c-info__value">{{ device.name }}</div>
  18. </div>
  19. <div class="l-flex--row l-flex__fill c-info__item">
  20. <div class="l-flex__none c-info__title">产品</div>
  21. <div class="l-flex__fill c-info__value">{{ device.productName }}</div>
  22. </div>
  23. </div>
  24. <div class="l-flex--row c-info__block">
  25. <div class="l-flex--row l-flex__fill c-info__item">
  26. <div class="l-flex__none c-info__title">MAC</div>
  27. <div class="l-flex__fill c-info__value">{{ device.mac }}</div>
  28. </div>
  29. <div class="l-flex--row l-flex__fill c-info__item">
  30. <div class="l-flex__none c-info__title">序列号</div>
  31. <div class="l-flex__fill c-info__value">{{ device.serialNumber }}</div>
  32. </div>
  33. </div>
  34. <div class="l-flex--row c-info__block">
  35. <div class="l-flex--row l-flex__fill c-info__item">
  36. <div class="l-flex__none c-info__title">分辨率</div>
  37. <div class="l-flex__fill c-info__value">{{ device.resolutionRatio }}</div>
  38. </div>
  39. <div class="l-flex--row l-flex__fill c-info__item">
  40. <div class="l-flex__none c-info__title">创建时间</div>
  41. <div class="l-flex__fill c-info__value">{{ device.createTime }}</div>
  42. </div>
  43. </div>
  44. <div class="l-flex--row c-info__block">
  45. <div class="l-flex--row l-flex__fill c-info__item">
  46. <div class="l-flex__none c-info__title">地址</div>
  47. <div class="l-flex__fill c-info__value primary">{{ device.remark }}</div>
  48. </div>
  49. </div>
  50. <el-dialog
  51. title="编辑"
  52. :visible.sync="show"
  53. custom-class="c-dialog"
  54. :close-on-click-modal="false"
  55. >
  56. <div class="c-form">
  57. <div class="c-form__section">
  58. <span class="c-form__label required">名称:</span>
  59. <el-input
  60. v-model.trim="info.name"
  61. class="c-form__item"
  62. maxlength="50"
  63. show-word-limit
  64. />
  65. </div>
  66. <div class="c-form__section">
  67. <span class="c-form__label required">地址:</span>
  68. <el-input
  69. v-model="info.remark"
  70. class="c-form__item"
  71. type="textarea"
  72. :rows="3"
  73. maxlength="100"
  74. show-word-limit
  75. />
  76. </div>
  77. </div>
  78. <template #footer>
  79. <button
  80. class="o-button"
  81. @click="save"
  82. >
  83. 确定
  84. </button>
  85. <button
  86. class="o-button cancel"
  87. @click="close"
  88. >
  89. 取消
  90. </button>
  91. </template>
  92. </el-dialog>
  93. </div>
  94. </template>
  95. <script>
  96. import { mapGetters } from 'vuex'
  97. import { updateDevice } from '@/api/device'
  98. export default {
  99. name: 'DeviceInfo',
  100. props: {
  101. device: {
  102. type: Object,
  103. default: null
  104. }
  105. },
  106. data () {
  107. return {
  108. show: false,
  109. info: {}
  110. }
  111. },
  112. computed: {
  113. ...mapGetters(['hasEditPermission'])
  114. },
  115. methods: {
  116. toEdit () {
  117. this.info = {
  118. name: this.device.name,
  119. remark: this.device.remark
  120. }
  121. this.show = true
  122. },
  123. close () {
  124. this.show = false
  125. },
  126. save () {
  127. if (!this.info.name) {
  128. this.$message({
  129. type: 'warning',
  130. message: '名称不能为空'
  131. })
  132. return
  133. }
  134. if (!this.info.remark) {
  135. this.$message({
  136. type: 'warning',
  137. message: '地址不能为空'
  138. })
  139. return
  140. }
  141. if (this.info.name === this.device.name && this.info.remark === this.device.remark) {
  142. this.close()
  143. return
  144. }
  145. updateDevice({
  146. id: this.device.id,
  147. ...this.info
  148. }).then(() => {
  149. Object.assign(this.device, this.info)
  150. this.close()
  151. })
  152. }
  153. }
  154. }
  155. </script>