mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-21 16:36:48 +08:00
tt
This commit is contained in:
187
hotgo-web/src/components/IconSelector/IconDetail.vue
Normal file
187
hotgo-web/src/components/IconSelector/IconDetail.vue
Normal file
@@ -0,0 +1,187 @@
|
||||
<template>
|
||||
<div class="prefixCls">
|
||||
<a-tabs v-model="currentTab" @change="handleTabChange">
|
||||
<a-tab-pane v-for="v in icons" :key="v.key">
|
||||
<span slot="tab" :style="{ fontSize: '10px' }">
|
||||
{{ v.title }}
|
||||
</span>
|
||||
<ul v-if="v.key != 'custom'" style="height: calc(100vh - 196px) ;">
|
||||
<li v-for="(icon, key) in iconList" :key="`${v.key}-${key}`" :class="{ 'active': selectedIcon==icon }" @click="handleSelectedIcon(icon)" >
|
||||
<a-icon :type="icon" :component="allIcon[icon + 'Icon']" :style="{ fontSize: '24px' }" />
|
||||
<span class="anticon-class">
|
||||
<span class="ant-badge">
|
||||
{{ icon }}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="IconList" v-if="v.key == 'custom'" style="height: calc(100vh - 196px) ;">
|
||||
<li v-for="(icon, key) in iconList" :key="`${v.key}-${key}`" :class="{ 'active': selectedIcon==icon }" @click="handleSelectedIcon(icon,'1')" >
|
||||
<a-icon :component="allIcon[icon + 'Icon']" :type="icon"/>
|
||||
<span class="anticon-class">
|
||||
<span class="ant-badge">
|
||||
{{ icon }}
|
||||
</span>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</a-tab-pane>
|
||||
<a-input-search class="inputsearch" slot="tabBarExtraContent" placeholder="全局搜索图标" @search="onSearchAll" />
|
||||
</a-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import icons from './icons'
|
||||
import allCustomIcon from '@/core/icons'
|
||||
export default {
|
||||
name: 'IconSelect',
|
||||
props: {
|
||||
prefixCls: {
|
||||
type: String,
|
||||
default: 'ant-pro-icon-selector'
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
value: {
|
||||
type: String
|
||||
},
|
||||
svgIcons: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
allIcon: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
selectedIcon: this.value || '',
|
||||
currentTab: 'custom',
|
||||
icons: icons,
|
||||
allCustomIcon,
|
||||
iconList: [], // 页面真实展示图标集合,根据搜索条件改变
|
||||
currentIconList: [] // 记录当前页面图标集合,不会根据搜索条件改变
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value (val) {
|
||||
this.selectedIcon = val
|
||||
this.autoSwitchTab()
|
||||
}
|
||||
},
|
||||
created () {
|
||||
if (this.value) {
|
||||
this.autoSwitchTab()
|
||||
}
|
||||
const custom = [{
|
||||
key: 'custom',
|
||||
title: '自定义图标',
|
||||
icons: this.svgIcons
|
||||
}]
|
||||
this.icons = custom.concat(this.icons)
|
||||
this.getCurrentIconList()
|
||||
},
|
||||
methods: {
|
||||
handleSelectedIcon (icon, type) {
|
||||
this.selectedIcon = icon
|
||||
if (allCustomIcon[icon + 'Icon']) {
|
||||
// 自定义图标,这里不能根据页签区分是否为自定义图标,因为搜索为全局搜索
|
||||
type = '1'
|
||||
} else {
|
||||
type = '2'
|
||||
}
|
||||
let copayValue = '<a-icon type="' + icon + '" />'
|
||||
if (type === '1') {
|
||||
// 自定义图标
|
||||
copayValue = '<a-icon type="" :component="allIcon.' + icon + 'Icon"/>'
|
||||
}
|
||||
var domType = document.createElement('input')
|
||||
domType.value = copayValue
|
||||
domType.id = 'creatDom'
|
||||
document.body.appendChild(domType)
|
||||
domType.select() // 选择对象
|
||||
document.execCommand('Copy') // 执行浏览器复制命令
|
||||
const creatDom = document.getElementById('creatDom')
|
||||
creatDom.parentNode.removeChild(creatDom)
|
||||
this.$message.success(
|
||||
copayValue + ' 复制成功 🎉🎉🎉',
|
||||
3
|
||||
)
|
||||
},
|
||||
handleTabChange (activeKey) {
|
||||
this.currentTab = activeKey
|
||||
this.getCurrentIconList()
|
||||
},
|
||||
autoSwitchTab () {
|
||||
const icons = this.icons
|
||||
icons.some(item => item.icons.some(icon => icon === this.value) && (this.currentTab = item.key))
|
||||
},
|
||||
getCurrentIconList () {
|
||||
this.icons.forEach((icon, index) => {
|
||||
if (icon.key === this.currentTab) {
|
||||
this.iconList = icon.icons
|
||||
this.currentIconList = icon.icons
|
||||
}
|
||||
})
|
||||
},
|
||||
onSearchAll (text) {
|
||||
if (text === '') {
|
||||
this.iconList = this.currentIconList
|
||||
return
|
||||
}
|
||||
this.iconList = []
|
||||
this.icons.forEach((icon, index) => {
|
||||
icon.icons.forEach((icon, index) => {
|
||||
if (icon.toUpperCase().indexOf(text.toUpperCase()) >= 0) {
|
||||
this.iconList.push(icon)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import "../index.less";
|
||||
.prefixCls{
|
||||
background: #ffffff;
|
||||
.inputsearch{
|
||||
width: 200px;
|
||||
margin-right: 15px;
|
||||
}
|
||||
}
|
||||
ul{
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
overflow-y: scroll;
|
||||
li{
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
height:105px;
|
||||
padding: 0;
|
||||
margin: 15px 13px;
|
||||
text-align: center;
|
||||
border-radius: @border-radius-base;
|
||||
|
||||
&:hover, &.active{
|
||||
// box-shadow: 0px 0px 5px 2px @primary-color;
|
||||
cursor: pointer;
|
||||
color: @white;
|
||||
background-color: @primary-color;
|
||||
}
|
||||
i.anticon {
|
||||
display: inline-block;
|
||||
margin-top: 25px;
|
||||
font-size: 24px;
|
||||
}
|
||||
.anticon-class {
|
||||
display: block;
|
||||
text-align: center;
|
||||
transform: scale(.83);
|
||||
margin-top: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
109
hotgo-web/src/components/IconSelector/IconSelector.vue
Normal file
109
hotgo-web/src/components/IconSelector/IconSelector.vue
Normal file
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<div :class="prefixCls">
|
||||
<a-tabs v-model="currentTab" @change="handleTabChange">
|
||||
<a-tab-pane v-for="v in icons" :key="v.key">
|
||||
<span slot="tab" :style="{ fontSize: '10px' }">
|
||||
{{ v.title }}
|
||||
</span>
|
||||
<ul v-if="v.key != 'custom'">
|
||||
<li v-for="(icon, key) in v.icons" :key="`${v.key}-${key}`" :class="{ 'active': selectedIcon==icon }" @click="handleSelectedIcon(icon)" >
|
||||
<a-icon :type="icon" :style="{ fontSize: '24px' }" />
|
||||
</li>
|
||||
</ul>
|
||||
<ul v-if="v.key == 'custom'">
|
||||
<li v-for="(icon, key) in v.icons" :key="`${v.key}-${key}`" :class="{ 'active': selectedIcon==icon }" @click="handleSelectedIcon(icon)" >
|
||||
<a-icon :component="allIcon[icon + 'Icon']" :style="{ fontSize: '24px' }"/>
|
||||
</li>
|
||||
</ul>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import icons from './icons'
|
||||
|
||||
export default {
|
||||
name: 'IconSelect',
|
||||
props: {
|
||||
prefixCls: {
|
||||
type: String,
|
||||
default: 'ant-pro-icon-selector'
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
value: {
|
||||
type: String
|
||||
},
|
||||
svgIcons: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
allIcon: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
selectedIcon: this.value || '',
|
||||
currentTab: 'custom',
|
||||
icons: icons
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value (val) {
|
||||
this.selectedIcon = val
|
||||
this.autoSwitchTab()
|
||||
}
|
||||
},
|
||||
created () {
|
||||
if (this.value) {
|
||||
this.autoSwitchTab()
|
||||
}
|
||||
const custom = [{
|
||||
key: 'custom',
|
||||
title: '自定义图标',
|
||||
icons: this.svgIcons
|
||||
}]
|
||||
this.icons = custom.concat(this.icons)
|
||||
},
|
||||
methods: {
|
||||
handleSelectedIcon (icon) {
|
||||
this.selectedIcon = icon
|
||||
this.$emit('change', icon)
|
||||
},
|
||||
handleTabChange (activeKey) {
|
||||
this.currentTab = activeKey
|
||||
},
|
||||
autoSwitchTab () {
|
||||
const icons = this.icons
|
||||
icons.some(item => item.icons.some(icon => icon === this.value) && (this.currentTab = item.key))
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import "../index.less";
|
||||
|
||||
ul{
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
overflow-y: scroll;
|
||||
height: 250px;
|
||||
|
||||
li{
|
||||
display: inline-block;
|
||||
padding: @padding-sm;
|
||||
margin: 3px 0;
|
||||
border-radius: @border-radius-base;
|
||||
|
||||
&:hover, &.active{
|
||||
// box-shadow: 0px 0px 5px 2px @primary-color;
|
||||
cursor: pointer;
|
||||
color: @white;
|
||||
background-color: @primary-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
48
hotgo-web/src/components/IconSelector/README.md
Normal file
48
hotgo-web/src/components/IconSelector/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
IconSelector
|
||||
====
|
||||
|
||||
> 图标选择组件,常用于为某一个数据设定一个图标时使用
|
||||
> eg: 设定菜单列表时,为每个菜单设定一个图标
|
||||
|
||||
该组件由 [@Saraka](https://github.com/saraka-tsukai) 封装
|
||||
|
||||
|
||||
|
||||
### 使用方式
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<div>
|
||||
<icon-selector @change="handleIconChange"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import IconSelector from '@/components/IconSelector'
|
||||
|
||||
export default {
|
||||
name: 'YourView',
|
||||
components: {
|
||||
IconSelector
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleIconChange (icon) {
|
||||
console.log('change Icon', icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 事件
|
||||
|
||||
|
||||
| 名称 | 说明 | 类型 | 默认值 |
|
||||
| ------ | -------------------------- | ------ | ------ |
|
||||
| change | 当改变了 `icon` 选中项触发 | String | - |
|
||||
36
hotgo-web/src/components/IconSelector/icons.js
Normal file
36
hotgo-web/src/components/IconSelector/icons.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 增加新的图标时,请遵循以下数据结构
|
||||
* Adding new icon please follow the data structure below
|
||||
*/
|
||||
export default [
|
||||
{
|
||||
key: 'directional',
|
||||
title: '方向性图标',
|
||||
icons: ['step-backward', 'step-forward', 'fast-backward', 'fast-forward', 'shrink', 'arrows-alt', 'down', 'up', 'left', 'right', 'caret-up', 'caret-down', 'caret-left', 'caret-right', 'up-circle', 'down-circle', 'left-circle', 'right-circle', 'double-right', 'double-left', 'vertical-left', 'vertical-right', 'forward', 'backward', 'rollback', 'enter', 'retweet', 'swap', 'swap-left', 'swap-right', 'arrow-up', 'arrow-down', 'arrow-left', 'arrow-right', 'play-circle', 'up-square', 'down-square', 'left-square', 'right-square', 'login', 'logout', 'menu-fold', 'menu-unfold', 'border-bottom', 'border-horizontal', 'border-inner', 'border-left', 'border-right', 'border-top', 'border-verticle', 'pic-center', 'pic-left', 'pic-right', 'radius-bottomleft', 'radius-bottomright', 'radius-upleft', 'fullscreen', 'fullscreen-exit']
|
||||
},
|
||||
{
|
||||
key: 'suggested',
|
||||
title: '提示建议性图标',
|
||||
icons: ['question', 'question-circle', 'plus', 'plus-circle', 'pause', 'pause-circle', 'minus', 'minus-circle', 'plus-square', 'minus-square', 'info', 'info-circle', 'exclamation', 'exclamation-circle', 'close', 'close-circle', 'close-square', 'check', 'check-circle', 'check-square', 'clock-circle', 'warning', 'issues-close', 'stop']
|
||||
},
|
||||
{
|
||||
key: 'editor',
|
||||
title: '编辑类图标',
|
||||
icons: ['edit', 'form', 'copy', 'scissor', 'delete', 'snippets', 'diff', 'highlight', 'align-center', 'align-left', 'align-right', 'bg-colors', 'bold', 'italic', 'underline', 'strikethrough', 'redo', 'undo', 'zoom-in', 'zoom-out', 'font-colors', 'font-size', 'line-height', 'colum-height', 'dash', 'small-dash', 'sort-ascending', 'sort-descending', 'drag', 'ordered-list', 'radius-setting']
|
||||
},
|
||||
{
|
||||
key: 'data',
|
||||
title: '数据类图标',
|
||||
icons: ['area-chart', 'pie-chart', 'bar-chart', 'dot-chart', 'line-chart', 'radar-chart', 'heat-map', 'fall', 'rise', 'stock', 'box-plot', 'fund', 'sliders']
|
||||
},
|
||||
{
|
||||
key: 'brand_logo',
|
||||
title: '网站通用图标',
|
||||
icons: ['lock', 'unlock', 'bars', 'book', 'calendar', 'cloud', 'cloud-download', 'code', 'copy', 'credit-card', 'delete', 'desktop', 'download', 'ellipsis', 'file', 'file-text', 'file-unknown', 'file-pdf', 'file-word', 'file-excel', 'file-jpg', 'file-ppt', 'file-markdown', 'file-add', 'folder', 'folder-open', 'folder-add', 'hdd', 'frown', 'meh', 'smile', 'inbox', 'laptop', 'appstore', 'link', 'mail', 'mobile', 'notification', 'paper-clip', 'picture', 'poweroff', 'reload', 'search', 'setting', 'share-alt', 'shopping-cart', 'tablet', 'tag', 'tags', 'to-top', 'upload', 'user', 'video-camera', 'home', 'loading', 'loading-3-quarters', 'cloud-upload', 'star', 'heart', 'environment', 'eye', 'camera', 'save', 'team', 'solution', 'phone', 'filter', 'exception', 'export', 'customer-service', 'qrcode', 'scan', 'like', 'dislike', 'message', 'pay-circle', 'calculator', 'pushpin', 'bulb', 'select', 'switcher', 'rocket', 'bell', 'disconnect', 'database', 'compass', 'barcode', 'hourglass', 'key', 'flag', 'layout', 'printer', 'sound', 'usb', 'skin', 'tool', 'sync', 'wifi', 'car', 'schedule', 'user-add', 'user-delete', 'usergroup-add', 'usergroup-delete', 'man', 'woman', 'shop', 'gift', 'idcard', 'medicine-box', 'red-envelope', 'coffee', 'copyright', 'trademark', 'safety', 'wallet', 'bank', 'trophy', 'contacts', 'global', 'shake', 'api', 'fork', 'dashboard', 'table', 'profile', 'alert', 'audit', 'branches', 'build', 'border', 'crown', 'experiment', 'fire', 'money-collect', 'property-safety', 'read', 'reconciliation', 'rest', 'security-scan', 'insurance', 'interation', 'safety-certificate', 'project', 'thunderbolt', 'block', 'cluster', 'deployment-unit', 'dollar', 'euro', 'pound', 'file-done', 'file-exclamation', 'file-protect', 'file-search', 'file-sync', 'gateway', 'gold', 'robot', 'shopping']
|
||||
},
|
||||
{
|
||||
key: 'application',
|
||||
title: '品牌和标识',
|
||||
icons: ['android', 'apple', 'windows', 'ie', 'chrome', 'github', 'aliwangwang', 'dingtalk', 'weibo-square', 'weibo-circle', 'taobao-circle', 'html5', 'weibo', 'twitter', 'wechat', 'youtube', 'alipay-circle', 'taobao', 'skype', 'qq', 'medium-workmark', 'gitlab', 'medium', 'linkedin', 'google-plus', 'dropbox', 'facebook', 'codepen', 'code-sandbox', 'amazon', 'google', 'codepen-circle', 'alipay', 'ant-design', 'aliyun', 'zhihu', 'slack', 'slack-square', 'behance', 'behance-square', 'dribbble', 'dribbble-square', 'instagram', 'yuque', 'alibaba', 'yahoo']
|
||||
}
|
||||
]
|
||||
2
hotgo-web/src/components/IconSelector/index.js
Normal file
2
hotgo-web/src/components/IconSelector/index.js
Normal file
@@ -0,0 +1,2 @@
|
||||
import IconSelector from './IconSelector'
|
||||
export default IconSelector
|
||||
Reference in New Issue
Block a user