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
| /** * @Description: 渐变色配置 * @author liu.shiyi * @date 2023/4/13 16:01 */
| <template>
| <div class="bs-gradual-wrap">
| <el-color-picker
| v-model="startColor"
| class="bs-el-color-picker"
| popper-class="bs-el-color-picker"
| />
| <div :class="positionIcon" @click="positionChange" />
| <el-color-picker
| v-model="endColor"
| class="bs-el-color-picker"
| popper-class="bs-el-color-picker"
| />
| </div>
| </template>
|
| <script>
| export default {
| name: 'GradualSetting',
| model: {
| prop: 'colors',
| event: 'change'
| },
| props: {
| colors: {
| type: String,
| default: ''
| }
| },
| data () {
| return {
| startColor: '', // 初始颜色
| endColor: '', // 终止颜色
| position: '', // 渐变方向
| colorsValue: '',// 拼接后的符合g2语法的颜色值
| positionList: ['l(0)', 'l(90)', 'l(180)', 'l(270)'],
| positionIconList: {
| 'l(0)': 'el-icon-right',
| 'l(90)': 'el-icon-bottom',
| 'l(180)': 'el-icon-back',
| 'l(270)': 'el-icon-top'
| },
| positionIcon: 'el-icon-right'
| }
| },
| computed: {
| },
| watch: {
| startColor () {
| this.colorChange()
| },
| endColor () {
| this.colorChange()
| }
| },
| mounted () {
| this.init()
| },
| methods: {
| init () {
| // color 格式是 'l(0) 0:#ffffff 1:#000000'
| const arr = this.colors?.split(' ') || []
| this.position = arr[0] || 'l(0)'
| this.positionIcon = this.positionIconList[this.position] || 'el-icon-right'
| const s = arr[1].split(':')[1] && arr[1].split(':')[1] !== 'null' ? arr[1].split(':')[1] : ''
| const e = arr[2].split(':')[1] && arr[2].split(':')[1] !== 'null' ? arr[2].split(':')[1] : ''
| this.startColor = s
| this.endColor = e
| },
| colorChange (val) {
| this.colorsValue = `${this.position} 0:${this.startColor} 1:${this.endColor}`
| this.$emit('change', this.colorsValue)
| },
| positionChange(){
| // 将position的值循环移动一位
| const index = this.positionList.indexOf(this.position)
| this.position = this.positionList[(index + 1) % 4]
| this.positionIcon = this.positionIconList[this.position]
| this.colorChange()
| },
| }
| }
| </script>
|
| <style lang="scss" scoped>
|
| .bs-gradual-wrap{
| width: 100%;
| display: flex;
| align-items: center;
| .el-icon-right{
| width: 40px;
| text-align: center;
| cursor: pointer;
|
| }
| .el-icon-bottom{
| width: 40px;
| text-align: center;
| cursor: pointer;
| }
| .el-icon-back{
| width: 40px;
| text-align: center;
| cursor: pointer;
| }
| .el-icon-top {
| width: 40px;
| text-align: center;
| cursor: pointer;
| }
| }
|
| </style>
|
|