index.vue 2.7 KB

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