index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. export default {
  42. name: 'TextGradient',
  43. model: {
  44. prop: 'colors',
  45. event: 'change'
  46. },
  47. props: {
  48. colors: {
  49. type: String,
  50. default: '',
  51. required: true
  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. // {
  69. // get () {
  70. // return this.colors
  71. // },
  72. // set (val) {
  73. // this.$emit('change', val)
  74. // }
  75. // },
  76. customLabel () {
  77. return this.label || '文字'
  78. }
  79. },
  80. watch: {
  81. colors: {
  82. handler (val) {
  83. this.init()
  84. },
  85. immediate: true
  86. },
  87. position () {
  88. this.colorChange()
  89. },
  90. startColor () {
  91. this.colorChange()
  92. },
  93. endColor () {
  94. this.colorChange()
  95. }
  96. },
  97. mounted () {
  98. this.init()
  99. },
  100. methods: {
  101. init () {
  102. const arr = this.colors.split(',').map(data => data.trim()) || []
  103. this.position = arr[0] || 'left'
  104. const s = arr[1] || '#ffffff'
  105. const e = arr[2] || '#ffffff'
  106. this.startColor = s
  107. this.endColor = e
  108. },
  109. colorChange (val) {
  110. if (!this.startColor && this.endColor) {
  111. this.colorsValue = `${this.position} ,${this.endColor},${this.endColor}`
  112. } else if (this.startColor && !this.endColor) {
  113. this.colorsValue = `${this.position} ,${this.startColor} ,${this.startColor}`
  114. } else if (!this.startColor && !this.endColor) {
  115. this.colorsValue = `${this.position} ,#ffffff ,#ffffff`
  116. } else {
  117. this.colorsValue = `${this.position} ,${this.startColor} ,${this.endColor}`
  118. }
  119. this.$emit('change', this.colorsValue)
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. @import "../../../assets/style/bsTheme.scss";
  126. .color-picker-box{
  127. width: 100%;
  128. display: flex;
  129. align-items: center;
  130. justify-content: left;
  131. flex-wrap: nowrap;
  132. .el-icon-right{
  133. width: 40px;
  134. text-align: center;
  135. /*color: #778390;*/
  136. }
  137. }
  138. </style>