index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div class="bs-gradual-wrap">
  3. <el-form-item
  4. :label="`${customLabel}渐变方向`"
  5. label-width="100px"
  6. >
  7. <el-radio-group
  8. v-model="position"
  9. class="bs-el-radio-group"
  10. >
  11. <el-radio label="top">
  12. 上下
  13. </el-radio>
  14. <el-radio label="left">
  15. 左右
  16. </el-radio>
  17. </el-radio-group>
  18. </el-form-item>
  19. <el-form-item
  20. :label="`${customLabel}渐变颜色`"
  21. label-width="100px"
  22. >
  23. <div class="color-picker-box">
  24. <el-color-picker
  25. v-model="startColor"
  26. class="bs-el-color-picker"
  27. popper-class="bs-el-color-picker"
  28. />
  29. <div class="el-icon-right" />
  30. <el-color-picker
  31. v-model="endColor"
  32. class="bs-el-color-picker"
  33. popper-class="bs-el-color-picker"
  34. />
  35. </div>
  36. </el-form-item>
  37. </div>
  38. </template>
  39. <script>
  40. // import _ from 'lodash'
  41. import cloneDeep from 'lodash/cloneDeep'
  42. export default {
  43. name: 'TextGradient',
  44. model: {
  45. prop: 'colors',
  46. event: 'change'
  47. },
  48. props: {
  49. colors: {
  50. type: String,
  51. default: ''
  52. },
  53. label: {
  54. type: String,
  55. default: ''
  56. }
  57. },
  58. data () {
  59. return {
  60. startColor: '', // 初始颜色
  61. endColor: '', // 终止颜色
  62. position: '', // 渐变方向
  63. colorsValue: ''// 拼接后的符合g2语法的颜色值
  64. }
  65. },
  66. computed: {
  67. newColors () {
  68. return cloneDeep(this.colors)
  69. },
  70. customLabel () {
  71. return this.label || '文字'
  72. }
  73. },
  74. watch: {
  75. position () {
  76. this.colorChange()
  77. },
  78. startColor () {
  79. this.colorChange()
  80. },
  81. endColor () {
  82. this.colorChange()
  83. }
  84. },
  85. mounted () {
  86. this.init()
  87. },
  88. methods: {
  89. init () {
  90. const arr = this.newColors.split(',').map(data => data.trim()) || []
  91. this.position = arr[0] || 'left'
  92. const s = arr[1] || '#ffffff'
  93. const e = arr[2] || '#ffffff'
  94. this.startColor = s
  95. this.endColor = e
  96. },
  97. colorChange (val) {
  98. if (!this.startColor && this.endColor) {
  99. this.colorsValue = `${this.position} ,${this.endColor},${this.endColor}`
  100. } else if (this.startColor && !this.endColor) {
  101. this.colorsValue = `${this.position} ,${this.startColor} ,${this.startColor}`
  102. } else if (!this.startColor && !this.endColor) {
  103. this.colorsValue = `${this.position} ,#ffffff ,#ffffff`
  104. } else {
  105. this.colorsValue = `${this.position} ,${this.startColor} ,${this.endColor}`
  106. }
  107. this.$emit('change', this.colorsValue)
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. @import "../../../assets/style/bsTheme.scss";
  114. .color-picker-box{
  115. width: 100%;
  116. display: flex;
  117. align-items: center;
  118. justify-content: left;
  119. flex-wrap: nowrap;
  120. .el-icon-right{
  121. width: 40px;
  122. text-align: center;
  123. /*color: #778390;*/
  124. }
  125. }
  126. </style>