CloudList.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. </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. // 当前云机id
  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. imgFun: {
  49. type: Function,
  50. default: () => () => {}
  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. methods: {
  68. // 切换云机
  69. changeCloud(item) {
  70. // 如果当前云机id和选中的云机id相同, 则不做任何操作
  71. if(+this.userCardId === item.userCardId) return;
  72. this.$emit('changeCloud', item);
  73. // 关闭popup
  74. this.$emit('update:levitatedSphereVisible', false);
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .cloud-list-item-wrap{
  81. padding: 8px 16px;
  82. border: 1px solid transparent;
  83. &.cloud-list-item-active{
  84. background-color: rgba(254,174,77,0.1);
  85. border: 1px solid #FEAE4D;
  86. }
  87. }
  88. .cloud-id-avatar-wrap{
  89. display: flex;
  90. }
  91. .cloud-id-desc-wrap{
  92. text-align: left;
  93. flex: 1;
  94. color: #F9F9F9;
  95. font-size: 10px;
  96. }
  97. </style>