提交 bbb80ff5 编写于 作者: Q qiang

feat(h5): pc 端单列 picker 组件支持 select 样式

上级 27790c75
...@@ -40,9 +40,9 @@ ...@@ -40,9 +40,9 @@
</div> </div>
<div :style="popupStyle.triangle" /> <div :style="popupStyle.triangle" />
</div> </div>
<keypress <keypress
:disable="!visible" :disable="!visible"
@esc="_close(-1)" @esc="_close(-1)"
/> />
</uni-actionsheet> </uni-actionsheet>
</template> </template>
...@@ -154,7 +154,7 @@ uni-actionsheet .uni-actionsheet__cell:first-child:before { ...@@ -154,7 +154,7 @@ uni-actionsheet .uni-actionsheet__cell:first-child:before {
display: none; display: none;
} }
@media screen and (min-width: 500px) { @media screen and (min-width: 500px) and (min-height: 500px) {
.uni-mask.uni-actionsheet__mask { .uni-mask.uni-actionsheet__mask {
background: none; background: none;
} }
......
...@@ -6,6 +6,9 @@ export default { ...@@ -6,6 +6,9 @@ export default {
} }
}, },
computed: { computed: {
isDesktop () {
return this.popupWidth >= 500 && this.popupHeight >= 500
},
popupStyle () { popupStyle () {
const style = {} const style = {}
const contentStyle = style.content = {} const contentStyle = style.content = {}
...@@ -14,7 +17,7 @@ export default { ...@@ -14,7 +17,7 @@ export default {
function getNumber (value) { function getNumber (value) {
return Number(value) || 0 return Number(value) || 0
} }
if (this.popupWidth >= 500 && popover) { if (this.isDesktop && popover) {
Object.assign(triangleStyle, { Object.assign(triangleStyle, {
position: 'absolute', position: 'absolute',
width: '0', width: '0',
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
<div <div
ref="picker" ref="picker"
class="uni-picker-container" class="uni-picker-container"
:class="`uni-${mode}-${selectorTypeComputed}`"
@wheel.prevent
@touchmove.prevent @touchmove.prevent
> >
<transition name="uni-fade"> <transition name="uni-fade">
...@@ -57,10 +59,23 @@ ...@@ -57,10 +59,23 @@
</div> </div>
</v-uni-picker-view-column> </v-uni-picker-view-column>
</v-uni-picker-view> </v-uni-picker-view>
<!-- 第二种时间单位展示方式-暂时不用这种 --> <div
<!-- <div v-if="units.length" class="uni-picker-units"> ref="select"
<div v-for="(item,index) in units" :key="index">{{item}}</div> class="uni-picker-select"
</div>--> >
<div
v-for="(item, index) in rangeArray[0]"
:key="index"
class="uni-picker-item"
:class="{ selected: valueArray[0] === index }"
@click="
valueArray[0] = index;
_change();
"
>
{{ typeof item === "object" ? item[rangeKey] || "" : item }}
</div>
</div>
<div :style="popupStyle.triangle" /> <div :style="popupStyle.triangle" />
</div> </div>
</div> </div>
...@@ -130,6 +145,10 @@ const fields = { ...@@ -130,6 +145,10 @@ const fields = {
MONTH: 'month', MONTH: 'month',
DAY: 'day' DAY: 'day'
} }
const selectorType = {
PICKER: 'picker',
SELECT: 'select'
}
export default { export default {
name: 'Picker', name: 'Picker',
components: { keypress }, components: { keypress },
...@@ -178,6 +197,10 @@ export default { ...@@ -178,6 +197,10 @@ export default {
disabled: { disabled: {
type: [Boolean, String], type: [Boolean, String],
default: false default: false
},
selectorType: {
type: String,
default: ''
} }
}, },
data () { data () {
...@@ -233,14 +256,21 @@ export default { ...@@ -233,14 +256,21 @@ export default {
default: default:
return [] return []
} }
},
selectorTypeComputed () {
const type = this.selectorType
if (Object.values(selectorType).includes(type)) {
return type
}
return String(navigator.vendor).indexOf('Apple') === 0 && navigator.maxTouchPoints > 0 ? selectorType.PICKER : selectorType.SELECT
} }
}, },
watch: { watch: {
visible (val) { visible (val) {
if (val) { if (val) {
clearTimeout(this.__contentVisibleDelay) clearTimeout(this.__contentVisibleDelay)
this.contentVisible = val this.contentVisible = val
this._select()
} else { } else {
this.__contentVisibleDelay = setTimeout(() => { this.__contentVisibleDelay = setTimeout(() => {
this.contentVisible = val this.contentVisible = val
...@@ -524,6 +554,11 @@ export default { ...@@ -524,6 +554,11 @@ export default {
this.$el.prepend($picker) this.$el.prepend($picker)
$picker.style.display = 'none' $picker.style.display = 'none'
}, 260) }, 260)
},
_select () {
if (this.mode === mode.SELECTOR && this.selectorTypeComputed === selectorType.SELECT) {
this.$refs.select.scrollTop = this.valueArray[0] * 34
}
} }
} }
} }
...@@ -594,6 +629,7 @@ uni-picker[disabled] { ...@@ -594,6 +629,7 @@ uni-picker[disabled] {
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
cursor: pointer;
} }
.uni-picker-container .uni-picker-header { .uni-picker-container .uni-picker-header {
...@@ -664,7 +700,11 @@ uni-picker[disabled] { ...@@ -664,7 +700,11 @@ uni-picker[disabled] {
transform: translateX(2em); transform: translateX(2em);
} */ } */
@media screen and (min-width: 500px) { .uni-picker-container .uni-picker-select {
display: none;
}
@media screen and (min-width: 500px) and (min-height: 500px) {
.uni-mask.uni-picker-mask { .uni-mask.uni-picker-mask {
background: none; background: none;
} }
...@@ -693,5 +733,27 @@ uni-picker[disabled] { ...@@ -693,5 +733,27 @@ uni-picker[disabled] {
opacity: 1; opacity: 1;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
.uni-selector-select .uni-picker-header,
.uni-selector-select .uni-picker-content {
display: none;
}
.uni-selector-select .uni-picker-select {
display: block;
max-height: 300px;
overflow: auto;
background-color: white;
border-radius: 5px;
padding: 6px 0;
}
.uni-selector-select .uni-picker-item {
padding: 0 10px;
color: #555555;
}
.uni-selector-select .uni-picker-item:hover {
background-color: #f6f6f6;
}
.uni-selector-select .uni-picker-item.selected {
color: #007aff;
}
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册