UNPKG

@form-create/vant

Version:

VantUI版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。

77 lines (71 loc) 2.39 kB
import {computed, defineComponent, ref, toRef} from 'vue'; const NAME = 'fcTimePicker'; export default defineComponent({ name: NAME, inheritAttrs: false, props: { disabled: Boolean, clearable: Boolean, placeholder: String, modelValue: [String, Number], }, emits: ['update:modelValue', 'fc.el', 'change'], setup(props, _) { const show = ref(false); const modelValue = toRef(props, 'modelValue'); const formValue = computed(() => { if (modelValue.value == null || modelValue.value === '') { return []; } return modelValue.value.split(':'); }); const onInput = (val) => { _.emit('update:modelValue', val); _.emit('change', val); } return { show, formValue, open() { if (props.disabled) { return; } show.value = true; }, confirm({selectedValues}) { onInput(selectedValues.join(':')); show.value = false; }, clear(e) { e.stopPropagation(); onInput(''); } } }, render() { const clearIcon = () => { return this.$props.clearable && this.modelValue ? <i class="van-badge__wrapper van-icon van-icon-clear van-field__clear" onClick={this.clear}></i> : undefined; } return <div class="_fc-time-picker"> <van-field ref="el" placeholder={this.placeholder} readonly disabled={this.$props.disabled} onClick={this.open} model-value={this.modelValue} border={false} isLink v-slots={{ 'right-icon': clearIcon }}/> <van-popup show={this.show} onUpdate:show={(v) => this.show = v} round position="bottom"> <van-time-picker columnsType={['hour', 'minute']} {...this.$attrs} modelValue={this.formValue} onConfirm={this.confirm} onCancel={() => this.show = false} /> </van-popup> </div> }, mounted() { this.$emit('fc.el', this.$refs.el); } });