zydx-plus 1.33.331 → 1.33.332
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
'min-height': height + 'px',
|
|
5
5
|
border: (readable)? '1px solid #ccc': 'none',
|
|
6
6
|
'background-color': (readable)? '#fff': 'transparent'
|
|
7
|
-
}" @input="event => checkLength(event, maxLength)" :placeholder="placeholder" :contenteditable="readable"
|
|
7
|
+
}" @input="event => checkLength(event, maxLength)" @keydown.enter="handleEnterKey" :placeholder="placeholder" :contenteditable="readable"
|
|
8
8
|
ref="textarea"></div>
|
|
9
9
|
<span class="num" v-if="maxLength !== 0&&readable">{{ num }}/{{ maxLength }}</span>
|
|
10
10
|
</div>
|
|
@@ -16,7 +16,8 @@ export default {
|
|
|
16
16
|
data() {
|
|
17
17
|
return {
|
|
18
18
|
num: 0,
|
|
19
|
-
placeholder: ''
|
|
19
|
+
placeholder: '',
|
|
20
|
+
length: 0
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
props: {
|
|
@@ -39,6 +40,10 @@ export default {
|
|
|
39
40
|
placeholder: {
|
|
40
41
|
type: String,
|
|
41
42
|
default: ''
|
|
43
|
+
},
|
|
44
|
+
lineNum: {
|
|
45
|
+
type: Number,
|
|
46
|
+
default: 5
|
|
42
47
|
}
|
|
43
48
|
},
|
|
44
49
|
watch: {
|
|
@@ -71,9 +76,22 @@ export default {
|
|
|
71
76
|
})
|
|
72
77
|
return html
|
|
73
78
|
},
|
|
79
|
+
// 添加限制行数(回车监听)
|
|
80
|
+
handleEnterKey(e) {
|
|
81
|
+
if(e.keyCode === 13) {
|
|
82
|
+
if(this.length + 1 >= this.lineNum) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
74
88
|
checkLength(event, maxLength) {
|
|
75
89
|
if (maxLength === 0) return
|
|
76
|
-
|
|
90
|
+
let text = event.target.innerText;
|
|
91
|
+
let html = event.target.innerHTML;
|
|
92
|
+
const regex = /<\/div>/g
|
|
93
|
+
const result = html.match(regex)
|
|
94
|
+
this.length = result ? result.length : 0 // 添加限制行数
|
|
77
95
|
this.num = text.length
|
|
78
96
|
if (text.length >= maxLength) {
|
|
79
97
|
event.preventDefault();
|