Skip to content

Commit 11e4f9e

Browse files
author
sugars
committed
新增右侧字母检索滑动功能,对应显示字母分组
1 parent 3e35760 commit 11e4f9e

File tree

3 files changed

+148
-52
lines changed

3 files changed

+148
-52
lines changed

src/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="app">
33
<!--头部-->
44
<!--<div class="container-top">-->
5-
<!--<top-nav></top-nav>-->
5+
<!--<top-nav></top-nav>-->
66
<!--</div>-->
77

88
<!--内容-->
@@ -68,4 +68,10 @@
6868
}
6969
}
7070
}
71+
72+
ul, ol {
73+
list-style: none;
74+
padding: 0;
75+
margin: 0;
76+
}
7177
</style>

src/common/css/base.css

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,3 @@ html, body {
33
font-family: 'PingFang SC', 'STHeitiSC-Light', 'Helvetica-Light';
44
background-color: #f4f4f6;
55
}
6-
7-
.color-black {
8-
color: #000;
9-
}
10-
11-
.color-lightblack {
12-
color: rgba(0, 0, 0, .54);
13-
}
14-
15-
.color-white {
16-
color: #fff;
17-
}
18-
19-
.color-active {
20-
color: #2e2c6b;
21-
}

src/components/home/home.vue

Lines changed: 141 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,66 +32,119 @@
3232
</mu-appbar>
3333
</div>
3434

35-
<mu-refresh-control :refreshing="refreshing" :trigger="trigger" @refresh="refresh()"/>
35+
<!--<mu-refresh-control :refreshing="refreshing" :trigger="trigger" @refresh="refresh()"/>-->
3636
<div style="margin-top: 50%;text-align: center" v-if="isAjax">
3737
<mu-circular-progress :size="40" :color="'474a4f'" :strokeWidth="5"/>
3838
</div>
39-
<mu-list v-if="!isAjax&&businessCardList">
40-
<div v-for="(value,key) in bcsSortList">
4139

42-
<mu-sub-header :ref="`key_${key}`">{{key}}</mu-sub-header>
43-
<business-card v-for="(item,index) in value"
44-
:key="index"
45-
:item="item">
46-
</business-card>
40+
<div>
41+
<mu-list v-if="!isAjax&&businessCardList">
42+
<ul id="list" ref="content">
43+
<li v-for="(value,key) in bcsSortList" class="sort-item">
44+
<div :id="key" class="sort-head" :ref="`key_${key}`">
45+
<mu-sub-header>{{key}}</mu-sub-header>
46+
</div>
47+
<business-card v-for="(item,index) in value"
48+
:key="index"
49+
:item="item">
50+
</business-card>
51+
</li>
52+
</ul>
4753

48-
</div>
49-
</mu-list>
54+
<!--检索-->
55+
<div class="initial-bar" :style="{'height':barHeight+'px'}" ref="nav" @touchstart="handleTouchStart">
56+
<ul class="initial-inner">
57+
<li class="initial-item" @click.stop="toPs(i)" v-for="i in bcInitialList">{{i}}</li>
58+
</ul>
59+
</div>
60+
</mu-list>
61+
62+
<div class="indicator" v-show="moving">{{ currentIndicator }}</div>
63+
</div>
5064

