field.vue
2.89 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
<template>
<div class="zan-cell zan-field"
:class="{ 'zan-field--error': error , 'zan-field--wrapped': mode === 'wrapped' }">
<div
v-if="title"
class="zan-cell__hd zan-field__title">{{ title }}</div>
<textarea
v-if="type === 'textarea'"
auto-height
:name="name || componentId || ''"
:value="value"
:focus="focus"
:key="'textarea-'+componentId"
:placeholder="placeholder"
class="zan-field__input zan-cell__bd"
:class="{ 'zan-field__input--right' : right }"
placeholder-class="zan-field__placeholder"
@input="_handleZanFieldChange"
@focus="_handleZanFieldFocus"
@blur="_handleZanFieldBlur"
:data-component-id="componentId || ''"></textarea>
<input
v-else
:type="inputType || 'text'"
:name="name || componentId || ''"
:value="value"
:focus="focus"
:key="'input-'+componentId"
:placeholder="placeholder"
class="zan-field__input zan-cell__bd"
:class="{ 'zan-field__input--right' : right }"
placeholder-class="zan-field__placeholder"
@input="_handleZanFieldChange"
@focus="_handleZanFieldFocus"
@blur="_handleZanFieldBlur"
:data-component-id="componentId || ''"/>
</div>
</template>
<script>
import {extractComponentId} from '../../utils/helper'
export default {
props: {
error: Boolean,
mode: String,
title: String,
type: String,
focus: Boolean,
name: String,
componentId: String,
value: String,
inputType: String,
right: Boolean,
placeholder: String,
handleZanFieldChange: Function,
handleZanFieldFocus: Function,
handleZanFieldBlur: Function
},
methods: {
_handleZanFieldChange (event) {
const componentId = extractComponentId(event)
event.componentId = componentId
// console.info('[zan:field:change]', event)
if (this.handleZanFieldChange) {
return this.handleZanFieldChange(event)
}
console.warn('页面缺少 handleZanFieldChange 回调函数')
},
_handleZanFieldFocus (event) {
const componentId = extractComponentId(event)
event.componentId = componentId
console.info('[zan:field:focus]', event)
if (this.handleZanFieldFocus) {
return this.handleZanFieldFocus(event)
}
console.warn('页面缺少 handleZanFieldFocus 回调函数')
},
_handleZanFieldBlur (event) {
const componentId = extractComponentId(event)
event.componentId = componentId
console.info('[zan:field:blur]', event)
if (this.handleZanFieldBlur) {
return this.handleZanFieldBlur(event)
}
console.warn('页面缺少 handleZanFieldBlur 回调函数')
}
}
}
</script>
<style scoped>
</style>