litian
2025-04-14 1d37cc9cb15c01d0f411f2c8c384f71a612fb2b9
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
<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>
  import brush from '@/assets/images/graffiti/brush.png'
  import rubber from '@/assets/images/graffiti/rubber.png'
  import scrub from '@/assets/images/graffiti/scrub.png'
  import revoke from '@/assets/images/graffiti/revoke.png'
  import save from '@/assets/images/graffiti/save.png'
  export default {
    props: {
      tool: {
        type: String,
        default: "brush",
      },
    },
    computed: {
      toolSelected() {
        return this.tool;
      },
    },
    data() {
      return {
        toolList: [
          {
            name: "brush",
            title: "画笔",
            icon: brush,
          },
          {
            name: "eraser",
            title: "橡皮擦",
            icon: rubber,
          },
          {
            name: "clear",
            title: "清空",
            icon: scrub,
          },
          {
            name: "undo",
            title: "撤销",
            icon: revoke,
          },
          {
            name: "save",
            title: "保存",
            icon: save,
          },
        ],
        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>