WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2025-03-18 fdeb869c386da95150a087bc22bcebc4e57d0f76
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
/**
 * CSwitch
 * 开关组件,用于在表单中提供开关选择功能
 * 基于 AtSwitch 封装,支持只读模式
 * 能够显示必填和错误状态
 * @author Tevin
 */
 
<template>
    <view :class="['c-switch', className, readOnly?'read-only':'']">
        <AtSwitch
            :title="itemRes.label"
            :checked="itemRes.formData[itemRes.name]"
            :disabled="readOnly"
            :onChange="evt=>itemRes.onChange(evt)"
        />
    </view>
</template>
 
<script>
import { AtSwitch } from 'taro-ui-vue';
import './cSwitch.scss';
 
export default {
    name: 'CSwitch',
    components: { AtSwitch },
    props: {
        // 表单数据资源(表单组件内部机制专用)
        itemRes: Object,
        // 只读模式
        readOnly: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {};
    },
    computed: {
        className() {
            let className = '';
            if (this.itemRes.required) {
                className += 'c-switch-required ';
            }
            if (this.itemRes.error) {
                className += 'c-switch-error ';
            }
            return className;
        },
    },
};
</script>