CloudList.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <!-- 云机列表 -->
  3. <div class="cloud-list-wrap" >
  4. <van-list :style="listStyle" :finished="false">
  5. <div v-for="item in list" :key="item.userCardId" class="cloud-list-item-wrap flex" :class="{'cloud-list-item-active': activeId === item.userCardId}" @click="activeId = item.userCardId">
  6. <!-- 云机套餐头像 -->
  7. <div class="cloud-id-avatar-wrap items-center pr-2">
  8. <van-image
  9. width="24"
  10. height="24"
  11. src="https://img01.yzcdn.cn/vant/cat.jpeg"
  12. />
  13. </div>
  14. <!-- 云机名称和ID -->
  15. <div class="cloud-id-desc-wrap">
  16. <div class="cloud-id-name mb-1">{{ item.diskName }}</div>
  17. <div class="cloud-id-detail-wrap">ID {{ item.userCardId }}</div>
  18. </div>
  19. </div>
  20. </van-list>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'CloudList',
  26. props: {
  27. // 云机列表高度
  28. height: {
  29. type: String,
  30. default: '50px'
  31. },
  32. // 云机列表的选中项
  33. userCardId: {
  34. type: [String, Number],
  35. default: ''
  36. },
  37. // 当前选择的云机分组id 默认-1, 代表全部设备
  38. activeGroupId: {
  39. type: Number,
  40. default: -1,
  41. },
  42. // 所有云机列表
  43. cloudList: {
  44. type: Array,
  45. default: () => []
  46. }
  47. },
  48. data() {
  49. return {
  50. activeId: +this.userCardId,
  51. }
  52. },
  53. computed: {
  54. // 云机列表高度
  55. listStyle() {
  56. return {height: this.height, overflowY: 'auto'}
  57. },
  58. list() {
  59. // 如果当前分组id为-1, 则返回所有云机列表
  60. if(this.activeGroupId === -1 ) {
  61. return this.cloudList;
  62. }
  63. // 过滤出当前分组的云机列表
  64. return this.cloudList.filter(item => item.groupId === this.activeGroupId);
  65. }
  66. },
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .cloud-list-item-wrap{
  71. padding: 8px 16px;
  72. border: 1px solid transparent;
  73. &.cloud-list-item-active{
  74. background-color: rgba(254,174,77,0.1);
  75. border: 1px solid #FEAE4D;
  76. }
  77. }
  78. .cloud-id-avatar-wrap{
  79. display: flex;
  80. }
  81. .cloud-id-desc-wrap{
  82. text-align: left;
  83. flex: 1;
  84. color: #F9F9F9;
  85. font-size: 10px;
  86. }
  87. </style>