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