lbp-form-button.js
3.35 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
119
120
121
122
123
124
125
126
127
128
// https://github.com/luban-h5-components/plugin-common-props
import PropTypes from '@luban-h5/plugin-common-props'
export default {
render () {
const {
color,
textAlign,
backgroundColor,
fontSize,
lineHeight,
borderColor,
borderRadius,
borderWidth,
text,
disabled
} = this
const style = {
color,
textAlign,
backgroundColor,
fontSize: fontSize,
lineHeight: lineHeight + 'em',
borderColor,
borderRadius: borderRadius + 'px',
borderWidth: borderWidth + 'px',
textDecoration: 'none',
disabled
}
return (
<button
style={style}
onClick={this.handleClick}
>{text}</button>)
},
name: 'lbp-form-button',
props: {
text: PropTypes.string({ defaultValue: '提交' }),
vertical: PropTypes.boolean(),
backgroundColor: PropTypes.color({ label: '背景色', defaultValue: 'rgba(255, 255, 255, 0.2)' }),
color: PropTypes.color(),
fontSize: PropTypes.number({ label: '字号(px)' }),
lineHeight: PropTypes.number({ label: '行高(px)', defaultValue: 1 }),
borderWidth: PropTypes.number({ label: '边框宽度(px)', defaultValue: 1 }),
borderRadius: PropTypes.number({ label: '圆角(px)', defaultValue: 4 }),
borderColor: PropTypes.color({ label: '边框颜色', defaultValue: '#ced4da' }),
textAlign: PropTypes.textAlign(),
disabled: {
type: Boolean,
default: false
}
},
methods: {
handleClick () {
if (this.disabled) return
// #!zh: data-type=lbp-form-input 在 lbp-form-input 组件中定义
let inputs = document.querySelectorAll("[data-type^='lbp-form-input']")
if (!inputs.length) return
const self = this
let formData = new FormData()
inputs.forEach(input => formData.append(input.dataset.uuid, input.value))
const req = new XMLHttpRequest()
req.onreadystatechange = function () {
if (req.readyState === 4) {
const message = req.status === 200 ? '提交成功' : '提交失败'
self.$message.info(message)
}
}
// #!zh: vuex.module.editor.setWork 中定义
const workId = window.__work.id
// TODO #!zh: 可以动态配置表单提交地址
req.open('post', `/works/form/submit/${workId}`, true)
req.send(formData)
}
},
componentsForPropsEditor: {
'lbs-select-input-type': {
props: ['value'],
computed: {
value_: {
get () {
return this.value
},
set (val) {
this.$emit('input', val)
}
}
},
template: `
<a-select v-model="value_" placeholder="类型">
<a-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</a-option>
</a-select>
`,
data: () => ({
options: [
{
label: '文字',
value: 'text'
},
{
label: '密码',
value: 'password'
},
{
label: '日期',
value: 'date'
},
{
label: '邮箱',
value: 'email'
},
{
label: '手机号',
value: 'tel'
}
]
})
}
}
}