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
<template>
<tooltip v-if="icons.length > 0" :content="icons.length > 1 ? '其他' : icons[0].text" :class="`app-icon ${disabled ? 'app-icon--disabled' : 'app-icon--normal'}`" placement="top" :disabled="disabled" :transfer="true">
<template v-if="icons.length > 1">
<poptip v-model="visible" trigger="hover" content="content" placement="bottom" :transfer="true" popper-class="app-icon-others" :disabled="disabled">
<img src="/assets/img/others.svg" />
<div class="others" slot="content">
<div v-for="(icon, index) in icons" :key="index" class="others-item" @click="($event) => handleClick(icon, $event)">
<span class="icon-text">{{icon.text}}</span>
</div>
</div>
</poptip>
</template>
<template v-else-if="icons.length == 1">
<img v-if="icons[0].imgPath" :src="icons[0].imgPath" @click="($event) => handleClick(icons[0], $event)"/>
<i v-else-if="icons[0].iconClass" :class="icons[0].iconClass" @click="($event) => handleClick(icons[0], $event)"></i>
</template>
</tooltip>
</template>
<script lang='ts'>
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component({})
export default class AppIcon extends Vue {
/**
* 禁用
*
* @type {boolean}
* @memberof AppIcon
*/
@Prop({ default: false })
public disabled!: boolean;
/**
* 图标集
*
* @type {any[]}
* @memberof AppIcon
*/
@Prop({ default: () => [] })
public icons!: any[];
/**
* 显示poptip
*
* @type {any[]}
* @memberof AppIcon
*/
public visible: boolean = false;
/**
* 处理点击
*
* @memberof AppIcon
*/
public handleClick(icon: any, $event: MouseEvent) {
$event.stopPropagation();
$event.preventDefault();
this.visible = false;
if (!this.disabled) {
this.$emit('click', icon, $event);
}
}
}
</script>
<style lang="scss">
@import './app-icon.scss';
</style>