CloudList.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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': userCardId === item.userCardId}" @click="changeCloud(item)">
  6. <!-- 云机套餐头像 -->
  7. <div class="cloud-id-avatar-wrap items-center pr-2">
  8. <van-image
  9. width="24"
  10. height="24"
  11. :src="imgFun(item.buyVipType, item.androidVersion)"
  12. >
  13. <!-- 图片加载中显示 -->
  14. <template v-slot:loading>
  15. <van-loading type="spinner" size="20" />
  16. </template>
  17. </van-image>
  18. </div>
  19. <!-- 云机名称和ID -->
  20. <div class="cloud-id-desc-wrap">
  21. <div class="cloud-id-name mb-1">{{ item.diskName }}</div>
  22. <div class="cloud-id-detail-wrap">ID {{ item.userCardId }}</div>
  23. </div>
  24. </div>
  25. </van-list>
  26. </div>
  27. </template>
  28. <script>
  29. export default {
  30. name: 'CloudList',
  31. props: {
  32. // 云机列表高度
  33. height: {
  34. type: String,
  35. default: '50px'
  36. },
  37. // 当前云机id
  38. userCardId: {
  39. type: [String, Number],
  40. default: ''
  41. },
  42. // 当前选择的云机分组id 默认-1, 代表全部设备
  43. activeGroupId: {
  44. type: Number,
  45. default: -1,
  46. },
  47. // 所有云机列表
  48. cloudList: {
  49. type: Array,
  50. default: () => []
  51. },
  52. // 云机套餐的图标
  53. imgFun: {
  54. type: Function,
  55. default: () => () => {}
  56. }
  57. },
  58. computed: {
  59. // 云机列表高度
  60. listStyle() {
  61. return {height: this.height, overflowY: 'auto'}
  62. },
  63. list() {
  64. // 如果当前分组id为-1, 则返回所有云机列表
  65. if(this.activeGroupId === -1 ) {
  66. return this.cloudList;
  67. }
  68. // 过滤出当前分组的云机列表
  69. return this.cloudList.filter(item => item.groupId === this.activeGroupId);
  70. }
  71. },
  72. methods: {
  73. // 切换云机
  74. changeCloud(item) {
  75. // 如果当前云机id和选中的云机id相同, 则不做任何操作
  76. if(+this.userCardId === item.userCardId) return;
  77. this.$emit('changeCloud', item);
  78. // 关闭popup
  79. this.$emit('update:levitatedSphereVisible', false);
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .cloud-list-item-wrap{
  86. padding: 8px 16px;
  87. border: 1px solid transparent;
  88. &.cloud-list-item-active{
  89. background-color: rgba(254,174,77,0.1);
  90. border: 1px solid #FEAE4D;
  91. }
  92. }
  93. .cloud-id-avatar-wrap{
  94. display: flex;
  95. }
  96. .cloud-id-desc-wrap{
  97. text-align: left;
  98. flex: 1;
  99. color: #F9F9F9;
  100. font-size: 10px;
  101. }
  102. </style>