Tenant.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <wrapper
  3. :vertical="false"
  4. fill
  5. margin
  6. padding
  7. background
  8. >
  9. <template v-if="groups">
  10. <div class="c-tree-sidebar u-overflow-y--auto">
  11. <el-tree
  12. ref="groupTree"
  13. :data="groups"
  14. class="c-tree-sidebar__main"
  15. node-key="path"
  16. highlight-current
  17. @node-click="onGroupTreeClick"
  18. />
  19. </div>
  20. <div class="l-flex__auto l-flex--col">
  21. <el-tabs
  22. v-model="active"
  23. class="c-tabs has-bottom-padding"
  24. >
  25. <el-tab-pane
  26. label="设备"
  27. name="Device"
  28. />
  29. <el-tab-pane
  30. label="产品"
  31. name="Product"
  32. />
  33. <el-tab-pane
  34. label="产品类型"
  35. name="ProductType"
  36. />
  37. </el-tabs>
  38. <component
  39. :is="active"
  40. v-if="group"
  41. :group="group"
  42. />
  43. </div>
  44. </template>
  45. <template v-else>
  46. <div
  47. v-loading="loading"
  48. class="l-flex__auto l-flex--row center"
  49. >
  50. <template v-if="!loading">
  51. <warning
  52. v-if="error"
  53. @click="getTreeData"
  54. />
  55. <div
  56. v-else
  57. class="u-bold"
  58. >
  59. 暂无租户,请先添加租户
  60. </div>
  61. </template>
  62. </div>
  63. </template>
  64. </wrapper>
  65. </template>
  66. <script>
  67. import { getTopGroups } from '@/api/user'
  68. import ProductType from './ProductType'
  69. import Product from './Product'
  70. import Device from './Device'
  71. export default {
  72. name: 'TenantDeviceManagement',
  73. components: {
  74. ProductType,
  75. Product,
  76. Device
  77. },
  78. data () {
  79. return {
  80. loading: true,
  81. error: false,
  82. active: 'Device',
  83. groups: null,
  84. group: null
  85. }
  86. },
  87. created () {
  88. this.getTreeData()
  89. },
  90. methods: {
  91. getTreeData () {
  92. this.loading = true
  93. this.error = false
  94. getTopGroups().then(
  95. ({ data }) => {
  96. if (data.length) {
  97. this.groups = data
  98. this.group = this.groups[0]
  99. this.$nextTick(() => {
  100. this.$refs.groupTree.setCurrentKey(this.group.path)
  101. })
  102. }
  103. },
  104. () => {
  105. this.error = true
  106. }
  107. ).finally(() => {
  108. this.loading = false
  109. })
  110. },
  111. onGroupTreeClick (group) {
  112. if (!this.group || this.group.id !== group.id) {
  113. this.group = null
  114. this.$nextTick(() => {
  115. this.group = group
  116. })
  117. }
  118. }
  119. }
  120. }
  121. </script>