index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="border-color">
  3. <el-input
  4. v-model="localValue"
  5. class="bs-el-input"
  6. :placeholder="placeholder"
  7. clearable
  8. />
  9. <el-color-picker
  10. slot="append"
  11. v-model="localValue"
  12. popper-class="bs-el-color-picker"
  13. show-alpha
  14. class="bs-el-color-picker"
  15. :predefine="predefineColors"
  16. />
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'ColorPicker',
  22. props: {
  23. value: {
  24. type: String,
  25. default: ''
  26. }, // v-model 绑定的值
  27. placeholder: {
  28. type: String,
  29. default: ''
  30. }, // 输入框的占位文本
  31. predefineColors: { // 预定义的主题颜色
  32. type: Array,
  33. default: () => [
  34. '#007aff',
  35. '#1aa97b',
  36. '#ff4d53',
  37. '#1890FF',
  38. '#DF0E1B',
  39. '#0086CC',
  40. '#2B74CF',
  41. '#00BC9D',
  42. '#ED7D32'
  43. ]
  44. }
  45. },
  46. data () {
  47. return {
  48. localValue: this.value
  49. }
  50. },
  51. watch: {
  52. value (newValue) {
  53. this.localValue = newValue
  54. },
  55. localValue (newValue) {
  56. this.$emit('input', newValue)
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss"></style>
  62. <style lang="scss" scoped>
  63. @import "../assets/style/bsTheme.scss";
  64. .border-color {
  65. display: flex;
  66. ::v-deep .el-input {
  67. width: auto;
  68. position: relative;
  69. margin-right: 5px;
  70. .el-input__inner {
  71. height: 32.5px;
  72. }
  73. }
  74. .el-input-group__append {
  75. width: 32.5px;
  76. height: 32.5px;
  77. background-color: var(--bs-background-1);
  78. .el-color-picker--mini {
  79. position: absolute;
  80. top: 1px;
  81. left: 7px;
  82. }
  83. }
  84. ::v-deep .el-color-picker__trigger {
  85. width: 32.5px;
  86. height: 32.5px;
  87. border-color: var(--bs-el-border);
  88. background-color: var(--bs-background-1);
  89. }
  90. }
  91. </style>