Commit 6eb308fd4fd8c1eaa339e0c64c634840c679ef4d
1 parent
270b4a22
feat(plugin): form radio
Showing
6 changed files
with
400 additions
and
0 deletions
front-end/h5/src/components/plugins/common/editor-config-for-configurable-props.js
0 → 100644
| 1 | +export default { | ||
| 2 | + text: { | ||
| 3 | + type: 'a-input', | ||
| 4 | + label: '按钮文字', | ||
| 5 | + require: true, | ||
| 6 | + defaultPropValue: '按钮' | ||
| 7 | + }, | ||
| 8 | + fontSize: { | ||
| 9 | + type: 'a-input-number', | ||
| 10 | + label: '字号(px)', | ||
| 11 | + require: true, | ||
| 12 | + prop: { | ||
| 13 | + step: 1, | ||
| 14 | + min: 12, | ||
| 15 | + max: 144 | ||
| 16 | + }, | ||
| 17 | + defaultPropValue: 14 | ||
| 18 | + }, | ||
| 19 | + color: { | ||
| 20 | + type: 'a-input', | ||
| 21 | + label: '文字颜色', | ||
| 22 | + // !#zh 为编辑组件指定 prop | ||
| 23 | + prop: { | ||
| 24 | + type: 'color' | ||
| 25 | + }, | ||
| 26 | + require: true, | ||
| 27 | + defaultPropValue: 'black' | ||
| 28 | + }, | ||
| 29 | + backgroundColor: { | ||
| 30 | + type: 'a-input', // lbs-color-picker | ||
| 31 | + label: '背景颜色', | ||
| 32 | + prop: { | ||
| 33 | + type: 'color' | ||
| 34 | + }, | ||
| 35 | + require: true, | ||
| 36 | + defaultPropValue: '#ffffff' // TODO why logogram for color does't work? | ||
| 37 | + }, | ||
| 38 | + borderColor: { | ||
| 39 | + type: 'a-input', // lbs-color-picker | ||
| 40 | + label: '边框颜色', | ||
| 41 | + prop: { | ||
| 42 | + type: 'color' | ||
| 43 | + }, | ||
| 44 | + require: true, | ||
| 45 | + defaultPropValue: '#eeeeee' | ||
| 46 | + }, | ||
| 47 | + borderWidth: { | ||
| 48 | + type: 'a-input-number', | ||
| 49 | + label: '边框宽度(px)', | ||
| 50 | + require: true, | ||
| 51 | + prop: { | ||
| 52 | + step: 1, | ||
| 53 | + min: 1, | ||
| 54 | + max: 10 | ||
| 55 | + }, | ||
| 56 | + defaultPropValue: 1 | ||
| 57 | + }, | ||
| 58 | + borderRadius: { | ||
| 59 | + type: 'a-input-number', | ||
| 60 | + label: '圆角(px)', | ||
| 61 | + require: true, | ||
| 62 | + prop: { | ||
| 63 | + step: 0.1, | ||
| 64 | + min: 0, | ||
| 65 | + max: 10 | ||
| 66 | + }, | ||
| 67 | + defaultPropValue: 0 | ||
| 68 | + }, | ||
| 69 | + lineHeight: { | ||
| 70 | + type: 'a-input-number', | ||
| 71 | + label: '行高', | ||
| 72 | + require: true, | ||
| 73 | + prop: { | ||
| 74 | + step: 0.1, | ||
| 75 | + min: 0.1, | ||
| 76 | + max: 10 | ||
| 77 | + }, | ||
| 78 | + defaultPropValue: 1 | ||
| 79 | + } | ||
| 80 | +} |
front-end/h5/src/components/plugins/common/props.js
0 → 100644
| 1 | +export default { | ||
| 2 | + text: { | ||
| 3 | + type: String, | ||
| 4 | + default: '按钮' | ||
| 5 | + }, | ||
| 6 | + type: { | ||
| 7 | + type: String, | ||
| 8 | + default: 'radio' | ||
| 9 | + }, | ||
| 10 | + placeholder: { | ||
| 11 | + type: String, | ||
| 12 | + default: '请填写提示文字' | ||
| 13 | + }, | ||
| 14 | + required: { | ||
| 15 | + type: Boolean, | ||
| 16 | + default: false | ||
| 17 | + }, | ||
| 18 | + vertical: { | ||
| 19 | + type: Boolean, | ||
| 20 | + default: false | ||
| 21 | + }, | ||
| 22 | + backgroundColor: { | ||
| 23 | + type: String, | ||
| 24 | + default: 'transparent' | ||
| 25 | + }, | ||
| 26 | + color: { | ||
| 27 | + type: String, | ||
| 28 | + default: 'black' | ||
| 29 | + }, | ||
| 30 | + fontSize: { | ||
| 31 | + type: Number, | ||
| 32 | + default: 14 | ||
| 33 | + }, | ||
| 34 | + lineHeight: { | ||
| 35 | + type: Number, | ||
| 36 | + default: 1 | ||
| 37 | + }, | ||
| 38 | + borderWidth: { | ||
| 39 | + type: Number, | ||
| 40 | + default: 1 | ||
| 41 | + }, | ||
| 42 | + borderRadius: { | ||
| 43 | + type: Number, | ||
| 44 | + default: 0 | ||
| 45 | + }, | ||
| 46 | + borderColor: { | ||
| 47 | + type: String, | ||
| 48 | + default: '#ced4da' | ||
| 49 | + }, | ||
| 50 | + textAlign: { | ||
| 51 | + type: String, | ||
| 52 | + default: 'center' | ||
| 53 | + } | ||
| 54 | +} |
front-end/h5/src/components/plugins/lbp-form-radio-group.js
0 → 100644
| 1 | +import LbpFormRadio from './lbp-form-radio.js' | ||
| 2 | + | ||
| 3 | +const defaultItems = [ | ||
| 4 | + { | ||
| 5 | + value: '选项A-value' | ||
| 6 | + }, | ||
| 7 | + { | ||
| 8 | + value: '选项B-value' | ||
| 9 | + }, | ||
| 10 | + { | ||
| 11 | + value: '选项C-value' | ||
| 12 | + } | ||
| 13 | +] | ||
| 14 | + | ||
| 15 | +export default { | ||
| 16 | + name: 'lbp-form-radio-group', | ||
| 17 | + components: { | ||
| 18 | + LbpFormRadio | ||
| 19 | + }, | ||
| 20 | + props: { | ||
| 21 | + aliasName: { | ||
| 22 | + type: String, | ||
| 23 | + default: '标题演示' | ||
| 24 | + }, | ||
| 25 | + items: { | ||
| 26 | + type: Array, | ||
| 27 | + default: () => defaultItems | ||
| 28 | + } | ||
| 29 | + }, | ||
| 30 | + data: () => ({ | ||
| 31 | + value: undefined, | ||
| 32 | + uuid: undefined | ||
| 33 | + }), | ||
| 34 | + editorConfig: { | ||
| 35 | + propsConfig: { | ||
| 36 | + items: { | ||
| 37 | + type: 'lbs-form-radio-items-editor', | ||
| 38 | + label: '选项列表', | ||
| 39 | + require: true, | ||
| 40 | + defaultPropValue: defaultItems | ||
| 41 | + }, | ||
| 42 | + aliasName: { | ||
| 43 | + type: 'a-input', | ||
| 44 | + label: '填写标题', | ||
| 45 | + require: true, | ||
| 46 | + defaultPropValue: '标题演示' | ||
| 47 | + } | ||
| 48 | + }, | ||
| 49 | + components: { | ||
| 50 | + 'lbs-form-radio-items-editor': { | ||
| 51 | + render () { | ||
| 52 | + return <div> | ||
| 53 | + { | ||
| 54 | + this.value_.map((item, index) => ( | ||
| 55 | + <div> | ||
| 56 | + <a-input value={item.value} onChange={e => { item.value = e.target.value }}></a-input> | ||
| 57 | + <a-button type="dashed" shape="circle" icon="plus" onClick={this.add} /> | ||
| 58 | + <a-button type="dashed" shape="circle" icon="minus" onClick={(item, index) => this.minus(item, index)} /> | ||
| 59 | + </div> | ||
| 60 | + )) | ||
| 61 | + } | ||
| 62 | + </div> | ||
| 63 | + }, | ||
| 64 | + props: { | ||
| 65 | + value: { | ||
| 66 | + type: Array, | ||
| 67 | + default: () => defaultItems | ||
| 68 | + } | ||
| 69 | + }, | ||
| 70 | + computed: { | ||
| 71 | + value_: { | ||
| 72 | + get () { | ||
| 73 | + return this.value | ||
| 74 | + }, | ||
| 75 | + set (val) { | ||
| 76 | + this.$emit('input', val) | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + }, | ||
| 80 | + methods: { | ||
| 81 | + add () { | ||
| 82 | + console.log(this.value_.length) | ||
| 83 | + this.$emit('change', [ | ||
| 84 | + ...this.value_, | ||
| 85 | + { | ||
| 86 | + value: `选项${this.value_.length + 1}-value`, | ||
| 87 | + label: `选项${this.value_.length + 1}-label` | ||
| 88 | + } | ||
| 89 | + ]) | ||
| 90 | + }, | ||
| 91 | + minus (item, index) { | ||
| 92 | + const items = this.value_.slice(0) | ||
| 93 | + items.splice(index, 1) | ||
| 94 | + this.$emit('change', items) | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + }, | ||
| 100 | + mounted () { | ||
| 101 | + this.uuid = this.$el.dataset.uuid | ||
| 102 | + }, | ||
| 103 | + render () { | ||
| 104 | + return ( | ||
| 105 | + <div> | ||
| 106 | + <h3>{this.aliasName}</h3> | ||
| 107 | + <input type="text" hidden value={this.value} data-type="lbp-form-input" data-uuid={this.uuid} /> | ||
| 108 | + { | ||
| 109 | + this.items.map(item => ( | ||
| 110 | + <lbp-form-radio | ||
| 111 | + vertical | ||
| 112 | + value={item.value} | ||
| 113 | + checked={this.value === item.value} | ||
| 114 | + aliasName={this.aliasName} | ||
| 115 | + onChange={e => { | ||
| 116 | + this.value = e | ||
| 117 | + }} | ||
| 118 | + >{item.value}</lbp-form-radio> | ||
| 119 | + )) | ||
| 120 | + } | ||
| 121 | + </div> | ||
| 122 | + ) | ||
| 123 | + } | ||
| 124 | +} |
front-end/h5/src/components/plugins/lbp-form-radio.js
0 → 100644
| 1 | +import './styles/radio.scss' | ||
| 2 | +import commonProps from './common/props.js' | ||
| 3 | +import editorConfigForProps from './common/editor-config-for-configurable-props.js' | ||
| 4 | + | ||
| 5 | +export default { | ||
| 6 | + name: 'lbp-form-radio', | ||
| 7 | + props: { | ||
| 8 | + ...commonProps, | ||
| 9 | + value: { | ||
| 10 | + type: [String, Number], | ||
| 11 | + default: '标题演示' | ||
| 12 | + }, | ||
| 13 | + aliasName: { | ||
| 14 | + type: String, | ||
| 15 | + default: '标题演示' | ||
| 16 | + }, | ||
| 17 | + checked: { | ||
| 18 | + type: Boolean, | ||
| 19 | + default: false | ||
| 20 | + }, | ||
| 21 | + onFocus: { | ||
| 22 | + type: Function, | ||
| 23 | + default: () => {} | ||
| 24 | + }, | ||
| 25 | + onClick: { | ||
| 26 | + type: Function, | ||
| 27 | + default: () => {} | ||
| 28 | + }, | ||
| 29 | + onBlur: { | ||
| 30 | + type: Function, | ||
| 31 | + default: () => {} | ||
| 32 | + } | ||
| 33 | + }, | ||
| 34 | + editorConfig: { | ||
| 35 | + propsConfig: { | ||
| 36 | + ...editorConfigForProps | ||
| 37 | + } | ||
| 38 | + }, | ||
| 39 | + methods: { | ||
| 40 | + handleChange (e) { | ||
| 41 | + if (this.disabled) return | ||
| 42 | + this.$emit('change', e.target.value) | ||
| 43 | + } | ||
| 44 | + }, | ||
| 45 | + render () { | ||
| 46 | + const { | ||
| 47 | + color, | ||
| 48 | + textAlign, | ||
| 49 | + backgroundColor, | ||
| 50 | + fontSize, | ||
| 51 | + lineHeight, | ||
| 52 | + borderColor, | ||
| 53 | + borderRadius, | ||
| 54 | + borderWidth, | ||
| 55 | + aliasName, | ||
| 56 | + id, | ||
| 57 | + type, | ||
| 58 | + // readOnly, // ? | ||
| 59 | + disabled, | ||
| 60 | + // tabIndex, // ? | ||
| 61 | + checked, | ||
| 62 | + // autoFocus, | ||
| 63 | + value, | ||
| 64 | + vertical | ||
| 65 | + } = this | ||
| 66 | + | ||
| 67 | + const style = { | ||
| 68 | + color, | ||
| 69 | + textAlign, | ||
| 70 | + backgroundColor, | ||
| 71 | + fontSize: fontSize, | ||
| 72 | + lineHeight: lineHeight + 'em', | ||
| 73 | + borderColor, | ||
| 74 | + borderRadius: borderRadius + 'px', | ||
| 75 | + borderWidth: borderWidth + 'px', | ||
| 76 | + textDecoration: 'none', | ||
| 77 | + display: vertical ? 'block' : 'inline-block' | ||
| 78 | + } | ||
| 79 | + return ( | ||
| 80 | + <label role="radio" tabindex="0" class="lbp-radio" style={style} aria-checked="true"> | ||
| 81 | + <input | ||
| 82 | + name={aliasName} | ||
| 83 | + id={id} | ||
| 84 | + type={type} | ||
| 85 | + ref="input" | ||
| 86 | + value={value} | ||
| 87 | + disabled={disabled} | ||
| 88 | + checked={!!checked} | ||
| 89 | + onChange={this.handleChange} | ||
| 90 | + // readOnly={readOnly} | ||
| 91 | + // tabIndex={tabIndex} | ||
| 92 | + // className={`${prefixCls}-input`} | ||
| 93 | + // onClick={this.onClick} | ||
| 94 | + // onFocus={this.onFocus} | ||
| 95 | + // onBlur={this.onBlur} | ||
| 96 | + // onInput={this.onInput} | ||
| 97 | + // autoFocus={autoFocus} | ||
| 98 | + // data-type="lbp-form-input" | ||
| 99 | + // {...globalProps} | ||
| 100 | + /> | ||
| 101 | + <span><slot>{value}</slot></span> | ||
| 102 | + </label> | ||
| 103 | + ) | ||
| 104 | + } | ||
| 105 | +} |
front-end/h5/src/components/plugins/styles/radio.scss
0 → 100644
| 1 | +.lbp-radio { | ||
| 2 | + input[type=checkbox], | ||
| 3 | + input[type=radio] { | ||
| 4 | + | ||
| 5 | + width: 16px; | ||
| 6 | + height: 16px; | ||
| 7 | + | ||
| 8 | + vertical-align: middle; | ||
| 9 | + margin: 5px; | ||
| 10 | + box-sizing: border-box; | ||
| 11 | + | ||
| 12 | + resize: none; | ||
| 13 | + overflow: hidden; | ||
| 14 | + line-height: 120%; | ||
| 15 | + display: inline-block!important; | ||
| 16 | + | ||
| 17 | + box-shadow: inherit; | ||
| 18 | + border: 1px solid #ccd5db; | ||
| 19 | + padding: 6px; | ||
| 20 | + outline: none!important; | ||
| 21 | + } | ||
| 22 | +} | ||
| 0 | \ No newline at end of file | 23 | \ No newline at end of file |
front-end/h5/src/mixins/load-plugins.js
| @@ -4,6 +4,7 @@ import LbpPicture from '../components/plugins/lbp-picture' | @@ -4,6 +4,7 @@ import LbpPicture from '../components/plugins/lbp-picture' | ||
| 4 | import LbpText from '../components/plugins/lbp-text' | 4 | import LbpText from '../components/plugins/lbp-text' |
| 5 | import LbpFormInput from '../components/plugins/lbp-form-input' | 5 | import LbpFormInput from '../components/plugins/lbp-form-input' |
| 6 | import LbpFormButton from '../components/plugins/lbp-form-button' | 6 | import LbpFormButton from '../components/plugins/lbp-form-button' |
| 7 | +import LbpFormRadioGroup from '../components/plugins/lbp-form-radio-group' | ||
| 7 | 8 | ||
| 8 | export const pluginsList = [ | 9 | export const pluginsList = [ |
| 9 | { | 10 | { |
| @@ -47,6 +48,20 @@ export const pluginsList = [ | @@ -47,6 +48,20 @@ export const pluginsList = [ | ||
| 47 | component: LbpFormButton, | 48 | component: LbpFormButton, |
| 48 | visible: true, | 49 | visible: true, |
| 49 | name: LbpFormButton.name | 50 | name: LbpFormButton.name |
| 51 | + }, | ||
| 52 | + // { | ||
| 53 | + // title: '表单单选', | ||
| 54 | + // icon: 'hand-pointer-o', | ||
| 55 | + // component: LbpFormRadio, | ||
| 56 | + // visible: true, | ||
| 57 | + // name: LbpFormRadio.name | ||
| 58 | + // }, | ||
| 59 | + { | ||
| 60 | + title: '表单单选', | ||
| 61 | + icon: 'hand-pointer-o', | ||
| 62 | + component: LbpFormRadioGroup, | ||
| 63 | + visible: true, | ||
| 64 | + name: LbpFormRadioGroup.name | ||
| 50 | } | 65 | } |
| 51 | ] | 66 | ] |
| 52 | 67 |