123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <template>
- <div class="simple-radio">
- <template v-for="(item, index) in list">
- <div
- class="simple-radio__item"
- :class="[
- 'simple-radio-theme-' + type,
- { active: item.value === value },
- ]"
- :key="index"
- @click="onClick(item)"
- >
- <span class="simple-radio__con"></span>
- <span class="simple-radio__label" v-text="item.name"></span>
- </div>
- </template>
- </div>
- </template>
- <script>
- export default {
- model: {
- prop: 'value',
- event: 'change',
- },
- props: {
- value: {
- type: Number,
- default: 0,
- },
- list: {
- type: Array,
- default: [],
- },
- type: {
- type: String,
- default: 'defalut',
- },
- },
- methods: {
- onClick(item) {
- this.$emit('change', item.value)
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- // pc端
- @media screen and (min-width: 768px) {
- .simple-radio {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- flex-wrap: wrap;
- .simple-radio__item {
- cursor: pointer;
- margin-right: 40px;
- &:last-child {
- margin-right: 0;
- }
- .simple-radio__label {
- font-size: 14px;
- color: #666;
- }
- &.simple-radio-theme-rect {
- display: flex;
- justify-content: center;
- align-items: center;
- width: 117px;
- height: 46px;
- box-sizing: border-box;
- border: 1px solid #c2c2c2;
- border-radius: 2px;
- position: relative;
- overflow: hidden;
- &.active {
- @include themify($themes) {
- border-color: themed('color');
- }
- .simple-radio__con {
- position: absolute;
- right: -20px;
- bottom: -20px;
- width: 40px;
- height: 40px;
- color: #fff;
- transform: rotateZ(45deg);
- @include themify($themes) {
- background: themed('color');
- }
- &::after {
- content: '选中';
- position: absolute;
- left: -5px;
- top: 0;
- display: block;
- font-size: 10px;
- transform: rotateZ(-90deg) scale(0.8);
- }
- }
- }
- }
- &.simple-radio-theme-defalut {
- position: relative;
- padding-left: 24px;
- &.active {
- .simple-radio__con {
- &::before {
- @include themify($themes) {
- background: themed('color');
- }
- }
- }
- }
- .simple-radio__con {
- position: absolute;
- left: 0;
- top: 50%;
- width: 18px;
- height: 18px;
- box-sizing: border-box;
- border-radius: 50%;
- transform: translateY(-50%);
- @include themify($themes) {
- border: 1px solid themed('color');
- }
- &::before {
- display: block;
- content: '';
- width: 8px;
- height: 8px;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- border-radius: 50%;
- }
- }
- }
- }
- }
- }
- // 移动端
- @media screen and (max-width: 768px) {
- .simple-radio {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- flex-wrap: wrap;
- .simple-radio__item {
- cursor: pointer;
- .simple-radio__label {
- font-size: 3.4vw;
- color: #666;
- }
- &.simple-radio-theme-rect {
- margin-right: 2.4vw;
- margin-bottom: 2.4vw;
- display: flex;
- justify-content: center;
- align-items: center;
- width: 27vw;
- height: 11.8vw;
- box-sizing: border-box;
- border: 1px solid #c2c2c2;
- border-radius: 0.4vw;
- position: relative;
- overflow: hidden;
- &:last-child {
- margin-left: 0;
- }
- &.active {
- @include themify($themes) {
- border-color: themed('color');
- }
- .simple-radio__con {
- position: absolute;
- right: -20px;
- bottom: -20px;
- width: 40px;
- height: 40px;
- color: #fff;
- transform: rotateZ(45deg);
- @include themify($themes) {
- background: themed('color');
- }
- &::after {
- content: '选中';
- position: absolute;
- left: -5px;
- top: 0;
- display: block;
- font-size: 10px;
- transform: rotateZ(-90deg) scale(0.8);
- }
- }
- }
- }
- &.simple-radio-theme-defalut {
- position: relative;
- padding-left: 6vw;
- margin-right: 7.2vw;
- &:last-child {
- margin-right: 0;
- }
- &.active {
- .simple-radio__con {
- &::before {
- @include themify($themes) {
- background: themed('color');
- }
- }
- }
- }
- .simple-radio__con {
- position: absolute;
- left: 0;
- top: 50%;
- width: 3.6vw;
- height: 3.6vw;
- box-sizing: border-box;
- border-radius: 50%;
- transform: translateY(-50%);
- @include themify($themes) {
- border: 1px solid themed('color');
- }
- &::before {
- display: block;
- content: '';
- width: 1.8vw;
- height: 1.8vw;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- border-radius: 50%;
- }
- }
- }
- }
- }
- }
- </style>
|