保誠-保戶業務員媒合平台
tomasysh
2025-01-02 4efb98f2b554b76270b12837db7a7f724e2ede89
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
<template>
  <div class="el-color-svpanel"
      :style="{
        backgroundColor: background
      }">
    <div class="el-color-svpanel__white"></div>
    <div class="el-color-svpanel__black"></div>
    <div class="el-color-svpanel__cursor"
      :style="{
        top: cursorTop + 'px',
        left: cursorLeft + 'px'
      }">
      <div></div>
    </div>
  </div>
</template>
 
<script>
  import draggable from '../draggable';
 
  export default {
    name: 'el-sl-panel',
 
    props: {
      color: {
        required: true
      }
    },
 
    computed: {
      colorValue() {
        const hue = this.color.get('hue');
        const value = this.color.get('value');
        return { hue, value };
      }
    },
 
    watch: {
      colorValue() {
        this.update();
      }
    },
 
    methods: {
      update() {
        const saturation = this.color.get('saturation');
        const value = this.color.get('value');
 
        const el = this.$el;
        let { clientWidth: width, clientHeight: height } = el;
 
        this.cursorLeft = saturation * width / 100;
        this.cursorTop = (100 - value) * height / 100;
 
        this.background = 'hsl(' + this.color.get('hue') + ', 100%, 50%)';
      },
 
      handleDrag(event) {
        const el = this.$el;
        const rect = el.getBoundingClientRect();
 
        let left = event.clientX - rect.left;
        let top = event.clientY - rect.top;
        left = Math.max(0, left);
        left = Math.min(left, rect.width);
 
        top = Math.max(0, top);
        top = Math.min(top, rect.height);
 
        this.cursorLeft = left;
        this.cursorTop = top;
        this.color.set({
          saturation: left / rect.width * 100,
          value: 100 - top / rect.height * 100
        });
      }
    },
 
    mounted() {
      draggable(this.$el, {
        drag: (event) => {
          this.handleDrag(event);
        },
        end: (event) => {
          this.handleDrag(event);
        }
      });
 
      this.update();
    },
 
    data() {
      return {
        cursorTop: 0,
        cursorLeft: 0,
        background: 'hsl(0, 100%, 50%)'
      };
    }
  };
</script>