index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. />
  12. <confirm-dialog
  13. ref="editDialog"
  14. :title="dialogTitle"
  15. @confirm="onSave"
  16. >
  17. <div class="c-grid-form u-align-self--center">
  18. <span class="c-grid-form__label required">名称:</span>
  19. <el-input
  20. v-model.trim="currObj.name"
  21. placeholder="请填写分组名称"
  22. maxlength="50"
  23. />
  24. <span class="c-grid-form__label">备注:</span>
  25. <el-input
  26. v-model="currObj.remark"
  27. type="textarea"
  28. maxlength="100"
  29. :rows="3"
  30. show-word-limit
  31. />
  32. </div>
  33. </confirm-dialog>
  34. <table-dialog
  35. ref="subDeviceDialog"
  36. title="设备"
  37. :schema="subDeviceSchema"
  38. size="large"
  39. />
  40. <table-dialog
  41. ref="deviceDialog"
  42. title="添加设备"
  43. :schema="deviceSchema"
  44. append-to-body
  45. @choosen="onChooseDevice"
  46. />
  47. </wrapper>
  48. </template>
  49. <script>
  50. import {
  51. getDeviceGroups,
  52. addDeviceGroup,
  53. updateDeviceGroup,
  54. deleteDeviceGroup,
  55. getDevicesByGroup,
  56. getDevices,
  57. addDeviceToGroup,
  58. deleteDeviceFromGroup
  59. } from '@/api/device'
  60. import mixin from '../mixins'
  61. export default {
  62. name: 'DeviceGroup',
  63. mixins: [mixin],
  64. data () {
  65. return {
  66. type: '分组',
  67. proxy: {
  68. add: addDeviceGroup,
  69. update: updateDeviceGroup,
  70. del: deleteDeviceGroup
  71. },
  72. schema: {
  73. condition: { name: '' },
  74. list: getDeviceGroups,
  75. buttons: [
  76. { type: 'add', on: this.onAdd }
  77. ],
  78. filters: [
  79. { key: 'name', type: 'search', placeholder: '分组名称' }
  80. ],
  81. cols: [
  82. { prop: 'name', label: '分组名称' },
  83. { prop: 'remark', label: '备注' },
  84. {
  85. type: 'invoke', render: [
  86. { label: '编辑', on: this.onEdit },
  87. { label: '设备', on: this.onViewDevices },
  88. { label: '删除', on: this.onDel }
  89. ]
  90. }
  91. ]
  92. },
  93. subDeviceSchema: {
  94. singlePage: true,
  95. list: this.getDevicesByGroup,
  96. buttons: [
  97. { type: 'add', label: '添加设备', on: this.onAddDevice }
  98. ],
  99. cols: [
  100. { prop: 'name', label: '设备名称' },
  101. { prop: 'productName', label: '产品' },
  102. { prop: 'serialNumber', label: '序列号' },
  103. { prop: 'mac', label: 'MAC' },
  104. { prop: 'resolutionRatio', label: '分辨率' },
  105. { prop: 'remark', label: '备注' },
  106. {
  107. type: 'invoke', render: [
  108. { label: '移除', on: this.onDelDevice }
  109. ]
  110. }
  111. ]
  112. },
  113. deviceSchema: {
  114. condition: { name: '' },
  115. filters: [
  116. { key: 'name', type: 'search', placeholder: '设备名称' }
  117. ],
  118. list: getDevices,
  119. cols: [
  120. { prop: 'name', label: '设备名称' },
  121. { prop: 'productName', label: '产品' },
  122. { prop: 'serialNumber', label: '序列号' },
  123. { prop: 'mac', label: 'MAC' },
  124. { prop: 'resolutionRatio', label: '分辨率' },
  125. { prop: 'remark', label: '备注' }
  126. ]
  127. }
  128. }
  129. },
  130. methods: {
  131. onSave (done) {
  132. if (!this.currObj.name) {
  133. this.$message({
  134. type: 'warning',
  135. message: '名称不能为空'
  136. })
  137. return false
  138. }
  139. this.save(done).then(() => {
  140. if (this.isAdd) {
  141. this.$refs.table.resetCondition({ name: this.currObj.name })
  142. } else {
  143. this.$refs.table.pageTo()
  144. }
  145. })
  146. },
  147. onViewDevices ({ id }) {
  148. this.$refs.subDeviceDialog.show({ id })
  149. },
  150. getDevicesByGroup ({ id }) {
  151. return getDevicesByGroup(id)
  152. },
  153. onDelDevice (device, index) {
  154. const table = this.$refs.subDeviceDialog.getTable()
  155. deleteDeviceFromGroup(table.getCondition().id, device).then(() => {
  156. table.getData().splice(index, 1)
  157. })
  158. },
  159. onAddDevice () {
  160. this.$refs.deviceDialog.show()
  161. },
  162. onChooseDevice ({ value: { id }, done }) {
  163. const table = this.$refs.subDeviceDialog.getTable()
  164. addDeviceToGroup(table.getCondition().id, id).then(() => {
  165. done()
  166. table.pageTo()
  167. })
  168. }
  169. }
  170. }
  171. </script>