index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /** * @Description: 渐变色配置 * @author liu.shiyi * @date 2023/4/13 16:01 */
  2. <template>
  3. <div class="bs-gradual-wrap">
  4. <el-color-picker v-model="startColor" /> <div class="el-icon-right" /> <el-color-picker v-model="endColor" />
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'GradualSetting',
  10. model: {
  11. prop: 'colors',
  12. event: 'change'
  13. },
  14. props: {
  15. colors: {
  16. type: String,
  17. default: ''
  18. }
  19. },
  20. data () {
  21. return {
  22. startColor: '', // 初始颜色
  23. endColor: '', // 终止颜色
  24. position: '', // 渐变方向
  25. colorsValue: ''// 拼接后的符合g2语法的颜色值
  26. }
  27. },
  28. computed: {
  29. },
  30. watch: {
  31. startColor () {
  32. this.colorChange()
  33. },
  34. endColor () {
  35. this.colorChange()
  36. }
  37. },
  38. mounted () {
  39. this.init()
  40. },
  41. methods: {
  42. init () {
  43. const arr = this.colors?.split(' ') || []
  44. this.position = arr[0]
  45. const s = arr[1].split(':')[1] && arr[1].split(':')[1] !== 'null' ? arr[1].split(':')[1] : ''
  46. const e = arr[2].split(':')[1] && arr[2].split(':')[1] !== 'null' ? arr[2].split(':')[1] : ''
  47. this.startColor = s
  48. this.endColor = e
  49. },
  50. colorChange (val) {
  51. this.colorsValue = `${this.position} 0:${this.startColor} 1:${this.endColor}`
  52. this.$emit('change', this.colorsValue)
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .bs-gradual-wrap{
  59. width: 100%;
  60. display: flex;
  61. align-items: center;
  62. .el-icon-right{
  63. width: 40px;
  64. text-align: center;
  65. }
  66. }
  67. </style>