he wei
2024-04-15 c94f1afa786f297be86b01b49a641b2c0ad98b6e
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
<template>
  <div :class="['gradient-btn', size, {active, disabled}]" @click="handlerClick" :style="styleVar">
    <slot>按钮</slot>
  </div>
</template>
 
<script>
export default {
  name: "",
 
  data() {
    return {};
  },
  props: {
    startColor: {
      type: String,
      default: "#50C9FE",
    },
    stopColor: {
      type: String,
      default: "#3473DA",
    },
    direction: {
      type: Number,
      default: 180,
    },
    color: {
      type: String,
      defualt: "#fff",
    },
    size: {
      type: String,
      validator(v) {
        return ['', "lg", "sm", "xs"].some((value) => v == value);
      },
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    active: {
      type: Boolean,
      default: false,
    }
  },
  components: {},
  computed: {
    styleVar() {
      return {
        "--color": this.color,
        "--startColor": this.startColor,
        "--stopColor": this.stopColor,
        "--direction": this.direction + "deg",
      };
    },
  },
  methods: {
    handlerClick() {
      if (this.disabled) {
        return false;
      }
      this.$emit("click");
    },
  },
 
  mounted() {},
};
</script>
 
<style scoped lang="less">
.gradient-btn {
  display: inline-block;
  cursor: pointer;
  min-width: 3em;
  padding: 10px;
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--color);
  background: linear-gradient(
    var(--direction),
    var(--startColor),
    var(--stopColor)
  );
  &.lg {
    padding: 16px;
    border-radius: 8px;
  }
  &.sm {
    padding: 8px;
    border-radius: 4px;
  }
  &.xs {
    padding: 4px;
    border-radius: 3px;
  }
  &~.gradient-btn {
    margin-left: 6px;
  }
  &.active {
    background: #F2891B;
  }
  &.disabled {
    cursor: not-allowed;
    background: #ccc;
  }
}
</style>