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
| <template>
| <div class="list-card">
| <div class="column" v-for="(item, idx) in list" :key="'column_' + idx">
| <div
| class="list-item"
| v-for="(iitem, iidx) in item"
| :key="'item_' + iidx"
| >
| <div class="content" v-if="iitem">
| <div class="label">{{ iitem.label }}:</div>
| <div class="value">
| {{ getValue(iitem) }}
| </div>
| </div>
| </div>
| </div>
| </div>
| </template>
|
| <script>
| export default {
| name: "",
| props: {
| valueObj: {
| type: Object,
| default() {
| return {};
| },
| },
| datas: {
| type: Array,
| required: true,
| },
| emptyIdxs: {
| type: Array,
| default() {
| return [];
| },
| },
| rows: {
| type: Number,
| default: 3,
| },
| cols: {
| type: Number,
| default: 2,
| },
| },
| computed: {
| // 添加空行 并转为二维数组
| list() {
| let { datas, emptyIdxs } = this;
| // let list = JSON.parse(JSON.stringify(datas));
| let list = [...datas];
| emptyIdxs.sort((a, b) => a - b);
| for (let i = 0, j = emptyIdxs.length; i < j; i++) {
| list.splice(emptyIdxs[i], 0, null);
| }
| list = this.chunkArray(list, this.rows, this.cols);
| return list;
| },
| },
| data() {
| return {};
| },
| components: {},
| methods: {
| getValue(iitem) {
| let valueObj = this.valueObj;
| let key = valueObj[iitem.flag] ? "key1" : "key0";
| if (iitem.config) {
| return `${iitem.config[valueObj[iitem[key]]] || '未知'} [${valueObj[iitem[key]]}]`;
| } else if (iitem.formatFN) {
| return iitem.formatFN(valueObj[iitem[key]]);
| } else {
| return valueObj[iitem[key]];
| }
| },
| chunkArray(array, chunkSize, len) {
| let chunks = [];
| for (let i = 0; i < array.length; i += chunkSize) {
| chunks.push(array.slice(i, i + chunkSize));
| }
| // 只有最后一个子元素可能不够长度补null 或子元素个数不够 差的组 全部补null
| let realLen = chunks.length;
| let lastItem = chunks[realLen - 1];
| if (lastItem.length < chunkSize) {
| lastItem.push(...new Array(chunkSize - lastItem.length));
| }
| if (realLen < len) {
| let arr = new Array(chunkSize);
| for (let m = len - realLen; m > 0; m--) {
| chunks.push(arr);
| }
| }
| return chunks;
| },
| },
|
| mounted() {},
| };
| </script>
|
| <style scoped lang="less">
| .list-card {
| // background: #011f39;
| height: 100%;
| display: flex;
| flex-direction: row;
| .column {
| flex: 1;
| display: flex;
| flex-direction: column;
| & + .column {
| margin-left: 6px;
| }
| .list-item {
| flex: 1;
| display: flex;
| align-items: center;
| padding-left: 10px;
| // height: 20px;
| // line-height: 20px;
| background: #153952;
| &:nth-child(2n) {
| background: rgba(21, 57, 82, 0.6);
| }
| }
| }
| .content {
| flex: 1;
| display: flex;
| justify-content: space-between;
| .value {
| width: 88px;
| margin-left: 6px;
| color: #75e8f2;
| flex-shrink: 0;
| }
| }
| }
| </style>
|
|