Commit b521c217 authored by JingChao's avatar JingChao

ios 键盘

parent 2526baac
...@@ -23,7 +23,7 @@ module.exports = { ...@@ -23,7 +23,7 @@ module.exports = {
proxyTable: {}, proxyTable: {},
// Various Dev Server settings // Various Dev Server settings
host: '192.168.137.1', // can be overwritten by process.env.HOST host: 'localhost', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false, autoOpenBrowser: false,
errorOverlay: true, errorOverlay: true,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module.exports = { module.exports = {
NODE_ENV: '"production"', NODE_ENV: '"production"',
CONFIG_ENV: JSON.stringify(process.env.CONFIG_ENV), CONFIG_ENV: JSON.stringify(process.env.CONFIG_ENV),
debug: false, debug: true,
isMobilePlatform: true, isMobilePlatform: true,
appCode:'"HLS_APP"', appCode:'"HLS_APP"',
clearTable: true, clearTable: true,
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
*/ */
<template> <template>
<div class="content"> <div
class="content" @touchstart.capture="touchStart"
@touchend.capture="touchEnd">
<slot/> <slot/>
</div> </div>
</template> </template>
...@@ -18,20 +20,25 @@ export default { ...@@ -18,20 +20,25 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
tapDelay: {
type: Number,
default: 200,
},
tapTimeout: {
type: Number,
default: 700,
},
}, },
data () { data () {
return { return {
docmHeight: 0, // 默认屏幕高度
showHeight: 0, // 实时屏幕高度
topHeight: 0, // content距离顶部的高度
contentsHeight: 0, // 内容区域本来高度
isResize: false, // 默认屏幕高度是否已获取
distance: 0,
final: 0,
fontSize: Number(window.document.documentElement.style.fontSize.replace('px', '')), fontSize: Number(window.document.documentElement.style.fontSize.replace('px', '')),
winHeight: window.innerHeight, winHeight: window.innerHeight,
winWidth: window.innerWidth, winWidth: window.innerWidth,
contentScrollTop: 0, height: 0,
firstClickTime: 0,
lastClickTime: 0,
startY: 0, // 触摸位置
endY: 0, // 结束位置
} }
}, },
watch: { watch: {
...@@ -40,33 +47,59 @@ export default { ...@@ -40,33 +47,59 @@ export default {
if (this.calContent) { if (this.calContent) {
this.contentHeight() this.contentHeight()
} }
this.contentsHeight = this.$el.style.height.slice(0, this.$el.style.height.length - 2) /* document.body.addEventListener('touchstart', (event) => {
// if (detectOS() === 'ios') { if (event.target.readOnly) return
// document.body.addEventListener('focusin', () => { if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') {
document.body.addEventListener('touchstart', (e) => { startTouches = event.changedTouches[0]
}
console.log('touchStartTime:' + event.timeStamp)
if ((event.timeStamp - lastClickTime) < tapDelay) {
event.preventDefault()
}
}) */
/* document.body.addEventListener('touchend', (event) => {
if ((event.timeStamp - lastClickTime) < tapDelay) return
debugger
console.log('touchEndTime:' + event.timeStamp)
lastClickTime = event.timeStamp
let keyboardHeight = this.getKeyBoardHeight() let keyboardHeight = this.getKeyBoardHeight()
if (e.target.localName === 'input' || e.target.localName === 'textarea') { if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') {
let pointY = e.touches[0].pageY let pointY = startTouches.clientY
console.log(pointY)
this.distance = (innerHeight - pointY) < keyboardHeight ? (keyboardHeight - (innerHeight - pointY)) : 0 let scrollTop = (this.winHeight - pointY) < keyboardHeight ? (keyboardHeight - (this.winHeight - pointY)) : 0
// if (this.distance) { if (scrollTop) {
// this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s' this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s'
// this.$el.style.transform = 'translate(0px, -' + this.distance + 'px) scale(1) translateZ(0px)' this.$el.style.transform = 'translate(0px, -' + scrollTop + 'px) scale(1) translateZ(0px)'
// // this.$el.style.paddingBottom = (distance + 20) + 'px' this.$el.style.paddingBottom = (scrollTop + 20) + 'px'
// this.$el.style.height = parseInt(this.contentsHeight) + this.distance + 'px' this.$el.style.height = parseInt(this.height) + scrollTop + 'px'
} }
// } event.target.focus()
// 软键盘弹出的事件处理 }
// }) }) */
}) /* document.body.addEventListener('focusin', () => {
document.body.addEventListener('focusin', () => {
// this.final = this.final + this.distance // this.final = this.final + this.distance
console.log('final:' + this.final) console.log('distance:' + this.distance)
this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s' // this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s'
this.$el.style.transform = 'translate(0px, -' + this.distance + 'px) scale(1) translateZ(0px)'
// this.$el.style.height = parseInt(this.contentsHeight) + this.distance + 'px' // this.$el.style.height = parseInt(this.contentsHeight) + this.distance + 'px'
// this.$el.style.transform = 'translate(0px, -' + this.distance + 'px) scale(1) translateZ(0px)'
let node = document.activeElement
setTimeout(() => {
if (node) {
if (node) {
if (node.nodeName === 'TEXTAREA' || node.nodeName === 'INPUT') { // 如果是input或textarea
if (node.style.textShadow === '') {
node.style.textShadow = 'rgba(0,0,0,0) 0 0 0' // 改变某个不可见样式,触发dom重绘
node.scrollIntoView()
node.focus()
} else {
node.style.textShadow = ''
}
}
}
}
}, 100)
// this.$el.scrollTop = this.final // this.$el.scrollTop = this.final
}) }) */
// document.body.addEventListener('focusout', () => { // document.body.addEventListener('focusout', () => {
// if (detectOS() === 'ios') { // if (detectOS() === 'ios') {
// document.body.addEventListener('focusin', () => { // document.body.addEventListener('focusin', () => {
...@@ -142,6 +175,31 @@ export default { ...@@ -142,6 +175,31 @@ export default {
} }
}, },
methods: { methods: {
touchStart (event) {
this.firstClickTime = event.timeStamp
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) return
if (event.target.readOnly) return
if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') {
this.startY = event.changedTouches[0].clientY
}
},
touchEnd (event) {
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) return
this.lastClickTime = event.timeStamp
if (event.target.nodeName === 'INPUT' || event.target.nodeName === 'TEXTAREA') {
this.endY = event.changedTouches[0].clientY
if ((this.endY - this.startY > 100) || this.endY - this.startY < -100) return
let keyboardHeight = this.getKeyBoardHeight()
let scrollTop = (this.winHeight - this.endY) < keyboardHeight ? (keyboardHeight - (this.winHeight - this.endY)) : 0
if (scrollTop) {
this.$el.style.transition = 'all .2s cubic-bezier(0.165, 0.84, 0.44, 1) 0s'
this.$el.style.transform = 'translate(0px, -' + scrollTop + 'px) scale(1) translateZ(0px)'
this.$el.style.paddingBottom = (scrollTop + 20) + 'px'
this.$el.style.height = parseInt(this.height) + scrollTop + 'px'
}
event.target.focus()
}
},
getHeaderHeight () { getHeaderHeight () {
let vm = this let vm = this
let $el = vm.$el.previousElementSibling let $el = vm.$el.previousElementSibling
...@@ -194,6 +252,7 @@ export default { ...@@ -194,6 +252,7 @@ export default {
const headerHeight = vm.getHeaderHeight() const headerHeight = vm.getHeaderHeight()
const nextHeight = vm.getNextElementHeight() const nextHeight = vm.getNextElementHeight()
let content = vm.$el let content = vm.$el
vm.height = (window.innerHeight - nextHeight - headerHeight)
content.style.height = (window.innerHeight - nextHeight - headerHeight) + 'px' content.style.height = (window.innerHeight - nextHeight - headerHeight) + 'px'
}, },
......
...@@ -10,10 +10,7 @@ ...@@ -10,10 +10,7 @@
<tab-item>Vue</tab-item> <tab-item>Vue</tab-item>
<tab-item>APP</tab-item> <tab-item>APP</tab-item>
</s-tab> </s-tab>
<<<<<<< HEAD
<div style="backgroundColor:red;height:50px"/> <div style="backgroundColor:red;height:50px"/>
=======
>>>>>>> c9d4ed65258c2013b54bec8dadfe8daca1f98232
<h-content > <h-content >
<list-item> <list-item>
<item> <item>
...@@ -100,22 +97,6 @@ ...@@ -100,22 +97,6 @@
<section slot="name">tun</section> <section slot="name">tun</section>
<input slot="content" type="text"> <input slot="content" type="text">
</item> </item>
<item>
<section slot="name">tun</section>
<input slot="content" type="text">
</item>
<item>
<section slot="name">tun</section>
<input slot="content" type="text">
</item>
<item>
<section slot="name">tun</section>
<input slot="content" type="text">
</item>
<item>
<section slot="name">tun</section>
<input slot="content" type="text">
</item>
</list-item> </list-item>
</h-content> </h-content>
<!-- <s-tab> <!-- <s-tab>
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment