提交 753f47b8 编写于 作者: 郭胜强

fix: 解决picker-view组件动态设置高度后显示异常的问题

上级 a1ee8f2e
...@@ -9,7 +9,6 @@ export default { ...@@ -9,7 +9,6 @@ export default {
return { return {
scope: `picker-view-column-${Date.now()}`, scope: `picker-view-column-${Date.now()}`,
inited: false, inited: false,
height: 34,
indicatorStyle: '', indicatorStyle: '',
indicatorClass: '', indicatorClass: '',
indicatorHeight: 34, indicatorHeight: 34,
...@@ -20,6 +19,9 @@ export default { ...@@ -20,6 +19,9 @@ export default {
} }
}, },
computed: { computed: {
height () {
return this.$parent.height
},
maskSize () { maskSize () {
return (this.height - this.indicatorHeight) / 2 return (this.height - this.indicatorHeight) / 2
} }
...@@ -49,8 +51,6 @@ export default { ...@@ -49,8 +51,6 @@ export default {
// this.__pageRerender = this._pageRerender.bind(this) // this.__pageRerender = this._pageRerender.bind(this)
}, },
mounted: function () { mounted: function () {
this.height = this.$el.offsetHeight
this.indicatorHeight = this.$refs.indicator.offsetHeight
this.touchtrack(this.$refs.main, '_handleTrack', true) this.touchtrack(this.$refs.main, '_handleTrack', true)
this.setCurrent(this.current) this.setCurrent(this.current)
this.$nextTick(() => { this.$nextTick(() => {
...@@ -61,7 +61,7 @@ export default { ...@@ -61,7 +61,7 @@ export default {
methods: { methods: {
_setItemHeight (height) { _setItemHeight (height) {
var style = document.createElement('style') var style = document.createElement('style')
style.innerText = `.uni-picker__content.${this.scope}>*{height: ${height}px;overflow: hidden;}` style.innerText = `.uni-picker-content.${this.scope}>*{height: ${height}px;overflow: hidden;}`
document.head.appendChild(style) document.head.appendChild(style)
}, },
_handleTrack: function (e) { _handleTrack: function (e) {
...@@ -122,6 +122,11 @@ export default { ...@@ -122,6 +122,11 @@ export default {
var current = Math.min(this.current, index) var current = Math.min(this.current, index)
this._scroller.update(current * this.indicatorHeight, undefined, this.indicatorHeight) this._scroller.update(current * this.indicatorHeight, undefined, this.indicatorHeight)
}) })
},
_resize ({
height
}) {
this.indicatorHeight = height
} }
}, },
render (createElement) { render (createElement) {
...@@ -135,24 +140,31 @@ export default { ...@@ -135,24 +140,31 @@ export default {
[ [
createElement('div', { createElement('div', {
ref: 'main', ref: 'main',
staticClass: 'uni-picker__group' staticClass: 'uni-picker-group'
}, },
[ [
createElement('div', { createElement('div', {
ref: 'mask', ref: 'mask',
staticClass: 'uni-picker__mask', staticClass: 'uni-picker-mask',
class: this.maskClass, class: this.maskClass,
style: `background-size: 100% ${this.maskSize}px;${this.maskStyle}` style: `background-size: 100% ${this.maskSize}px;${this.maskStyle}`
}), }),
createElement('div', { createElement('div', {
ref: 'indicator', ref: 'indicator',
staticClass: 'uni-picker__indicator', staticClass: 'uni-picker-indicator',
class: this.indicatorClass, class: this.indicatorClass,
style: this.indicatorStyle style: this.indicatorStyle
}), }, [createElement('v-uni-resize-sensor', {
attrs: {
initial: true
},
on: {
resize: this._resize
}
})]),
createElement('div', { createElement('div', {
ref: 'content', ref: 'content',
staticClass: 'uni-picker__content', staticClass: 'uni-picker-content',
class: this.scope, class: this.scope,
style: `padding: ${this.maskSize}px 0;` style: `padding: ${this.maskSize}px 0;`
}, },
...@@ -173,24 +185,28 @@ uni-picker-view-column { ...@@ -173,24 +185,28 @@ uni-picker-view-column {
overflow: hidden; overflow: hidden;
} }
.uni-picker__group { uni-picker-view-column[hidden] {
display: none;
}
.uni-picker-group {
height: 100%; height: 100%;
} }
.uni-picker__mask { .uni-picker-mask {
transform: translateZ(0); transform: translateZ(0);
-webkit-transform: translateZ(0); -webkit-transform: translateZ(0);
} }
.uni-picker__indicator, .uni-picker-indicator,
.uni-picker__mask { .uni-picker-mask {
position: absolute; position: absolute;
left: 0; left: 0;
width: 100%; width: 100%;
z-index: 3; z-index: 3;
} }
.uni-picker__mask { .uni-picker-mask {
top: 0; top: 0;
height: 100%; height: 100%;
margin: 0 auto; margin: 0 auto;
...@@ -205,15 +221,15 @@ uni-picker-view-column { ...@@ -205,15 +221,15 @@ uni-picker-view-column {
background-repeat: no-repeat; background-repeat: no-repeat;
} }
.uni-picker__indicator { .uni-picker-indicator {
height: 34px; height: 34px;
/* top: 102px; */ /* top: 102px; */
top: 50%; top: 50%;
transform: translateY(-50%); transform: translateY(-50%);
} }
.uni-picker__indicator, .uni-picker-indicator,
.uni-picker__mask { .uni-picker-mask {
position: absolute; position: absolute;
left: 0; left: 0;
width: 100%; width: 100%;
...@@ -221,7 +237,7 @@ uni-picker-view-column { ...@@ -221,7 +237,7 @@ uni-picker-view-column {
pointer-events: none; pointer-events: none;
} }
.uni-picker__content { .uni-picker-content {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
...@@ -230,13 +246,13 @@ uni-picker-view-column { ...@@ -230,13 +246,13 @@ uni-picker-view-column {
padding: 102px 0; padding: 102px 0;
} }
.uni-picker__content > * { .uni-picker-content > * {
height: 34px; height: 34px;
overflow: hidden; overflow: hidden;
} }
.uni-picker__indicator:after, .uni-picker-indicator:after,
.uni-picker__indicator:before { .uni-picker-indicator:before {
content: " "; content: " ";
position: absolute; position: absolute;
left: 0; left: 0;
...@@ -245,7 +261,7 @@ uni-picker-view-column { ...@@ -245,7 +261,7 @@ uni-picker-view-column {
color: #e5e5e5; color: #e5e5e5;
} }
.uni-picker__indicator:before { .uni-picker-indicator:before {
top: 0; top: 0;
border-top: 1px solid #e5e5e5; border-top: 1px solid #e5e5e5;
-webkit-transform-origin: 0 0; -webkit-transform-origin: 0 0;
...@@ -254,7 +270,7 @@ uni-picker-view-column { ...@@ -254,7 +270,7 @@ uni-picker-view-column {
transform: scaleY(0.5); transform: scaleY(0.5);
} }
.uni-picker__indicator:after { .uni-picker-indicator:after {
bottom: 0; bottom: 0;
border-bottom: 1px solid #e5e5e5; border-bottom: 1px solid #e5e5e5;
-webkit-transform-origin: 0 100%; -webkit-transform-origin: 0 100%;
...@@ -263,8 +279,8 @@ uni-picker-view-column { ...@@ -263,8 +279,8 @@ uni-picker-view-column {
transform: scaleY(0.5); transform: scaleY(0.5);
} }
.uni-picker__indicator:after, .uni-picker-indicator:after,
.uni-picker__indicator:before { .uni-picker-indicator:before {
content: " "; content: " ";
position: absolute; position: absolute;
left: 0; left: 0;
......
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
data () { data () {
return { return {
valueSync: [...this.value], valueSync: [...this.value],
height: 0, height: 34,
items: [], items: [],
changeSource: '' changeSource: ''
} }
...@@ -62,23 +62,8 @@ export default { ...@@ -62,23 +62,8 @@ export default {
}) })
} }
} }
},
indicatorStyle () {
},
indicatorClass () {
},
maskStyle () {
},
maskClass () {
} }
}, },
mounted: function () {
this.height = this.$el.offsetHeight
},
methods: { methods: {
getItemIndex (vnode) { getItemIndex (vnode) {
return this.items.indexOf(vnode) return this.items.indexOf(vnode)
...@@ -94,10 +79,15 @@ export default { ...@@ -94,10 +79,15 @@ export default {
this.$set(this.valueSync, index, val) this.$set(this.valueSync, index, val)
} }
}, },
_valueChanged: function (val) { _valueChanged (val) {
this.items.forEach(function (item, index) { this.items.forEach(function (item, index) {
item.componentInstance.setCurrent(val[index] || 0) item.componentInstance.setCurrent(val[index] || 0)
}) })
},
_resize ({
height
}) {
this.height = height
} }
}, },
render (createElement) { render (createElement) {
...@@ -114,11 +104,19 @@ export default { ...@@ -114,11 +104,19 @@ export default {
'uni-picker-view', 'uni-picker-view',
{ {
on: this.$listeners on: this.$listeners
}, }, [createElement('v-uni-resize-sensor', {
[createElement('div', { attrs: {
initial: true
},
on: {
resize: this._resize
}
}),
createElement('div', {
ref: 'wrapper', ref: 'wrapper',
'class': 'uni-picker-view-wrapper' 'class': 'uni-picker-view-wrapper'
}, items)]) }, items)
])
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册