| | |
| | | /** |
| | | * CSwitch |
| | | * 开关组件,用于在表单中提供开关选择功能 |
| | | * 基于 AtSwitch 封装,支持只读模式 |
| | | * 能够显示必填和错误状态 |
| | | * @author Tevin |
| | | */ |
| | | |
| | | <template> |
| | | <view :class="['c-switch', className]"> |
| | | <view :class="['c-switch', className, readOnly?'read-only':'']"> |
| | | <AtSwitch |
| | | :title="itemData.label" |
| | | :checked="itemData.formData[itemData.name]" |
| | | :onChange="evt=>itemData.onChange(evt)" |
| | | :title="itemRes.label" |
| | | :checked="itemRes.formData[itemRes.name]" |
| | | :disabled="readOnly" |
| | | :onChange="evt=>itemRes.onChange(evt)" |
| | | /> |
| | | </view> |
| | | </template> |
| | |
| | | name: 'CSwitch', |
| | | components: { AtSwitch }, |
| | | props: { |
| | | itemData: Object, |
| | | // 表单数据资源(表单组件内部机制专用) |
| | | itemRes: Object, |
| | | // 只读模式 |
| | | readOnly: { |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | }, |
| | | data() { |
| | | return {}; |
| | |
| | | computed: { |
| | | className() { |
| | | let className = ''; |
| | | if (this.itemData.required) { |
| | | if (this.itemRes.required) { |
| | | className += 'c-switch-required '; |
| | | } |
| | | if (this.itemData.error) { |
| | | if (this.itemRes.error) { |
| | | className += 'c-switch-error '; |
| | | } |
| | | return className; |