index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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: 'rect',
  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. display: flex;
  51. justify-content: flex-start;
  52. align-items: center;
  53. flex-wrap: wrap;
  54. .simple-radio__item {
  55. cursor: pointer;
  56. margin-right: 40px;
  57. &:last-child {
  58. margin-right: 0;
  59. }
  60. .simple-radio__label {
  61. font-size: 14px;
  62. color: #666;
  63. }
  64. &.simple-radio-theme-rect {
  65. display: flex;
  66. justify-content: center;
  67. align-items: center;
  68. width: 117px;
  69. height: 46px;
  70. box-sizing: border-box;
  71. border: 1px solid #c2c2c2;
  72. border-radius: 2px;
  73. position: relative;
  74. overflow: hidden;
  75. &.active {
  76. @include themify($themes) {
  77. border-color: themed('color');
  78. }
  79. .simple-radio__con {
  80. position: absolute;
  81. right: -20px;
  82. bottom: -20px;
  83. width: 40px;
  84. height: 40px;
  85. color: #fff;
  86. transform: rotateZ(45deg);
  87. @include themify($themes) {
  88. background: themed('color');
  89. }
  90. &::after {
  91. content: '选中';
  92. position: absolute;
  93. left: -5px;
  94. top: 0;
  95. display: block;
  96. font-size: 10px;
  97. transform: rotateZ(-90deg) scale(0.8);
  98. }
  99. }
  100. }
  101. }
  102. &.simple-radio-theme-defalut {
  103. position: relative;
  104. padding-left: 24px;
  105. &.active {
  106. .simple-radio__con {
  107. &::before {
  108. @include themify($themes) {
  109. background: themed('color');
  110. }
  111. }
  112. }
  113. }
  114. .simple-radio__con {
  115. position: absolute;
  116. left: 0;
  117. top: 50%;
  118. width: 18px;
  119. height: 18px;
  120. box-sizing: border-box;
  121. border-radius: 50%;
  122. transform: translateY(-50%);
  123. @include themify($themes) {
  124. border: 1px solid themed('color');
  125. }
  126. &::before {
  127. display: block;
  128. content: '';
  129. width: 8px;
  130. height: 8px;
  131. position: absolute;
  132. left: 50%;
  133. top: 50%;
  134. transform: translate(-50%, -50%);
  135. border-radius: 50%;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. // 移动端
  143. @media screen and (max-width: 768px) {
  144. .simple-radio {
  145. display: flex;
  146. justify-content: flex-start;
  147. align-items: center;
  148. flex-wrap: wrap;
  149. .simple-radio__item {
  150. cursor: pointer;
  151. .simple-radio__label {
  152. font-size: 3.4vw;
  153. color: #666;
  154. }
  155. &.simple-radio-theme-rect {
  156. margin-right: 2.4vw;
  157. margin-bottom: 2.4vw;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. width: 27vw;
  162. height: 11.8vw;
  163. box-sizing: border-box;
  164. border: 1px solid #c2c2c2;
  165. border-radius: 0.4vw;
  166. position: relative;
  167. overflow: hidden;
  168. &:nth-child(3n) {
  169. margin-right: 0;
  170. }
  171. &.active {
  172. @include themify($themes) {
  173. border-color: themed('color');
  174. }
  175. .simple-radio__con {
  176. position: absolute;
  177. right: -20px;
  178. bottom: -20px;
  179. width: 40px;
  180. height: 40px;
  181. color: #fff;
  182. transform: rotateZ(45deg);
  183. @include themify($themes) {
  184. background: themed('color');
  185. }
  186. &::after {
  187. content: '选中';
  188. position: absolute;
  189. left: -5px;
  190. top: 0;
  191. display: block;
  192. font-size: 10px;
  193. transform: rotateZ(-90deg) scale(0.8);
  194. }
  195. }
  196. }
  197. }
  198. &.simple-radio-theme-defalut {
  199. position: relative;
  200. padding-left: 6vw;
  201. margin-right: 7.2vw;
  202. &:nth-child(4n) {
  203. margin-right: 0;
  204. }
  205. &.active {
  206. .simple-radio__con {
  207. &::before {
  208. @include themify($themes) {
  209. background: themed('color');
  210. }
  211. }
  212. }
  213. }
  214. .simple-radio__con {
  215. position: absolute;
  216. left: 0;
  217. top: 50%;
  218. width: 3.6vw;
  219. height: 3.6vw;
  220. box-sizing: border-box;
  221. border-radius: 50%;
  222. transform: translateY(-50%);
  223. @include themify($themes) {
  224. border: 1px solid themed('color');
  225. }
  226. &::before {
  227. display: block;
  228. content: '';
  229. width: 1.8vw;
  230. height: 1.8vw;
  231. position: absolute;
  232. left: 50%;
  233. top: 50%;
  234. transform: translate(-50%, -50%);
  235. border-radius: 50%;
  236. }
  237. }
  238. }
  239. }
  240. }
  241. }
  242. </style>