index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <div
  9. v-loading="options.loading"
  10. class="l-flex__auto l-flex--col"
  11. >
  12. <div class="l-flex__none l-flex--row has-bottom-padding">
  13. <div class="l-flex__auto c-sibling-item" />
  14. <div class="l-flex__none c-sibling-item">
  15. <svg-icon
  16. class="c-sibling-item o-menu-icon u-pointer"
  17. :class="{ active: gridClass === 'one' }"
  18. icon-class="menu-one"
  19. @click="onChange(1)"
  20. />
  21. <svg-icon
  22. class="c-sibling-item o-menu-icon u-pointer"
  23. :class="{ active: gridClass === 'four' }"
  24. icon-class="menu-four"
  25. @click="onChange(4)"
  26. />
  27. <svg-icon
  28. class="c-sibling-item o-menu-icon u-pointer"
  29. :class="{ active: gridClass === 'nine' }"
  30. icon-class="menu-nine"
  31. @click="onChange(9)"
  32. />
  33. </div>
  34. </div>
  35. <div class="l-flex__auto u-overflow-y--auto">
  36. <div
  37. class="c-back-grid"
  38. :class="gridClass"
  39. >
  40. <device-player
  41. v-for="item in options.list"
  42. :key="item.identifier"
  43. :device="item"
  44. >
  45. <div class="o-video__tag" />
  46. <div class="c-footer u-ellipsis">{{ item.name }}</div>
  47. </device-player>
  48. </div>
  49. <pagination
  50. :total="options.totalCount"
  51. :page.sync="options.params.pageNum"
  52. :limit.sync="options.params.pageSize"
  53. @pagination="getDevices"
  54. />
  55. </div>
  56. <status-wrapper
  57. v-if="isAbnormal"
  58. :error="options.error"
  59. @click="getDevices"
  60. />
  61. </div>
  62. </wrapper>
  63. </template>
  64. <script>
  65. import { getDevices } from '@/api/device'
  66. import { createListOptions } from '@/utils'
  67. export default {
  68. name: 'Back',
  69. data () {
  70. return {
  71. options: createListOptions({ activate: 2, pageSize: 4 })
  72. }
  73. },
  74. computed: {
  75. gridClass () {
  76. switch (this.options.params.pageSize) {
  77. case 4:
  78. return 'four'
  79. case 9:
  80. return 'nine'
  81. default:
  82. return 'one'
  83. }
  84. },
  85. isAbnormal () {
  86. const options = this.options
  87. return options.error || !options.loading && options.list.length === 0
  88. }
  89. },
  90. created () {
  91. this.getDevices()
  92. },
  93. methods: {
  94. getDevices () {
  95. const options = this.options
  96. options.error = false
  97. options.loading = true
  98. options.list = []
  99. getDevices(options.params).then(
  100. ({ data, totalCount }) => {
  101. options.totalCount = totalCount
  102. options.list = data
  103. },
  104. () => {
  105. options.error = true
  106. options.totalCount = 0
  107. options.list = []
  108. }
  109. ).finally(() => {
  110. options.loading = false
  111. })
  112. },
  113. onChange (num) {
  114. const params = this.options.params
  115. if (num === params.pageSize) {
  116. return
  117. }
  118. params.pageSize = num
  119. params.pageNum = 1
  120. this.getDevices()
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .o-menu-icon {
  127. color: #d5d9e4;
  128. font-size: 32px;
  129. &.active {
  130. color: $blue;
  131. }
  132. }
  133. .c-back-grid {
  134. display: grid;
  135. grid-template-rows: max-content;
  136. grid-row-gap: 4px;
  137. grid-column-gap: 4px;
  138. min-height: 0;
  139. min-width: 0;
  140. &.one {
  141. grid-template-columns: 1fr;
  142. }
  143. &.four {
  144. grid-template-columns: 1fr 1fr;
  145. }
  146. &.nine {
  147. grid-template-columns: 1fr 1fr 1fr;
  148. }
  149. }
  150. </style>