index.vue
4.41 KB
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
162
163
164
165
<template>
<el-dialog title="图标选择" :close-on-click-modal="false"
class="NCC-dialog NCC-dialog_center icon-dialog" lock-scroll append-to-body v-bind="$attrs"
width="950px" :modal-append-to-body="false" v-on="$listeners" @open="onOpen" @close="onClose">
<div slot="title" class="icon-dialog-title">
图标选择
<el-input v-model="keyword" placeholder="请输入图标名称" prefix-icon="el-icon-search" clearable />
</div>
<el-tabs class="NCC-el_tabs" v-model="activeName">
<el-tab-pane label="ymIcon 图标">
<div class="icon-box-list">
<el-button v-for="(item, index) in ymIconsList" :key="index"
@click="iconActiveHandle(generateYmIconCode(item))"
:class="{ 'is-active': generateYmIconCode(item) === active }">
<i :class="generateYmIconCode(item)" />
</el-button>
</div>
</el-tab-pane>
<el-tab-pane label="Element-UI 图标">
<div class="icon-box-list">
<el-button v-for="(item, index) in elementIconsList" :key="index"
@click="iconActiveHandle(item)" :class="{ 'is-active': item === active }">
<i :class="item" />
</el-button>
</div>
</el-tab-pane>
<el-tab-pane label="ymCustom 图标">
<div class="icon-box-list">
<el-button v-for="(item, index) in ymCustomList" :key="index"
@click="iconActiveHandle(generateYmCustomCode(item))"
:class="{ 'is-active': generateYmCustomCode(item) === active }">
<i :class="generateYmCustomCode(item)" />
</el-button>
</div>
</el-tab-pane>
</el-tabs>
<span slot="footer" class="dialog-footer">
<el-button @click="closeDialog">{{$t('common.cancelButton')}}</el-button>
<el-button type="primary" @click="choiceIcon()">{{$t('common.confirmButton')}}</el-button>
</span>
</el-dialog>
</template>
<script>
import elementIconsJson from 'static/json/element-icons.json'
import ymIconsJson from 'static/json/ymIcon.json'
import ymCustomJson from 'static/json/ymCustom.json'
const ymIcons = ymIconsJson.glyphs.map(o => `icon-ym-${o.font_class}`)
const ymCustom = ymCustomJson.glyphs.map(o => `ym-custom-${o.font_class}`)
const elementIcons = elementIconsJson.map(name => `el-icon-${name}`)
export default {
props: ['current'],
data() {
return {
elementIcons,
ymIcons,
ymCustom,
active: null,
keyword: '',
ymIconsList: [],
ymCustomList: [],
elementIconsList: [],
activeName: ''
}
},
watch: {
keyword(val) {
this.search()
},
activeName(val) {
if (this.keyword) {
this.keyword = ''
} else {
this.search()
}
}
},
methods: {
search() {
let key = ''
if (this.activeName == '0') {
key = 'ymIcons'
} else if (this.activeName == '1') {
key = 'elementIcons'
} else if (this.activeName == '2') {
key = 'ymCustom'
}
if (this.keyword) {
this[key + 'List'] = this[key].filter(o => o.indexOf(this.keyword) > -1)
} else {
this[key + 'List'] = this[key]
}
},
onOpen() {
this.active = this.current
this.keyword = ''
},
onClose() { },
closeDialog() {
this.$emit('update:visible', false)
},
choiceIcon() {
if (!this.active) return
this.$emit('choiceIcon', this.active)
this.$emit('update:visible', false)
},
generateYmIconCode(symbol) {
return `icon-ym ${symbol}`
},
generateYmCustomCode(symbol) {
return `ym-custom ${symbol}`
},
iconActiveHandle(item) {
this.active = item
}
}
}
</script>
<style lang="scss" scoped>
.icon-dialog {
.icon-dialog-title {
font-size: 18px;
.el-input {
width: 260px;
margin-left: 10px;
}
}
>>> .el-dialog__body {
height: 70vh;
padding: 0 20px !important;
}
}
.icon-box-list {
padding-bottom: 8px;
> .el-button {
margin: 8px 0 0 8px;
width: 60px;
height: 60px;
padding: 0;
>>> span {
width: 60px;
height: 60px;
display: inline-block;
line-height: 60px;
text-align: center;
transition: 300ms;
[class^='el-icon-'] {
margin-top: 17px;
}
.fa {
margin-top: 17px;
}
}
i {
font-size: 24px;
}
&:hover {
>>> span {
transform: scale(1.8);
}
}
}
}
</style>