Skip to content

Commit 361ede0

Browse files
committed
Update demos.
1 parent 72ec3b7 commit 361ede0

File tree

16 files changed

+86029
-54
lines changed

16 files changed

+86029
-54
lines changed

demos/common/Header.vue

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,57 @@
33
<h1>{{ title }}</h1>
44
<section>
55
<span class="desciption">{{ desciption }}</span>
6-
<span class="memory" v-if="supportMemory && isRenderSetting">Memory used: {{memoryUsed}} MB.</span>
7-
<div class="icon" v-if="isRenderSetting" v-bind:class="showSetting ? 'active' : ''" v-on:click="clickIcon">
6+
<span id="time" class="performance time"></span>
7+
<span id="memory" class="performance memory"></span>
8+
<div class="icon" v-bind:class="showSetting ? 'active' : ''" v-on:click="clickIcon">
89
<svg width="25" height="25" t="1553394278598" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8690" xmlns:xlink="http://www.w3.org/1999/xlink">
910
<path d="M809.21 474.749H374.022c-19.865 0-35.966 16.101-35.966 35.966 0 19.859 16.101 35.966 35.966 35.966H809.21c19.865 0 35.966-16.107 35.966-35.966 0-19.864-16.101-35.966-35.966-35.966m0 215.796H374.022c-19.865 0-35.966 16.101-35.966 35.966 0 19.859 16.101 35.966 35.966 35.966H809.21c19.865 0 35.966-16.107 35.966-35.966 0-19.865-16.101-35.966-35.966-35.966M220.52 258.954c-19.865 0-35.966 16.101-35.966 35.966 0 19.865 16.101 35.966 35.966 35.966s35.966-16.101 35.966-35.966c0-19.865-16.102-35.966-35.966-35.966m153.502 71.932H809.21c19.865 0 35.966-16.101 35.966-35.966 0-19.865-16.101-35.966-35.966-35.966H374.022c-19.865 0-35.966 16.101-35.966 35.966 0 19.864 16.102 35.966 35.966 35.966M220.52 474.749c-19.865 0-35.966 16.101-35.966 35.966 0 19.859 16.101 35.966 35.966 35.966s35.966-16.107 35.966-35.966c0-19.864-16.102-35.966-35.966-35.966m0 215.796c-19.865 0-35.966 16.101-35.966 35.966 0 19.859 16.101 35.966 35.966 35.966s35.966-16.107 35.966-35.966c0-19.865-16.102-35.966-35.966-35.966" p-id="8691" fill="#2c2c2c"></path>
1011
</svg>
1112
</div>
12-
<div class="setting" v-if="isRenderSetting">
13-
<label v-if="showStart">
14-
<span class="name">START INDEX:</span>
13+
<div class="setting" v-show="showSetting">
14+
<div class="option" v-if="showStart">
15+
<span class="name" v-if="isMobile">Index:</span>
16+
<span class="name" v-else>Start index:</span>
1517
<input type="text"
1618
v-model="selfStartIndex"
1719
v-on:focus="$event.target.select()"
1820
v-on:input="inputDataChange('start', $event.target.value)"
1921
>
20-
</label>
21-
<i v-bind:style="{visibility: hasTypingInput ? 'visible' : 'hidden'}">updated after debounce 1s.</i>
22+
</div>
23+
24+
<div class="option">
25+
<span class="name" v-if="isMobile">Count:</span>
26+
<span class="name" v-else>List count:</span>
27+
<label>
28+
<input type="radio" value="1" v-model="renderCount">
29+
<span class="t1">1,000</span>
30+
</label>
31+
<label class="middle">
32+
<input type="radio" value="2" v-model="renderCount">
33+
<span class="t2">10,000</span>
34+
</label>
35+
<label>
36+
<input type="radio" value="3" v-model="renderCount">
37+
<span class="t3">100,000</span>
38+
</label>
39+
</div>
2240
</div>
2341
</section>
2442
</header>
2543
</template>
2644

