ZZJ
2022-03-09 cc7401e771e13b40bb7dea11ec26da3acfc8e5c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<template>
  <div class="ClusterList">
    <div class="title">集群列表</div>
    <div v-if="showCluster">
      <div class="List">
        <ClusterCard
          v-for="i in listlength"
          :key="i"
          @showDetail="showList"
        ></ClusterCard>
        <div
          class="ClusterCard"
          v-for="i in emptylength"
          :key="'empty' + i"
        ></div>
      </div>
      <el-pagination
        @current-change="refrash"
        @size-change="handleSizeChange"
        :small="true"
        :current-page="page"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[5, 10, 15, 20, 25]"
        :total="total"
        background
      ></el-pagination>
    </div>
 
    <EquipmentForm v-else @hiddenList="hiddenList"></EquipmentForm>
  </div>
</template>
 
<script>
import ClusterCard from "@/views/hashrate/components/ClusterCard";
import EquipmentForm from "@/views/hashrate/components/EquipmentForm";
export default {
  mounted() {
    this.getEmptyElement();
    this.addSizeListener();
  },
  components: {
    ClusterCard,
    EquipmentForm,
  },
  data() {
    return {
      showCluster: true,
      listlength: 11,
      emptylength: 0,
      page: 1,
      size: 10,
      total: 100,
    };
  },
  methods: {
    addSizeListener() {
      window.onresize = () => {
        this.getEmptyElement();
      };
    },
    //回填空白项
    getEmptyElement() {
      //  获取屏幕总宽度(即浏览器窗口的宽度)
      var allWidth = document.body.clientWidth;
 
      // 获取单个item项宽度(即单个item元素的宽度是多少)
      var dom = document.querySelector(".ClusterCard").scrollWidth;
 
      // [结果取整] 计算一行能放多少个item项(即一排能放多少个元素)
      var line = parseInt(allWidth / dom);
 
      // 计算需要补多少个item项(元素不需要补的时候(=0)必须作处理)
      // 公式: ( [总item项数量] % [一行能放多少个item项] )
      // 如果等于0则证明不需要补 | 反之一行减去补全
      var result =
        this.listlength % line == 0 ? 0 : line - (this.listlength % line);
 
      //通知视图进行补元素(渲染视图上的隐藏元素)
      this.emptylength = result;
    },
    handleSizeChange() {},
    refrash() {},
    showList() {
      this.showCluster = false;
    },
    hiddenList() {
      this.showCluster = true;
    },
  },
};
</script>
 
<style lang="scss" scoped>
.ClusterList {
  box-sizing: border-box;
  margin-bottom: 60px;
  padding: 20px;
  background-color: #fff;
  .title {
    margin-bottom: 30px;
    padding-left: 10px;
    height: 20px;
    line-height: 20px;
    border-left: 4px solid #0065ff;
    font-size: 16px;
    font-weight: 700;
  }
 
  .List {
    display: flex;
    flex-wrap: wrap;
 
    .ClusterCard {
      margin-right: 24px;
      margin-bottom: 24px;
      padding: 20px;
      flex: 1;
    }
  }
 
  .el-pagination ::v-deep {
    margin-top: 30px;
    text-align: right;
    height: 24px;
    .el-pagination__sizes {
      margin-right: 0;
    }
 
    button {
      margin: 0;
      background-color: #fff;
      border: 1px solid #c0c5cc;
      border-radius: 2px;
    }
 
    .number {
      background-color: #fff;
 
      &:not(.disabled):hover {
        color: #0065ff;
      }
 
      &:not(.disabled).active {
        background-color: #0065ff;
        color: #fff;
      }
    }
 
    .el-input .el-input__inner {
      padding-left: 0;
      height: 22px;
      line-height: 22px;
 
      &:hover,
      &:focus {
        border-color: #0065ff;
      }
    }
 
    .el-input__suffix {
      height: 120%;
      top: -1px;
    }
 
    .el-pagination__total {
      font-weight: 700;
    }
  }
}
</style>