Skip to content

Commit b661cde

Browse files
committed
feat: add icon-selector component
1 parent 96ec260 commit b661cde

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<div>
3+
<a-tabs>
4+
<a-tab-pane v-for="(v, i) in icons" :tab="v.title" :key="i">
5+
<ul>
6+
<li v-for="(icon, key) in v.icons" :key="`${v.title}-${key}`" :class="{ 'active': selectedIcon==icon }">
7+
<a-icon :type="icon" :style="{ fontSize: '36px' }" @click="handleSelectedIcon(icon)" />
8+
</li>
9+
</ul>
10+
</a-tab-pane>
11+
</a-tabs>
12+
</div>
13+
</template>
14+
15+
<script>
16+
import icons from './icons'
17+
18+
export default {
19+
name: 'IconSelect',
20+
data () {
21+
return {
22+
selectedIcon: '',
23+
icons
24+
}
25+
},
26+
methods: {
27+
handleSelectedIcon (icon) {
28+
this.selectedIcon = icon
29+
this.$emit('change', icon)
30+
}
31+
}
32+
}
33+
</script>
34+
35+
<style lang="less" scoped>
36+
ul{
37+
list-style: none;
38+
padding: 0;
39+
overflow-y: scroll;
40+
height: 250px;
41+
li{
42+
display: inline-block;
43+
padding:5px;
44+
margin:5px;
45+
&:hover {
46+
cursor: pointer;
47+
}
48+
&.active{
49+
box-shadow: 0px 0px 5px 2px #888888;
50+
}
51+
}
52+
}
53+
</style>

src/components/IconSelector/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
IconSelector
2+
====
3+
4+
> 图标选择组件,常用于为某一个数据设定一个图标时使用
5+
> eg: 设定菜单列表时,为每个菜单设定一个图标
6+
7+
该组件由 [@AraragiTsukihiz](https://github.com./araragitsukihiz) 封装
8+
9+
10+
11+
### 使用方式
12+
13+
```vue
14+
<template>
15+
<div>
16+
<icon-selector @change="handleIconChange"/>
17+
</div>
18+
</template>
19+
20+
<script>
21+
import IconSelector from '@/components/IconSelector'
22+
23+
export default {
24+
name: 'YourView',
25+
components: {
26+
IconSelector
27+
},
28+
data () {
29+
return {
30+
}
31+
},
32+
methods: {
33+
handleIconChange (icon) {
34+
console.log('change Icon', icon)
35+
}
36+
}
37+
}
38+
</script>
39+
```
40+
41+
42+
43+
### 事件
44+
45+
46+
| 名称 | 说明 | 类型 | 默认值 |
47+
| ------ | -------------------------- | ------ | ------ |
48+
| change | 当改变了 `icon` 选中项触发 | String | - |

src/components/IconSelector/icons.js

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/IconSelector/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import IconSelector from './IconSelector'
2+
export default IconSelector

src/config/router.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ export const asyncRouterMap = [
308308
]
309309
}
310310
]
311+
},
312+
313+
// other
314+
{
315+
path: '/other',
316+
name: 'otherPage',
317+
component: PageView,
318+
meta: { title: '其他组件', icon: 'slack', permission: [ 'dashboard' ] },
319+
redirect: '/other/icon-selector',
320+
children: [
321+
{
322+
path: '/other/icon-selector',
323+
name: 'TestIconSelect',
324+
component: () => import('@/views/other/IconSelectorView'),
325+
meta: { title: 'IconSelector', keepAlive: true, permission: [ 'dashboard' ] }
326+
}
327+
]
311328
}
312329
]
313330
},

src/views/other/IconSelectorView.vue

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<a-card :body-style="{padding: '24px 32px'}" :bordered="false">
3+
<icon-selector @change="handleIconChange"/>
4+
</a-card>
5+
</template>
6+
7+
<script>
8+
import IconSelector from '@/components/IconSelector'
9+
10+
export default {
11+
name: 'IconSelectorView',
12+
components: {
13+
IconSelector
14+
},
15+
data () {
16+
return {
17+
18+
}
19+
},
20+
methods: {
21+
handleIconChange (icon) {
22+
console.log('change Icon', icon)
23+
this.$message.info(<span>选中图标 <code>{icon}</code></span>)
24+
}
25+
}
26+
}
27+
</script>

0 commit comments

Comments
 (0)