WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2022-03-02 758ffe976bb2ff00237be95baf6513ea4b98a032
实现单选式开关
1 files added
2 files modified
88 ■■■■■ changed files
forms/switch/CSwitchRadio.vue 69 ●●●●● patch | view | raw | blame | history
forms/switch/cSwitch.scss 17 ●●●●● patch | view | raw | blame | history
forms/switch/index.js 2 ●●●●● patch | view | raw | blame | history
forms/switch/CSwitchRadio.vue
New file
@@ -0,0 +1,69 @@
/**
 * CSwitchRadio
 * @author Tevin
 */
<template>
    <view
        class="c-switch c-switch-radio"
        :class="className"
    >
        <AtSwitch :title="itemRes.label" />
        <radio-group @change="evt => handleChange(evt.detail.value)">
            <label>
                <radio
                    value="true"
                    :checked="itemRes.formData[itemRes.name]"
                >{{checkedLabel}}</radio>
            </label>
            <label>
                <radio
                    value="false"
                    :checked="!itemRes.formData[itemRes.name]"
                >{{uncheckedLabel}}</radio>
            </label>
        </radio-group>
    </view>
</template>
<script>
import { AtSwitch } from 'taro-ui-vue';
import './cSwitch.scss';
export default {
    name: 'CSwitchRadio',
    components: { AtSwitch },
    props: {
        // 表单数据资源(表单组件内部机制专用)
        itemRes: Object,
        checkedLabel: {
            type: String,
            default: '是',
        },
        uncheckedLabel: {
            type: String,
            default: '否',
        },
    },
    data() {
        return {};
    },
    computed: {
        className() {
            let className = '';
            if (this.itemRes.required) {
                className += 'c-switch-required ';
            }
            if (this.itemRes.error) {
                className += 'c-switch-error ';
            }
            return className;
        },
    },
    methods: {
        handleChange(value) {
            this.itemRes.onChange(JSON.parse(value));
        },
    },
};
</script>
forms/switch/cSwitch.scss
@@ -31,4 +31,21 @@
            color: #FF4949;
        }
    }
    &.c-switch-radio {
        position: relative;
        .at-switch__title {
            flex: 4;
        }
        .at-switch__container {
            visibility: hidden;
        }
        .weui-cells_radiogroup {
            @include position(absolute, 50% n n 0);
            padding: 24px 32px 24px 0;
            transform: translateY(-50%);
        }
        .weui-check:checked+.weui-icon-checked:before {
            color: #2093df;
        }
    }
}
forms/switch/index.js
@@ -4,7 +4,9 @@
 */
import CSwitch from '@components/forms/switch/CSwitch.vue';
import CSwitchRadio from '@components/forms/switch/CSwitchRadio.vue';
export {
    CSwitch,
    CSwitchRadio,
}