demo2.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="m-color__list">
  3. <div class="m-color__section">
  4. <div class="m-color__top" :style="{ backgroundColor: state1.currentColor }">
  5. <p class="m-color__title">Brand Color</p>
  6. <p class="m-color__desc">{{ state1.currentColor }}</p>
  7. </div>
  8. <div class="m-color__bottom">
  9. <div @click="mColorItemAction1(index)" :style="{ backgroundColor: item }"
  10. v-for="(item, index) in state1.colorList" :key="index" class="m-color__item"></div>
  11. </div>
  12. </div>
  13. <div class="m-color__section">
  14. <div class="m-color__top" :style="{ backgroundColor: state2.currentColor }">
  15. <p class="m-color__title">Brand Color</p>
  16. <p class="m-color__desc">{{ state2.currentColor }}</p>
  17. </div>
  18. <div class="m-color__bottom">
  19. <div @click="mColorItemAction2(index)" :style="{ backgroundColor: item }"
  20. v-for="(item, index) in state2.colorList" :key="index" class="m-color__item"></div>
  21. </div>
  22. </div>
  23. <div class="m-color__section">
  24. <div class="m-color__top" :style="{ backgroundColor: state3.currentColor }">
  25. <p class="m-color__title">Brand Color</p>
  26. <p class="m-color__desc">{{ state3.currentColor }}</p>
  27. </div>
  28. <div class="m-color__bottom">
  29. <div @click="mColorItemAction3(index)" :style="{ backgroundColor: item }"
  30. v-for="(item, index) in state3.colorList" :key="index" class="m-color__item"></div>
  31. </div>
  32. </div>
  33. <div class="m-color__section">
  34. <div class="m-color__top" :style="{ backgroundColor: state4.currentColor }">
  35. <p class="m-color__title">Brand Color</p>
  36. <p class="m-color__desc">{{ state4.currentColor }}</p>
  37. </div>
  38. <div class="m-color__bottom">
  39. <div @click="mColorItemAction4(index)" :style="{ backgroundColor: item }"
  40. v-for="(item, index) in state4.colorList" :key="index" class="m-color__item"></div>
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script setup>
  46. import { reactive } from 'vue-demi';
  47. const state1 = reactive({
  48. currentColor: '#67C23A',
  49. colorList: ['#67C23A', '#529B2E', '#95D475', '#B3E19D', '#D1EDC4', '#E1F3D8', '#F0F9EB']
  50. })
  51. const state2 = reactive({
  52. currentColor: '#E6A23C',
  53. colorList: ['#E6A23C', '#B88230', '#EEBE77', '#F3D19E', '#F8E3C5', '#FAECD8', '#FDF6EC']
  54. })
  55. const state3 = reactive({
  56. currentColor: '#F56C6C',
  57. colorList: ['#F56C6C', '#C45656', '#F89898', '#FAB6B6', '#FCD3D3', '#FDE2E2', '#FEF0F0']
  58. })
  59. const state4 = reactive({
  60. currentColor: '#909399',
  61. colorList: ['#909399', '#73767A', '#B1B3B8', '#C8C9CC', '#DEDFE0', '#E9E9EB', '#F4F4F5']
  62. })
  63. const mColorItemAction1 = (index) => {
  64. state1.currentColor = state1.colorList[index];
  65. }
  66. const mColorItemAction2 = (index) => {
  67. state2.currentColor = state2.colorList[index];
  68. }
  69. const mColorItemAction3 = (index) => {
  70. state3.currentColor = state3.colorList[index];
  71. }
  72. const mColorItemAction4 = (index) => {
  73. state4.currentColor = state4.colorList[index];
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. // @import '../../styles/components/button.scss';
  78. .m-color__list {
  79. display: flex;
  80. .m-color__section {
  81. width: 210px;
  82. height: 112px;
  83. border-radius: 5px;
  84. margin-left: 20px;
  85. &:first-child {
  86. margin-left: 0px;
  87. }
  88. .m-color__top {
  89. color: #fff;
  90. height: 60%;
  91. padding: 10px 0 0 20px;
  92. border-top-left-radius: 5px;
  93. border-top-right-radius: 5px;
  94. .m-color__title {
  95. font-size: 16px;
  96. }
  97. .m-color__desc {
  98. font-size: 14px;
  99. }
  100. }
  101. .m-color__bottom {
  102. height: 40%;
  103. display: flex;
  104. .m-color__item {
  105. width: calc(100% / 7);
  106. cursor: pointer;
  107. }
  108. }
  109. }
  110. }
  111. </style>