cuiqian2004
2025-06-19 619b47962e41f506baf7ce2b535b2de1fecc719e
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
<template>
    <view class="oi-form-switch">
        <!-- Switch开关 -->
        <switch v-if="model" :class="data.disabled?'input-disabled':''" :disabled="data.disabled"
            :checked="model[data.fieldId]" @change="onChange" />
        <switch v-else :class="data.disabled?'input-disabled':''" :disabled="data.disabled" checked="data.value"
            @change="onChange" />
    </view>
</template>
 
<script>
    export default {
        name: "OIFormSwitch",
        props: {
            data: {
                type: Object,
                required: true,
            },
            model: Object,
        },
        methods: {
            onChange(e) {
                this.data.value = e.detail.value
                if (this.model)
                    this.model[this.data.fieldId] = e.detail.value
 
                this.$emit("on-change", e)
            },
 
 
        }
    };
</script>
 
<style lang="less" scoped>
    .oi-form-switch {
        vertical-align: middle;
        margin-left: 10rpx
    }
</style>