Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
cube-ui
提交
5cf2bd06
C
cube-ui
项目概览
DiDi
/
cube-ui
9 个月 前同步成功
通知
34
Star
9078
Fork
1508
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cube-ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5cf2bd06
编写于
9月 10, 2018
作者:
F
fengweiyao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(index-list): using cube-sticky to refactor index-list
上级
f0d64b83
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
104 deletion
+30
-104
src/components/index-list/index-list-group.vue
src/components/index-list/index-list-group.vue
+5
-1
src/components/index-list/index-list.vue
src/components/index-list/index-list.vue
+25
-103
未找到文件。
src/components/index-list/index-list-group.vue
浏览文件 @
5cf2bd06
<
template
>
<li
class=
"cube-index-list-group"
>
<h2
class=
"cube-index-list-anchor"
v-html=
"group.name"
></h2>
<cube-sticky-ele
:ele-key=
"group.name"
>
<h2
class=
"cube-index-list-anchor"
v-html=
"group.name"
></h2>
</cube-sticky-ele>
<ul>
<slot>
<cube-index-list-item
v-for=
"(item, index) in group.items"
:key=
"index"
:item=
"item"
@
select=
"selectItem"
></cube-index-list-item>
...
...
@@ -10,6 +12,7 @@
</
template
>
<
script
type=
"text/ecmascript-6"
>
import
CubeStickyEle
from
'
../sticky/sticky-ele.vue
'
import
CubeIndexListItem
from
'
./index-list-item.vue
'
const
COMPONENT_NAME
=
'
cube-index-list-group
'
...
...
@@ -31,6 +34,7 @@
}
},
components
:
{
CubeStickyEle
,
CubeIndexListItem
}
}
...
...
src/components/index-list/index-list.vue
浏览文件 @
5cf2bd06
<
template
>
<div
class=
"cube-index-list"
>
<cube-sticky
ref=
"sticky"
:pos=
"scrollY"
@
change=
"indexChange"
class=
"cube-index-list"
>
<cube-scroll
ref=
"scroll"
:scroll-events=
"scrollEvents"
...
...
@@ -48,23 +51,17 @@
</li>
</ul>
</div>
<div
ref=
"fixed"
v-show=
"fixedTitle"
v-html=
"fixedTitle"
class=
"cube-index-list-fixed cube-index-list-anchor"
>
</div>
</div>
</cube-sticky>
</template>
<
script
type=
"text/ecmascript-6"
>
import
{
getData
,
getRect
,
prefixStyle
,
getMatchedTarget
}
from
'
../../common/helpers/dom
'
import
{
inBrowser
}
from
'
../../common/helpers/env
'
import
CubeSticky
from
'
../sticky/sticky.vue
'
import
CubeScroll
from
'
../scroll/scroll.vue
'
import
CubeIndexListGroup
from
'
./index-list-group.vue
'
import
scrollMixin
from
'
../../common/mixins/scroll
'
...
...
@@ -77,7 +74,6 @@
const
EVENT_PULLING_DOWN
=
'
pulling-down
'
const
ANCHOR_HEIGHT
=
inBrowser
?
window
.
innerHeight
<=
480
?
17
:
18
:
18
const
transformStyleKey
=
prefixStyle
(
'
transform
'
)
export
default
{
name
:
COMPONENT_NAME
,
...
...
@@ -120,17 +116,10 @@
return
{
scrollEvents
:
[
'
scroll
'
],
currentIndex
:
0
,
scrollY
:
-
1
,
diff
:
-
1
,
titleHeight
:
0
scrollY
:
-
1
}
},
computed
:
{
fixedTitle
()
{
this
.
title
&&
!
this
.
titleHeight
&&
this
.
_caculateTitleHeight
()
return
this
.
scrollY
<=
-
this
.
titleHeight
&&
this
.
data
[
this
.
currentIndex
]
?
this
.
data
[
this
.
currentIndex
].
name
:
''
},
shortcutList
()
{
return
this
.
data
.
map
((
group
)
=>
{
return
group
?
group
.
shortcut
||
group
.
name
.
substr
(
0
,
1
)
:
''
...
...
@@ -143,17 +132,16 @@
},
this
.
options
)
}
},
watch
:
{
data
()
{
this
.
$refs
.
sticky
.
refresh
()
},
title
()
{
this
.
$refs
.
sticky
.
refresh
()
}
},
created
()
{
this
.
groupList
=
[]
this
.
listHeight
=
[]
this
.
touch
=
{}
this
.
subTitleHeight
=
0
},
mounted
()
{
this
.
$nextTick
(()
=>
{
this
.
title
&&
this
.
_caculateTitleHeight
()
this
.
_calculateHeight
()
})
},
methods
:
{
/* TODO: remove refresh next minor version */
...
...
@@ -164,7 +152,10 @@
this
.
$emit
(
EVENT_SELECT
,
item
)
},
scroll
(
pos
)
{
this
.
scrollY
=
pos
.
y
this
.
scrollY
=
-
pos
.
y
},
indexChange
(
currentKey
,
currentIndex
)
{
this
.
currentIndex
=
currentIndex
>=
0
?
currentIndex
:
0
},
titleClick
()
{
this
.
$emit
(
EVENT_TITLE_CLICK
,
this
.
title
)
...
...
@@ -196,79 +187,16 @@
onPullingDown
()
{
this
.
$emit
(
EVENT_PULLING_DOWN
)
},
_caculateTitleHeight
()
{
this
.
titleHeight
=
this
.
$refs
.
title
?
getRect
(
this
.
$refs
.
title
).
height
:
0
},
_calculateHeight
()
{
this
.
groupList
=
this
.
$el
.
getElementsByClassName
(
'
cube-index-list-group
'
)
const
subTitleEl
=
this
.
$el
.
getElementsByClassName
(
'
cube-index-list-anchor
'
)[
0
]
this
.
subTitleHeight
=
subTitleEl
?
getRect
(
subTitleEl
).
height
:
0
this
.
listHeight
=
[]
if
(
!
this
.
groupList
)
{
return
}
let
height
=
this
.
titleHeight
this
.
listHeight
.
push
(
height
)
for
(
let
i
=
0
;
i
<
this
.
groupList
.
length
;
i
++
)
{
let
item
=
this
.
groupList
[
i
]
height
+=
item
.
clientHeight
this
.
listHeight
.
push
(
height
)
}
},
_scrollTo
(
index
)
{
if
(
index
<
0
)
{
index
=
0
}
else
if
(
index
>
this
.
listHeight
.
length
-
2
)
{
index
=
this
.
listHeight
.
length
-
2
}
this
.
$refs
.
scroll
.
scrollToElement
(
this
.
groupList
[
index
],
this
.
speed
)
this
.
scrollY
=
this
.
$refs
.
scroll
.
scroll
.
y
}
},
watch
:
{
data
()
{
this
.
$nextTick
(()
=>
{
this
.
_calculateHeight
()
})
},
title
(
newVal
)
{
this
.
$nextTick
(()
=>
{
this
.
_caculateTitleHeight
()
this
.
_calculateHeight
()
})
},
diff
(
newVal
)
{
let
fixedTop
=
(
newVal
>
0
&&
newVal
<
this
.
subTitleHeight
)
?
newVal
-
this
.
subTitleHeight
:
0
if
(
this
.
fixedTop
===
fixedTop
)
{
return
}
this
.
fixedTop
=
fixedTop
this
.
$refs
.
fixed
.
style
[
transformStyleKey
]
=
`translate3d(0,
${
fixedTop
}
px,0)`
},
scrollY
(
newY
)
{
const
listHeight
=
this
.
listHeight
// top
if
(
newY
>
-
this
.
titleHeight
)
{
this
.
currentIndex
=
0
return
}
// midd
for
(
let
i
=
0
;
i
<
listHeight
.
length
-
1
;
i
++
)
{
let
height1
=
listHeight
[
i
]
let
height2
=
listHeight
[
i
+
1
]
if
(
-
newY
>=
height1
&&
-
newY
<
height2
)
{
this
.
currentIndex
=
i
this
.
diff
=
height2
+
newY
return
}
}
// bottom
this
.
currentIndex
=
listHeight
.
length
-
2
const
maxScrollY
=
this
.
$refs
.
scroll
.
scroll
.
maxScrollY
const
positionY
=
Math
.
max
(
-
this
.
$refs
.
sticky
.
positions
[
index
],
maxScrollY
)
this
.
$refs
.
scroll
.
scrollTo
(
0
,
positionY
,
this
.
speed
)
this
.
scrollY
=
-
this
.
$refs
.
scroll
.
scroll
.
y
}
},
components
:
{
CubeSticky
,
CubeScroll
,
CubeIndexListGroup
}
...
...
@@ -304,12 +232,6 @@
font-size: $fontsize-medium
color: $index-list-anchor-color
background: $index-list-anchor-bgc
.cube-index-list-fixed
z-index: 1
position: absolute
top: 0
left: 0
right: 0
.cube-index-list-nav
position: absolute
z-index: 30
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录