5165
<mu-dialog :open="delDialog" title="提示" @close="closeDel">
5266
确定删除此条信息吗?
5367
<mu-flat-button slot="actions" @click="closeDel" default label="取消"/>
5468
<mu-flat-button slot="actions" primary @click="closeDel" label="确定"/>
5569
</mu-dialog>
56-
57-
<!--<div class="container-bottom">-->
58-
<!--<bottom-tab class="tab"></bottom-tab>-->
59-
<!--</div>-->
60-
61-
<!--检索-->
62-
<div class="initial-bar">
63-
<span @click.stop="toPs(i)" v-for="i in bcInitialList">{{i}}</span>
64-
</div>
6570
</div>
6671
</template>
6772
<style lang="scss">
6873
.bc-box {
6974
position: relative;
70-
padding-top: 10vh;
75+
/*padding-top: 10vh;*/
76+
padding-top: 56px;
7177
}
7278
7379
.initial-bar {
7480
position: fixed;
75-
top: 50%;
81+
/*top: 50%;*/
82+
top: 56px;
83+
right: 0;
84+
bottom: 0;
7685
font-size: 11px;
7786
line-height: 1.2;
78-
right: 8px;
79-
width: 10px;
80-
-webkit-transform: translate3d(0, -50%, 0);
81-
transform: translate3d(0, -50%, 0);
82-
span {
87+
/*right: 8px;*/
88+
width: 13px;
89+
background-color: #474a4f;
90+
max-height: 100%;
91+
display: -webkit-box;
92+
display: -ms-flexbox;
93+
display: flex;
94+
-webkit-box-orient: vertical;
95+
-webkit-box-direction: normal;
96+
-ms-flex-direction: column;
97+
flex-direction: column;
98+
-webkit-box-pack: center;
99+
-ms-flex-pack: center;
100+
justify-content: center;
101+
/*-webkit-transform: translate3d(0, -50%, 0);*/
102+
/*transform: translate3d(0, -50%, 0);*/
103+
z-index: 999;
104+
.initial-inner {
105+
display: -webkit-box;
106+
display: -ms-flexbox;
107+
display: flex;
108+
-webkit-box-orient: vertical;
109+
-webkit-box-direction: normal;
110+
-ms-flex-direction: column;
111+
flex-direction: column;
112+
margin: 0;
113+
max-height: 100%;
114+
}
115+
li {
83116
display: block;
84-
text-align: left;
85117
font-size: 12px;
86118
font-weight: bold;
119+
color: #fff;
120+
text-align: center;
121+
margin: 3px auto;
87122
}
88123
}
89124
125+
.indicator {
126+
position: fixed;
127+
width: 50px;
128+
height: 50px;
129+
top: 50%;
130+
left: 50%;
131+
-webkit-transform: translate(-50%, -50%);
132+
transform: translate(-50%, -50%);
133+
text-align: center;
134+
line-height: 50px;
135+
background-color: rgba(0, 0, 0, .7);
136+
border-radius: 5px;
137+
color: #fff;
138+
font-size: 22px;
139+
z-index: 10000;
140+
}
141+
90142
.mu-list {
91143
position: relative;
92144
overflow: hidden;
93145
-webkit-overflow-scrolling: touch;
94146
user-select: none;
147+
margin-right: 13px;
95148
.list-item {
96149
width: 100%;
97150
float: left;
@@ -166,15 +219,21 @@
166219
delDialog: false,
167220
refreshing: false,
168221
trigger: null,
169-
group: '1'
222+
group: '1',
223+
barHeight: document.documentElement.clientHeight - 112,
224+
sections: [],
225+
indicatorTime: null,
226+
moving: false,
227+
firstSection: null,
228+
currentIndicator: '',
229+
navOffsetX: 0
170230
}
171231
},
172232
computed: {
173233
...mapGetters(['nowMessageList', 'bcInitialList', 'bcsSortList']),
174234
...mapState(['isAjax', 'businessCardList'])
175235
},
176-
mounted() {
177-
this.trigger = this.$el
236+
created() {
178237
},
179238
methods: {
180239
...mapMutations(['removeMessage', 'showSearch']),
@@ -199,13 +258,60 @@
199258
},
200259
toPs(i) {
201260
window.scrollTo(0, this.$refs['key_' + i][0].offsetTop)
261+
},
262+
handleTouchStart(e) {
263+
let listItems = this.$refs.content.getElementsByTagName('li');
264+
if (listItems.length > 0) {
265+
this.firstSection = listItems[0];
266+
}
267+
this.sections = listItems;
268+
269+
if (e.target.tagName !== 'LI') {
270+
return;
271+
}
272+
this.navOffsetX = e.changedTouches[0].clientX;
273+
this.scrollList(e.changedTouches[0].clientY);
274+
if (this.indicatorTime) {
275+
clearTimeout(this.indicatorTime);
276+
}
277+
this.moving = true;
278+
window.addEventListener('touchmove', this.handleTouchMove);
279+
window.addEventListener('touchend', this.handleTouchEnd);
280+
},
281+
handleTouchMove(e) {
282+
e.preventDefault();
283+
this.scrollList(e.changedTouches[0].clientY);
284+
},
285+
handleTouchEnd() {
286+
this.indicatorTime = setTimeout(() => {
287+
this.moving = false;
288+
this.currentIndicator = '';
289+
}, 500);
290+
window.removeEventListener('touchmove', this.handleTouchMove);
291+
window.removeEventListener('touchend', this.handleTouchEnd);
292+
},
293+
scrollList(y) {
294+
let currentItem = document.elementFromPoint(this.navOffsetX, y);
295+
if (!currentItem || !currentItem.classList.contains('initial-item')) {
296+
return;
297+
}
298+
this.currentIndicator = currentItem.innerText;
299+
let targets = [];
300+
for (let i = 0; i < this.sections.length; i++) {
301+
if (this.sections[i].firstChild.innerText.trim() === currentItem.innerText) {
302+
targets.push(this.sections[i])
303+
}
304+
}
305+
let targetDOM;
306+
307+
if (targets.length > 0) {
308+
targetDOM = targets[0];
309+
window.scrollTo(0, document.getElementById(currentItem.innerText).offsetTop)
310+
}
202311
}
203312
},
204-
created() {
205-
// this.$store.dispatch('getAllData', this).then(() => {
206-
// console.log('getAllData success');
207-
// })
208-
313+
mounted() {
314+
this.trigger = this.$el
209315
}
210316
}
211317
</script>

0 commit comments

Comments
 (0)