index.vue 2.4 KB

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