提交 46a78570 编写于 作者: Q qiang

feat(h5): 日期类型 picker 在桌面 Chrome、Firefox 浏览器默认使用系统日历

上级 bbb80ff5
...@@ -19,9 +19,10 @@ ...@@ -19,9 +19,10 @@
/> />
</transition> </transition>
<div <div
v-if="!system"
:class="{ 'uni-picker-toggle': visible }" :class="{ 'uni-picker-toggle': visible }"
:style="popupStyle.content" :style="popupStyle.content"
class="uni-picker" class="uni-picker-custom"
> >
<div <div
class="uni-picker-header" class="uni-picker-header"
...@@ -82,6 +83,21 @@ ...@@ -82,6 +83,21 @@
<div> <div>
<slot /> <slot />
</div> </div>
<div
v-if="system"
class="uni-picker-system"
>
<input
ref="input"
:value="valueSync"
:type="mode"
tabindex="-1"
:min="start"
:max="end"
:class="[system, popupStyle.dock]"
@change.stop="_input"
>
</div>
<keypress <keypress
:disable="!visible" :disable="!visible"
@esc="_cancel" @esc="_cancel"
...@@ -107,7 +123,7 @@ function getDefaultStartValue () { ...@@ -107,7 +123,7 @@ function getDefaultStartValue () {
return year.toString() return year.toString()
case fields.MONTH: case fields.MONTH:
return year + '-01' return year + '-01'
case fields.DAY: default:
return year + '-01-01' return year + '-01-01'
} }
} }
...@@ -125,7 +141,7 @@ function getDefaultEndValue () { ...@@ -125,7 +141,7 @@ function getDefaultEndValue () {
return year.toString() return year.toString()
case fields.MONTH: case fields.MONTH:
return year + '-12' return year + '-12'
case fields.DAY: default:
return year + '-12-31' return year + '-12-31'
} }
} }
...@@ -176,15 +192,12 @@ export default { ...@@ -176,15 +192,12 @@ export default {
type: String, type: String,
default: mode.SELECTOR, default: mode.SELECTOR,
validator (val) { validator (val) {
return Object.values(mode).indexOf(val) >= 0 return Object.values(mode).includes(val)
} }
}, },
fields: { fields: {
type: String, type: String,
default: 'day', default: ''
validator (val) {
return Object.values(fields).indexOf(val) >= 0
}
}, },
start: { start: {
type: String, type: String,
...@@ -234,7 +247,7 @@ export default { ...@@ -234,7 +247,7 @@ export default {
return [dateArray[0]] return [dateArray[0]]
case fields.MONTH: case fields.MONTH:
return [dateArray[0], dateArray[1]] return [dateArray[0], dateArray[1]]
case fields.DAY: default:
return [dateArray[0], dateArray[1], dateArray[2]] return [dateArray[0], dateArray[1], dateArray[2]]
} }
} }
...@@ -263,6 +276,16 @@ export default { ...@@ -263,6 +276,16 @@ export default {
return type return type
} }
return String(navigator.vendor).indexOf('Apple') === 0 && navigator.maxTouchPoints > 0 ? selectorType.PICKER : selectorType.SELECT return String(navigator.vendor).indexOf('Apple') === 0 && navigator.maxTouchPoints > 0 ? selectorType.PICKER : selectorType.SELECT
},
system () {
if (this.mode === mode.DATE && !Object.values(fields).includes(this.fields) && this.isDesktop && /win|mac/i.test(navigator.platform)) {
if (navigator.vendor === 'Google Inc.') {
return 'chrome'
} else if (/Firefox/.test(navigator.userAgent)) {
return 'firefox'
}
}
return ''
} }
}, },
watch: { watch: {
...@@ -542,7 +565,15 @@ export default { ...@@ -542,7 +565,15 @@ export default {
value value
}) })
}, },
_cancel () { _cancel ($event) {
if (this.system === 'firefox') {
// Firefox 在 input 同位置区域点击无法隐藏控件
const { top, left, width, height } = this.popover
const { pageX, pageY } = $event
if (pageX > left && pageX < left + width && pageY > top && pageY < top + height) {
return
}
}
this._close() this._close()
this.$trigger('cancel', {}, {}) this.$trigger('cancel', {}, {})
}, },
...@@ -559,6 +590,12 @@ export default { ...@@ -559,6 +590,12 @@ export default {
if (this.mode === mode.SELECTOR && this.selectorTypeComputed === selectorType.SELECT) { if (this.mode === mode.SELECTOR && this.selectorTypeComputed === selectorType.SELECT) {
this.$refs.select.scrollTop = this.valueArray[0] * 34 this.$refs.select.scrollTop = this.valueArray[0] * 34
} }
},
_input ($event) {
this.valueSync = $event.target.value
this.$nextTick(() => {
this._change()
})
} }
} }
} }
...@@ -566,6 +603,7 @@ export default { ...@@ -566,6 +603,7 @@ export default {
<style> <style>
uni-picker { uni-picker {
position: relative;
display: block; display: block;
cursor: pointer; cursor: pointer;
} }
...@@ -590,11 +628,11 @@ uni-picker[disabled] { ...@@ -590,11 +628,11 @@ uni-picker[disabled] {
font-size: 16px; font-size: 16px;
} }
.uni-picker-container .uni-picker * { .uni-picker-container .uni-picker-custom * {
box-sizing: border-box; box-sizing: border-box;
} }
.uni-picker-container .uni-picker { .uni-picker-container .uni-picker-custom {
position: fixed; position: fixed;
left: 0; left: 0;
bottom: 0; bottom: 0;
...@@ -607,7 +645,7 @@ uni-picker[disabled] { ...@@ -607,7 +645,7 @@ uni-picker[disabled] {
transition: transform 0.3s, visibility 0.3s; transition: transform 0.3s, visibility 0.3s;
} }
.uni-picker-container .uni-picker.uni-picker-toggle { .uni-picker-container .uni-picker-custom.uni-picker-toggle {
visibility: visible; visibility: visible;
transform: translate(0, 0); transform: translate(0, 0);
} }
...@@ -678,37 +716,48 @@ uni-picker[disabled] { ...@@ -678,37 +716,48 @@ uni-picker[disabled] {
color: #007aff; color: #007aff;
} }
/* .uni-picker { .uni-picker-container .uni-picker-select {
position: relative; display: none;
} }
.uni-picker-units {
.uni-picker-system {
position: absolute; position: absolute;
display: flex; display: none;
display: block;
top: 0;
left: 0;
width: 100%; width: 100%;
line-height: 16px; height: 100%;
font-size: 14px;
top: 50%;
margin-top: 22.5px;
transform: translateY(-50%);
overflow: hidden; overflow: hidden;
color: #666666;
pointer-events: none;
} }
.uni-picker-units > div {
flex: 1;
text-align: center;
transform: translateX(2em);
} */
.uni-picker-container .uni-picker-select { .uni-picker-system > input {
display: none; position: absolute;
border: none;
height: 100%;
opacity: 0;
}
.uni-picker-system > input.firefox {
top: 0;
left: 0;
width: 100%;
}
.uni-picker-system > input.chrome {
/* 翻转且使用较大字体保证可点击日历按钮 */
top: 0;
right: 100%;
font-size: 9999px;
transform-origin: 100% 0;
transform: scaleX(-1);
} }
@media screen and (min-width: 500px) and (min-height: 500px) { @media screen and (min-width: 500px) and (min-height: 500px) {
.uni-mask.uni-picker-mask { .uni-mask.uni-picker-mask {
background: none; background: none;
} }
.uni-picker-container .uni-picker { .uni-picker-container .uni-picker-custom {
width: 300px; width: 300px;
left: 50%; left: 50%;
right: auto; right: auto;
...@@ -729,7 +778,7 @@ uni-picker[disabled] { ...@@ -729,7 +778,7 @@ uni-picker[disabled] {
overflow: hidden; overflow: hidden;
border-radius: 0 0 5px 5px; border-radius: 0 0 5px 5px;
} }
.uni-picker-container .uni-picker.uni-picker-toggle { .uni-picker-container .uni-picker-custom.uni-picker-toggle {
opacity: 1; opacity: 1;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册