index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-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="文字渐变颜色"
  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. },
  54. data () {
  55. return {
  56. startColor: '', // 初始颜色
  57. endColor: '', // 终止颜色
  58. position: '', // 渐变方向
  59. colorsValue: ''// 拼接后的符合g2语法的颜色值
  60. }
  61. },
  62. computed: {
  63. newColors () {
  64. return cloneDeep(this.colors)
  65. }
  66. },
  67. watch: {
  68. position () {
  69. this.colorChange()
  70. },
  71. startColor () {
  72. this.colorChange()
  73. },
  74. endColor () {
  75. this.colorChange()
  76. }
  77. },
  78. mounted () {
  79. this.init()
  80. },
  81. methods: {
  82. init () {
  83. const arr = this.newColors.split(',').map(data => data.trim()) || []
  84. this.position = arr[0] || 'left'
  85. const s = arr[1] || '#ffffff'
  86. const e = arr[2] || '#ffffff'
  87. this.startColor = s
  88. this.endColor = e
  89. },
  90. colorChange (val) {
  91. if (!this.startColor && this.endColor) {
  92. this.colorsValue = `${this.position} ,${this.endColor},${this.endColor}`
  93. } else if (this.startColor && !this.endColor) {
  94. this.colorsValue = `${this.position} ,${this.startColor} ,${this.startColor}`
  95. } else if (!this.startColor && !this.endColor) {
  96. this.colorsValue = `${this.position} ,#ffffff ,#ffffff`
  97. } else {
  98. this.colorsValue = `${this.position} ,${this.startColor} ,${this.endColor}`
  99. }
  100. this.$emit('change', this.colorsValue)
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. @import "../../../assets/style/bsTheme.scss";
  107. .color-picker-box{
  108. width: 100%;
  109. display: flex;
  110. align-items: center;
  111. justify-content: left;
  112. flex-wrap: nowrap;
  113. .el-icon-right{
  114. width: 40px;
  115. text-align: center;
  116. /*color: #778390;*/
  117. }
  118. }
  119. </style>