闫增涛
2024-07-01 0ab7ff07fd29ac32be045d505ae2d2b9290647a7
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
<template>
  <div class="tools">
    <button
      v-for="(item, index) of toolList"
      :key="index"
      :class="{ active: toolSelected === item.name }"
      :title="item.title"
      @click="onChangeTool(item.name, index)"
      :style="{ boxShadow: index == num ? '0 0 15px #00ccff' : '' }"
    >
      <img
        :src="item.icon"
        alt=""
        class="giaffiti-btn"
        :style="{ width: index == 0 ? '18px' : '' }"
      />
    </button>
  </div>
</template>
 
<script>
export default {
  props: {
    tool: {
      type: String,
      default: "brush",
    },
  },
  computed: {
    toolSelected() {
      return this.tool;
    },
  },
  data() {
    return {
      toolList: [
        {
          name: "brush",
          title: "画笔",
          icon: require("@/assets/images/brush.png"),
        },
        {
          name: "eraser",
          title: "橡皮擦",
          icon: require("@/assets/images/rubber.png"),
        },
        {
          name: "clear",
          title: "清空",
          icon: require("@/assets/images/scrub.png"),
        },
        {
          name: "undo",
          title: "撤销",
          icon: require("@/assets/images/revoke.png"),
        },
        {
          name: "save",
          title: "保存",
          icon: require("@/assets/images/save.png"),
        },
      ],
      num: 0,
    };
  },
  methods: {
    onChangeTool(tool, index) {
      if (index == 0 || index == 1) this.num = index;
      this.$emit("change-tool", tool);
    },
  },
};
</script>
 
<style scoped>
.tools {
  display: flex;
  align-items: center;
}
.tools button {
  /* border-radius: 50%; */
  width: 32px;
  height: 32px;
  background-color: rgba(255, 255, 255, 0.7);
  border: 1px solid #eee;
  outline: none;
  cursor: pointer;
  box-sizing: border-box;
  margin: 0 8px;
  padding: 0;
  text-align: center;
  color: #ccc;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
  transition: 0.3s;
}
 
.tools button.active,
.tools button:active {
  /* box-shadow: 0 0 15px #00CCFF; */
  color: #00ccff;
}
 
.tools button i {
  font-size: 20px;
}
.giaffiti-btn {
  width: 24px;
}
</style>