keyboard.js
3.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Component({
properties: {
'isKeyboard': {
type: Boolean,
value: false
},
'keyboardType': {
type: String,
value: "keyboardOne"
// value: "keyboardTwo"
},
'maxLength': {
type: Number,
value: ""
},
'minLength': {
type: Number,
value: ""
},
'test': {
type: String,
value: ""
},
'placeholder': {
type: String,
value: ""
},
'inputContent': {
type: String,
value: ""
},
'keyboardTwo': {
type: String,
value: true
},
'isKeyboardContent': {
type: Boolean,
value: false
}
},
data: {
categoryOne: '粤京津沪冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵川青藏琼宁渝✘'.split(''),
categoryTwo: '1234567890'.split(''),
categoryThree: 'QWERTYUIOP'.split(''),
categoryFour: 'ASDFGHJKLZ'.split(''),
// categoryFive: '✔XCVBNM✘'.split(''),
categoryFive: ['确认', 'X', 'C', 'V', 'B', 'N', 'M', '删除'],
categorySix: '123456789✘0✔'.split(''),
},
methods: {
changeKeyboardContent(e) {
if (e.currentTarget.dataset.value == '省称') {
this.setData({
isKeyboardContent: true
})
}
if (e.currentTarget.dataset.value == '英\数') {
this.setData({
isKeyboardContent: false
})
}
},
keyboard(e) {
// console.log(e)
if (e.target.dataset.value == undefined) {
return;
}
// if (e.target.dataset.value == '✘') {
if (e.target.dataset.value == '删除') {
if (this.data.inputContent.length > 0) {
this.setData({
inputContent: this.data.inputContent.substring(0, this.data.inputContent.length - 1)
})
// console.log(this.data.inputContent, 'this.data.inputContent');
}
return
}
if (e.target.dataset.value == '确认') {
if (this.data.minLength != '' && this.data.inputContent.length < this.data.minLength) {
wx.showToast({
title: '输入位数不得小于' + this.data.minLength + '位',
icon: 'none'
})
return
}
let reg = new RegExp(this.data.test)
if (this.data.test != '' && !reg.test(this.data.inputContent)) {
wx.showToast({
title: '不符合规则',
icon: 'none'
})
return
}
this.triggerEvent('fwhfContent', {
inputContent: this.data.inputContent
})
return
}
if (this.data.maxLength != '' && this.data.inputContent.length >= this.data.maxLength) {
wx.showToast({
title: '输入位数不得超过' + this.data.maxLength + '位',
icon: 'none'
})
return
}
this.setData({
inputContent: this.data.inputContent + e.target.dataset.value
})
// console.log(this.data.inputContent);
},
keyboardClick() {
this.setData({
isKeyboard: false
})
}
}
})