Device.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <schema-table
  3. ref="table"
  4. :schema="schema"
  5. >
  6. <table-dialog
  7. ref="tableDialog"
  8. size="lg"
  9. title="分配设备"
  10. :schema="deviceSchema"
  11. @row-dblclick="onChoosen"
  12. />
  13. </schema-table>
  14. </template>
  15. <script>
  16. import { mapGetters } from 'vuex'
  17. import {
  18. getDevicesByAdmin,
  19. getBoundDevices,
  20. bindDeviceToObject,
  21. unbindDevice
  22. } from '@/api/device'
  23. export default {
  24. name: 'Device',
  25. props: {
  26. group: {
  27. type: Object,
  28. required: true
  29. }
  30. },
  31. data () {
  32. return {
  33. schema: {
  34. list: this.getDevices,
  35. buttons: [
  36. { type: 'add', label: '分配', on: this.onAdd }
  37. ],
  38. filters: [
  39. { key: 'name', type: 'search', placeholder: '设备名称' }
  40. ],
  41. cols: [
  42. { prop: 'name', label: '设备名称', 'min-width': 120 },
  43. { prop: 'serialNumber', label: '序列号', 'min-width': 140 },
  44. { prop: 'mac', label: 'MAC', 'min-width': 140 },
  45. { prop: 'address', label: '地址' },
  46. { type: 'invoke', width: 100, render: [
  47. { label: '移除', on: this.onDel }
  48. ] }
  49. ]
  50. }
  51. }
  52. },
  53. computed: {
  54. ...mapGetters(['tenant']),
  55. deviceSchema () {
  56. return {
  57. list: getDevicesByAdmin,
  58. condition: { name: '', tenant: this.tenant },
  59. filters: [
  60. { key: 'name', type: 'search', placeholder: '设备名称' }
  61. ],
  62. cols: [
  63. { prop: 'name', label: '设备名称', 'min-width': 120 },
  64. { prop: 'serialNumber', label: '序列号', 'min-width': 140 },
  65. { prop: 'mac', label: 'MAC', 'min-width': 140 },
  66. { prop: 'address', label: '地址', 'min-width': 100 }
  67. ]
  68. }
  69. }
  70. },
  71. watch: {
  72. group () {
  73. this.$refs.table.pageTo(1)
  74. }
  75. },
  76. methods: {
  77. getDevices (params) {
  78. return getBoundDevices({
  79. org: this.group.path,
  80. ...params
  81. })
  82. },
  83. onAdd () {
  84. this.$refs.tableDialog.show()
  85. },
  86. onChoosen ({ id }) {
  87. bindDeviceToObject(id, this.group.path).then(() => {
  88. this.$message({
  89. type: 'success',
  90. message: '分配成功'
  91. })
  92. this.$refs.table.pageTo(1)
  93. })
  94. },
  95. onDel (device) {
  96. unbindDevice(device).then(() => {
  97. this.$refs.table.decrease(1)
  98. })
  99. }
  100. }
  101. }
  102. </script>