index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="simple-radio">
  3. <template v-for="(item, index) in list">
  4. <div
  5. class="simple-radio__item"
  6. :class="[
  7. 'simple-radio-theme-' + type,
  8. { active: item.value === value },
  9. ]"
  10. :key="index"
  11. @click="onClick(item)"
  12. >
  13. <span class="simple-radio__con"></span>
  14. <span class="simple-radio__label" v-text="item.name"></span>
  15. </div>
  16. </template>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. model: {
  22. prop: 'value',
  23. event: 'change',
  24. },
  25. props: {
  26. value: {
  27. type: Number,
  28. default: 0,
  29. },
  30. list: {
  31. type: Array,
  32. default: [],
  33. },
  34. type: {
  35. type: String,
  36. default: 'defalut',
  37. },
  38. },
  39. methods: {
  40. onClick(item) {
  41. this.$emit('change', item.value)
  42. },
  43. },
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. // pc端
  48. @media screen and (min-width: 768px) {
  49. .simple-radio {
  50. @include useTheme() {
  51. display: flex;
  52. justify-content: flex-start;
  53. align-items: center;
  54. flex-wrap: wrap;
  55. .simple-radio__item {
  56. cursor: pointer;
  57. margin-right: 40px;
  58. &:last-child {
  59. margin-right: 0;
  60. }
  61. .simple-radio__label {
  62. font-size: 14px;
  63. color: #666;
  64. }
  65. &.simple-radio-theme-rect {
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. width: 117px;
  70. height: 46px;
  71. box-sizing: border-box;
  72. border: 1px solid #c2c2c2;
  73. border-radius: 2px;
  74. position: relative;
  75. overflow: hidden;
  76. &.active {
  77. border-color: fetch('color');
  78. .simple-radio__con {
  79. position: absolute;
  80. right: -20px;
  81. bottom: -20px;
  82. width: 40px;
  83. height: 40px;
  84. color: #fff;
  85. transform: rotateZ(45deg);
  86. background: fetch('color');
  87. &::after {
  88. content: '选中';
  89. position: absolute;
  90. left: -5px;
  91. top: 0;
  92. display: block;
  93. font-size: 10px;
  94. transform: rotateZ(-90deg) scale(0.8);
  95. }
  96. }
  97. }
  98. }
  99. &.simple-radio-theme-defalut {
  100. position: relative;
  101. padding-left: 24px;
  102. &.active {
  103. .simple-radio__con {
  104. &::before {
  105. background: fetch('color');
  106. }
  107. }
  108. }
  109. .simple-radio__con {
  110. position: absolute;
  111. left: 0;
  112. top: 50%;
  113. width: 18px;
  114. height: 18px;
  115. box-sizing: border-box;
  116. border-radius: 50%;
  117. transform: translateY(-50%);
  118. border: 1px solid fetch('color');
  119. &::before {
  120. display: block;
  121. content: '';
  122. width: 8px;
  123. height: 8px;
  124. position: absolute;
  125. left: 50%;
  126. top: 50%;
  127. transform: translate(-50%, -50%);
  128. border-radius: 50%;
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. }
  136. // 移动端
  137. @media screen and (max-width: 768px) {
  138. .simple-radio {
  139. @include useTheme() {
  140. display: flex;
  141. justify-content: flex-start;
  142. align-items: center;
  143. flex-wrap: wrap;
  144. .simple-radio__item {
  145. cursor: pointer;
  146. .simple-radio__label {
  147. font-size: 3.4vw;
  148. color: #666;
  149. }
  150. &.simple-radio-theme-rect {
  151. margin-right: 2.4vw;
  152. margin-bottom: 2.4vw;
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. width: 27vw;
  157. height: 11.8vw;
  158. box-sizing: border-box;
  159. border: 1px solid #c2c2c2;
  160. border-radius: 0.4vw;
  161. position: relative;
  162. overflow: hidden;
  163. &:last-child {
  164. margin-left: 0;
  165. }
  166. &.active {
  167. border-color: fetch('color');
  168. .simple-radio__con {
  169. position: absolute;
  170. right: -20px;
  171. bottom: -20px;
  172. width: 40px;
  173. height: 40px;
  174. color: #fff;
  175. transform: rotateZ(45deg);
  176. background: fetch('color');
  177. &::after {
  178. content: '选中';
  179. position: absolute;
  180. left: -5px;
  181. top: 0;
  182. display: block;
  183. font-size: 10px;
  184. transform: rotateZ(-90deg) scale(0.8);
  185. }
  186. }
  187. }
  188. }
  189. &.simple-radio-theme-defalut {
  190. position: relative;
  191. padding-left: 6vw;
  192. margin-right: 7.2vw;
  193. &:last-child {
  194. margin-right: 0;
  195. }
  196. &.active {
  197. .simple-radio__con {
  198. &::before {
  199. background: fetch('color');
  200. }
  201. }
  202. }
  203. .simple-radio__con {
  204. position: absolute;
  205. left: 0;
  206. top: 50%;
  207. width: 3.6vw;
  208. height: 3.6vw;
  209. box-sizing: border-box;
  210. border-radius: 50%;
  211. transform: translateY(-50%);
  212. border: 1px solid fetch('color');
  213. &::before {
  214. display: block;
  215. content: '';
  216. width: 1.8vw;
  217. height: 1.8vw;
  218. position: absolute;
  219. left: 50%;
  220. top: 50%;
  221. transform: translate(-50%, -50%);
  222. border-radius: 50%;
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. </style>