ColorPicker.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <el-color-picker
  3. :predefine="groupedPredefineColors"
  4. popper-class="color-picker has-history"
  5. v-bind="$attrs"
  6. v-on="$listeners"
  7. />
  8. </template>
  9. <script>
  10. import { GetColorList_Common, GetColorList_RecentlyUsed } from '@/api/project';
  11. export default {
  12. name: 'ColorPicker',
  13. inheritAttrs: false,
  14. props: {
  15. // 常用颜色类型
  16. type: {
  17. type: Number,
  18. default: 0,
  19. },
  20. },
  21. data() {
  22. return {
  23. commonList: [], // 常用颜色
  24. recentlyUsedList: [], // 制作人员历史颜色
  25. };
  26. },
  27. computed: {
  28. groupedPredefineColors() {
  29. return [
  30. ...this.commonList.map(({ color }) => `#${color}`),
  31. ...this.recentlyUsedList.map(({ color }) => `#${color}`),
  32. ];
  33. },
  34. },
  35. created() {
  36. this.getColorList_Common();
  37. this.getColorList_RecentlyUsed();
  38. },
  39. methods: {
  40. getColorList_Common() {
  41. GetColorList_Common({ type: this.type }).then(({ color_list }) => {
  42. this.commonList = color_list;
  43. });
  44. },
  45. getColorList_RecentlyUsed() {
  46. GetColorList_RecentlyUsed({ type: this.type }).then(({ color_list }) => {
  47. this.recentlyUsedList = color_list;
  48. });
  49. },
  50. },
  51. };
  52. </script>
  53. <style lang="scss">
  54. .color-picker {
  55. .el-color-predefine__colors {
  56. display: flex;
  57. flex-wrap: wrap;
  58. &::before {
  59. flex: 0 0 100%;
  60. order: 0;
  61. margin-bottom: 8px;
  62. font-size: 12px;
  63. color: #666;
  64. content: '常用颜色';
  65. }
  66. }
  67. .el-color-predefine__color-selector:nth-child(-n + 20) {
  68. order: 1;
  69. }
  70. &.has-history .el-color-predefine__colors::after {
  71. flex: 0 0 100%;
  72. order: 2;
  73. margin-top: 10px;
  74. margin-bottom: 8px;
  75. font-size: 12px;
  76. color: #666;
  77. content: '制作人员历史颜色';
  78. }
  79. .el-color-predefine__color-selector:nth-child(n + 21) {
  80. order: 3;
  81. }
  82. }
  83. </style>