Skip to content

Commit ed27e8d

Browse files
refactor: Table 骨架屏统一,优化骨架屏小屏下缩放问题 (#2921)
1 parent 5f5a2ab commit ed27e8d

44 files changed

Lines changed: 399 additions & 902 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<template>
2+
<content-loader
3+
:width="baseWidth"
4+
:style="{ transform: `scaleX(${resolvedScale})` }"
5+
:height="height"
6+
:speed="loadingConf.speed"
7+
:primary-color="loadingConf.primaryColor"
8+
:secondary-color="loadingConf.secondaryColor"
9+
>
10+
<rect
11+
v-for="index in operationCount"
12+
:key="`operation-${index}`"
13+
:x="(index - 1) * (operationWidth + 20)"
14+
y="0"
15+
rx="2"
16+
ry="2"
17+
:width="operationWidth"
18+
height="28"
19+
/>
20+
<rect
21+
:x="x"
22+
:y="resolvedTableTop"
23+
rx="2"
24+
ry="2"
25+
:width="tableWidth"
26+
:height="resolvedHeaderHeight"
27+
/>
28+
<rect
29+
v-for="index in rows"
30+
:key="index"
31+
:x="x"
32+
:y="getRowY(index)"
33+
rx="1"
34+
ry="1"
35+
:width="tableWidth"
36+
:height="rowPlaceholderHeight"
37+
/>
38+
</content-loader>
39+
</template>
40+
41+
<script>
42+
import { ContentLoader } from 'vue-content-loader';
43+
44+
const SIZE_MAP = {
45+
small: 32,
46+
medium: 42,
47+
large: 56,
48+
};
49+
50+
export default {
51+
components: {
52+
ContentLoader,
53+
},
54+
props: {
55+
baseWidth: {
56+
type: Number,
57+
default: 1180,
58+
},
59+
contentWidth: {
60+
type: Number,
61+
default: 1180,
62+
},
63+
height: {
64+
type: Number,
65+
default: 520,
66+
},
67+
tableTop: {
68+
type: Number,
69+
},
70+
rows: {
71+
type: Number,
72+
default: 5,
73+
},
74+
size: {
75+
type: String,
76+
default: 'medium',
77+
validator: value => ['small', 'medium', 'large'].includes(value),
78+
},
79+
headerHeight: {
80+
type: Number,
81+
default: 32,
82+
},
83+
x: {
84+
type: Number,
85+
default: 0,
86+
},
87+
width: {
88+
type: Number,
89+
},
90+
rowOffset: {
91+
type: Number,
92+
default: 13,
93+
},
94+
rowStep: {
95+
type: Number,
96+
},
97+
rowPlaceholderHeight: {
98+
type: Number,
99+
default: 22,
100+
},
101+
rowYList: {
102+
type: Array,
103+
default: () => [],
104+
},
105+
operationCount: {
106+
type: Number,
107+
default: 0,
108+
},
109+
operationWidth: {
110+
type: Number,
111+
default: 140,
112+
},
113+
isTransform: {
114+
type: Boolean,
115+
default: true,
116+
},
117+
},
118+
computed: {
119+
loadingConf() {
120+
return this.$store.state.loadingConf;
121+
},
122+
resolvedSize() {
123+
return SIZE_MAP[this.size];
124+
},
125+
resolvedHeaderHeight() {
126+
return this.headerHeight || this.resolvedSize;
127+
},
128+
resolvedTableTop() {
129+
if (this.tableTop !== undefined) {
130+
return this.tableTop;
131+
}
132+
return this.operationCount > 0 ? 48 : 0;
133+
},
134+
resolvedRowStep() {
135+
return this.rowStep || this.resolvedSize;
136+
},
137+
tableWidth() {
138+
return this.width || this.baseWidth;
139+
},
140+
resolvedScale() {
141+
if (!this.isTransform) {
142+
return 1;
143+
}
144+
return Math.max(this.contentWidth / this.baseWidth, 1);
145+
},
146+
},
147+
methods: {
148+
getRowY(index) {
149+
if (this.rowYList[index - 1] !== undefined) {
150+
return this.rowYList[index - 1];
151+
}
152+
return this.resolvedTableTop + this.resolvedHeaderHeight + this.rowOffset + (index - 1) * this.resolvedRowStep;
153+
},
154+
},
155+
};
156+
</script>

0 commit comments

Comments
 (0)