ThemePicker.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div :class="prefixCls">
  3. <template v-for="color in colorList || []" :key="color">
  4. <span
  5. @click="handleClick(color)"
  6. :class="[
  7. `${prefixCls}__item`,
  8. {
  9. [`${prefixCls}__item--active`]: def === color,
  10. },
  11. ]"
  12. :style="{ background: color }"
  13. >
  14. <CheckOutlined />
  15. </span>
  16. </template>
  17. </div>
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent, PropType } from 'vue';
  21. import { CheckOutlined } from '@ant-design/icons-vue';
  22. import { useDesign } from '/@/hooks/web/useDesign';
  23. import { baseHandler } from '../handler';
  24. import { HandlerEnum } from '../enum';
  25. export default defineComponent({
  26. name: 'ThemePicker',
  27. components: { CheckOutlined },
  28. props: {
  29. colorList: {
  30. type: Array as PropType<string[]>,
  31. defualt: [],
  32. },
  33. event: {
  34. type: Number as PropType<HandlerEnum>,
  35. default: () => {},
  36. },
  37. def: {
  38. type: String,
  39. },
  40. },
  41. setup(props) {
  42. const { prefixCls } = useDesign('setting-theme-picker');
  43. function handleClick(color: string) {
  44. props.event && baseHandler(props.event, color);
  45. }
  46. return {
  47. prefixCls,
  48. handleClick,
  49. };
  50. },
  51. });
  52. </script>
  53. <style lang="less">
  54. @prefix-cls: ~'@{namespace}-setting-theme-picker';
  55. .@{prefix-cls} {
  56. display: flex;
  57. flex-wrap: wrap;
  58. margin: 16px 0;
  59. justify-content: space-around;
  60. &__item {
  61. width: 20px;
  62. height: 20px;
  63. cursor: pointer;
  64. border: 1px solid #ddd;
  65. border-radius: 2px;
  66. svg {
  67. display: none;
  68. }
  69. &--active {
  70. border: 1px solid lighten(@primary-color, 10%);
  71. svg {
  72. display: inline-block;
  73. margin: 0 0 3px 3px;
  74. font-size: 12px;
  75. fill: @white !important;
  76. }
  77. }
  78. }
  79. }
  80. </style>