<template>
<view class="keyboard-wrap" v-if="kbShow">
<view class="head">
<view class="done" @tap="done">
<text class="iconfont iconxiala-"></text>关闭
</view>
</view>
<view class="key-list">
<view class="colspan" :class="{'active' : index === currentIndex }" v-for="(item, index) in keyboardList"
:key="index">
<view class="uni-flex" v-for="(secondItem, secondIndex) in item" :key="secondIndex">
<view class="item" :class="{'disable': thridItem.split(',')[1] == 'f'}"
v-for="(thridItem, thridIndex) in secondItem" :key="thridIndex"
@tap.stop="touchstartActive(thridItem)">
<view class="content">
{{thridItem.split(',')[0]}}
</view>
</view>
</view>
</view>
<!-- 删除键 -->
<view class="item del-item" @tap.stop="del" :style="{right:(currentIndex==0?'10.5vw':'1vw') }">
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
keyboardList: [], //键盘类型
currentIndex: 0 //键盘区当前下标
}
},
props: ['kbIndex', 'kbType', 'kbShow'],
mounted() {
this.keyboardList = [
[
['京', '津', '晋', '冀', '蒙', '辽', '吉', '黑', '沪'],
['苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘'],
['', '粤', '桂', '琼', '渝', '川', '贵', '云', '藏', ''],
['', '', '陕', '甘', '青', '宁', '新', 'W', '', ''],
],
[
['1,f', '2,f', '3,f', '4,f', '5,f', '6,f', '7,f', '8,f', '9,f', '0,f'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'P', '学', '军'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港', '澳', ''],
],
[
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'O', 'P', '军,f'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '警,f'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', '港,f', '澳,f', ''],
]
]
},
watch: {
//获取键盘区域下标
kbIndex: {
immediate: true,
handler(res) {
//转为数字类型,防止数据类型不能匹配
this.currentIndex = Number(res);
}
}
},
methods: {
done() {
this.kbShow = true;
this.$emit('childClose', '');
},
//删除
del() {
this.$emit('childDel', this.currentIndex);
if (this.currentIndex == 0) {
return;
}
this.currentIndex--;
this.$emit('childIndex', this.currentIndex);
},
//点击事件
touchstartActive(res) {
//键盘包含f字符不执行
console.log(this.currentIndex, 'emitqian');
if (res.split(',')[1] == 'f' || res == '') {
return;
}
this.$emit('childValue', res);
if (this.currentIndex == this.keyboardList.length - 1) {
this.$emit('hide')
}
this.currentIndex++;
this.$emit('childIndex', this.currentIndex);
console.log(this.currentIndex, 'emithou');
}
}
}
</script>
<style lang="less" scoped>
@color:
.keyboard-wrap {
position: fixed;
bottom: 0;
right: 0;
left: 0;
width: 100%;
z-index: 999;
box-shadow: 0 0 30rpx rgba(0, 0, 0, .1);
box-sizing: border-box;
.head {
overflow: hidden;
background-color:
border-top: 1rpx
.done {
float: right;
width: 150rpx;
height: 90rpx;
line-height: 90rpx;
text-align: center;
color: @color;
font-size: 3.2vw;
display: flex;
.iconfont {
margin-left: 6rpx;
font-size: 30rpx;
}
}
}
.key-list {
padding: 3.467vw 1.067vw 2.133vw;
margin: 0 auto;
text-align: center;
background:
}
.uni-flex {
display: flex;
margin-bottom: 1.867vw;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
justify-content: center;
}
/*iphone键盘*/
.item {
-webkit-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
margin-right: 1.067vw;
font-size: 0;
.content {
display: inline-block;
width: 100%;
line-height: 12vw;
font-size: 4vw;
color:
-webkit-box-shadow: 0 0.267vw 0.267vw
box-shadow: 0 0.267vw 0.267vw
background-color:
border-radius: 1.067vw;
z-index: 50;
}
&.disable .content {
color:
background-color:
}
&.item:not(.disable):active .content {
background-color: @color;
color:
}
}
.colspan {
display: none;
&.active {
display: block;
}
}
.del-item {
position: absolute;
right: 1vw;
bottom: 2.5vh;
width: 9vw;
height: 12vw;
background:
background-size: 5.467vw;
border-radius: 1.067vw;
// width: 20%;
// height: 90rpx;
.iconfont {
line-height: 1;
font-size: 50rpx;
}
}
}
.iconxiala- {
background-size: 2.267vw;
background-repeat: no-repeat;
display: block;
width: 5.867vw;
height: 3vh;
margin-top: 3.1vh;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABsAAAAbCAYAAACN1PRVAAAAGX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