2745
<script>
28-
import { debounce } from './util'
46+
import { isMobile, debounce, getQuery, countStorage, settingStorage } from './util'
2947
3048
export default {
3149
name: 'app-header',
3250
3351
data () {
3452
return {
35-
memoryUsed: 0,
36-
supportMemory: false,
37-
showSetting: false,
53+
isMobile,
3854
selfStartIndex: 0,
39-
hasTypingInput: false,
55+
showSetting: settingStorage.isShow(),
56+
renderCount: String(countStorage.get()).length - 3
4057
}
4158
},
4259
@@ -50,6 +67,13 @@ export default {
5067
}
5168
},
5269
70+
watch: {
71+
renderCount (val) {
72+
countStorage.set(val)
73+
window.location.reload()
74+
}
75+
},
76+
5377
props: {
5478
warning: Boolean,
5579
title: String,
@@ -60,25 +84,21 @@ export default {
6084
6185
methods: {
6286
clickIcon () {
63-
this.showSetting = !this.showSetting
87+
const nextStatus = !this.showSetting
88+
this.showSetting = nextStatus
89+
settingStorage.setShow(nextStatus)
6490
},
6591
6692
inputDataChange: debounce(function (type, value) {
6793
const val = Number(value)
6894
if (this.onDataChange && value !== '' && !isNaN(val) && val >= 0) {
69-
this.hasTypingInput = true
7095
this.onDataChange(type, val)
7196
}
7297
}, 1000, false)
7398
},
7499
75100
mounted () {
76101
this.selfStartIndex = this.startIndex
77-
78-
if (window.performance && window.performance.memory && window.performance.memory.usedJSHeapSize) {
79-
this.supportMemory = true
80-
this.memoryUsed = parseInt(window.performance.memory.usedJSHeapSize / (1024 * 1024))
81-
}
82102
}
83103
}
84104
</script>
@@ -100,17 +120,31 @@ header {
100120
margin-bottom: 20px;
101121
border-radius: 5px;
102122
position: relative;
103-
.memory {
123+
.performance {
104124
color: #ee82ee;
105125
position: absolute;
106126
right: 50px;
127+
font-size: 12px;
128+
@media (max-width: 640px) {
129+
display: block;
130+
position: relative;
131+
right: 0;
132+
padding-top: 5px;
133+
}
134+
}
135+
.memory {
136+
top: 18px;
107137
@media (max-width: 640px) {
108138
display: block;
109139
position: relative;
110140
right: 0;
111141
padding-top: 5px;
142+
top: 0;
112143
}
113144
}
145+
.time {
146+
top: 5px;
147+
}
114148
.icon {
115149
width: 25px;
116150
height: 25px;
@@ -128,7 +162,10 @@ header {
128162
.setting {
129163
position: relative;
130164
padding: 30px 0 20px 20px;
131-
label {
165+
@media (max-width: 640px) {
166+
padding: 20px 0 20px 0px;
167+
}
168+
.option {
132169
display: block;
133170
margin-bottom: 20px;
134171
&:last-child {
@@ -140,6 +177,29 @@ header {
140177
display: inline-block;
141178
min-width: 120px;
142179
text-align: left;
180+
@media (max-width: 640px) {
181+
min-width: 50px;
182+
}
183+
}
184+
.middle {
185+
margin: 0 20px;
186+
@media (max-width: 640px) {
187+
margin: 0;
188+
}
189+
}
190+
label {
191+
input {
192+
@media (max-width: 640px) {
193+
position: relative;
194+
top: 3px;
195+
}
196+
}
197+
span {
198+
@media (max-width: 640px) {
199+
position: relative;
200+
left: -5px;
201+
}
202+
}
143203
}
144204
}
145205
i {
@@ -148,7 +208,7 @@ header {
148208
color: lightsteelblue;
149209
font-size: 12px;
150210
}
151-
input {
211+
input[type="text"] {
152212
-webkit-appearance: none;
153213
appearance: none;
154214
padding: 5px;
@@ -168,8 +228,11 @@ header {
168228
}
169229
}
170230
header.warning {
171-
h1 {
231+
h1, .desciption {
172232
color: #ffc107;
173233
}
234+
.t3 {
235+
color: red;
236+
}
174237
}
175238
</style>

demos/common/Item.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</template>
2020

2121
<script>
22-
import { getQuery, isMobile } from './util'
22+
import { getQuery } from './util'
2323
2424
export default {
2525
name: 'item',
@@ -38,7 +38,6 @@ export default {
3838
3939
data () {
4040
return {
41-
// avatar: isMobile ? getQuery('avatar') !== null : getQuery('noavatar') === null
4241
avatar: getQuery('avatar') !== null
4342
}
4443
},

demos/common/speed-report.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
window.addEventListener('load', function () {
2+
function reportPerformance () {
3+
var performance = window.performance || window.webkitPerformance
4+
if (performance) {
5+
var timeElement = document.getElementById('time')
6+
var memoryElement = document.getElementById('memory')
7+
8+
if (timeElement && performance.timing) {
9+
var timing = performance.timing
10+
var timeUsed = Date.now() - timing.navigationStart
11+
if (timeUsed > 0) {
12+
timeElement.textContent = 'Time used: ' + timeUsed + ' ms.'
13+
}
14+
}
15+
16+
if (memoryElement && performance.memory && performance.memory.usedJSHeapSize) {
17+
var memoryUsed = parseInt(performance.memory.usedJSHeapSize / (1024 * 1024))
18+
memoryElement.textContent = 'Memory used: ' + memoryUsed + ' MB.'
19+
}
20+
}
21+
}
22+
23+
setTimeout(function () {
24+
reportPerformance()
25+
}, 0)
26+
})

demos/common/util.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,43 @@ export const debounce = (func, wait, immediate) => {
219219
}
220220
}
221221
}
222+
const oneThousand = 1000
223+
const typeMap = {
224+
1: oneThousand,
225+
2: oneThousand * 10,
226+
3: oneThousand * 100
227+
}
228+
// browser will crash render 100,000 in example `without-virtual-list`.
229+
const isWitoutVirtual = window.location.href.indexOf('without-virtual-list') > -1
230+
const defaultCount = typeMap[isWitoutVirtual ? 2 : 3]
231+
export const countStorage = {
232+
get () {
233+
try {
234+
return +sessionStorage.getItem('RENDER-COUNT') || defaultCount
235+
} catch (e) {
236+
return defaultCount
237+
}
238+
},
239+
240+
set (type) {
241+
try {
242+
sessionStorage.setItem('RENDER-COUNT', typeMap[type] || defaultCount)
243+
} catch (e) {}
244+
}
245+
}
246+
247+
export const settingStorage = {
248+
isShow () {
249+
try {
250+
return !!+(sessionStorage.getItem('SETTING-SHOW'))
251+
} catch (e) {
252+
return false
253+
}
254+
},
255+
256+
setShow (isShow) {
257+
try {
258+
sessionStorage.setItem('SETTING-SHOW', isShow ? 1 : 0)
259+
} catch (e) {}
260+
}
261+
}

demos/item-mode/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
<script>
2828
import Item from '../common/Item.vue'
2929
import VirtualList from 'vue-virtual-scroll-list'
30-
import { getRandomUser } from '../common/util'
30+
import { countStorage, getRandomUser } from '../common/util'
3131
3232
const remain = 6
3333
const itemSize = 80
34-
const itemCount = 1000 * 100
34+
const itemCount = countStorage.get()
3535
3636
let userInfoList = []
3737
for (let i = 0; i < itemCount; i++) {

0 commit comments

Comments
 (0)