zhangzeli
2021-11-01 baa03e2f9b1388a673e39cc3f2c1b055b16e513e
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template>
  <Card
    :padding="0"
    :bordered="bordered"
    :style="{ backgroundColor: realBackgroundColor }"
  >
    <div
      class="card-app card-content"
      @click="click"
      @mouseover="itemHover"
      @mouseout="removeHover"
    >
      <div class="card-body">
        <Icon
          class="card-icon"
          :type="icon"
          :color="realIconColor"
          :size="iconSize"
          v-if="icon"
        ></Icon>
        <img :src="image" :width="width" :height="height" v-else />
        <div
          class="card-title"
          :style="{
            color: realTitleColor,
            fontSize: titleSize,
            fontWeight: titleWeight,
          }"
        >
          {{ title }}
        </div>
      </div>
    </div>
  </Card>
</template>
 
<script>
export default {
  name: "card-app",
  components: {},
  props: {
    idName: String,
    backgroundColor: String,
    activeColor: {
      type: String,
      default: "#2d8cf0",
    },
    openBackColorChange: {
      type: Boolean,
      default: true,
    },
    bordered: {
      type: Boolean,
      default: true,
    },
    icon: String,
    iconSize: {
      type: Number,
      default: 40,
    },
    iconColor: {
      type: String,
      default: "#b5b5c5",
    },
    image: String,
    width: {
      type: String,
      default: "40px",
    },
    height: {
      type: String,
      default: "40px",
    },
    title: String,
    titleColor: {
      type: String,
      default: "#7e8299",
    },
    titleSize: {
      type: String,
      default: "16px",
    },
    titleWeight: {
      type: Number,
      default: 600,
    },
  },
  data() {
    return {
      clicked: false,
      realIconColor: this.iconColor,
      realTitleColor: this.titleColor,
      realBackgroundColor: this.backgroundColor,
    };
  },
  methods: {
    click() {
      this.clicked = !this.clicked;
      if (this.clicked) {
        if (this.openBackColorChange) {
          this.realBackgroundColor = this.activeColor;
          this.bordered = false;
          this.realIconColor = "#fff";
          this.realTitleColor = "#fff";
        } else {
          this.realIconColor = this.activeColor;
          this.realTitleColor = this.activeColor;
        }
      } else {
        if (this.openBackColorChange) {
          this.realBackgroundColor = this.backgroundColor;
          this.bordered = false;
          this.realIconColor = this.iconColor;
          this.realTitleColor = this.titleColor;
        } else {
          this.realIconColor = this.iconColor;
          this.realTitleColor = this.titleColor;
        }
      }
    },
    itemHover() {
      if (!this.clicked) {
        this.realIconColor = this.activeColor;
        this.realTitleColor = this.activeColor;
      }
    },
    removeHover() {
      if (!this.clicked) {
        this.realIconColor = this.iconColor;
        this.realTitleColor = this.titleColor;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.card-content {
  height: 150px;
  padding: 26px 30px;
}
.card-app {
  cursor: pointer;
  .card-body {
    display: flex;
    flex-direction: column;
    height: 102px;
    justify-content: center;
    align-items: center;
    .card-icon {
      transition: all 0.2s ease;
    }
    .card-title {
      transition: all 0.2s ease;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      margin-top: 10px;
    }
  }
}
</style>