mirror of
				https://github.com/soybeanjs/soybean-admin.git
				synced 2025-11-04 07:43:42 +08:00 
			
		
		
		
	feat(projects): 增加Icon选择器组件
This commit is contained in:
		
							
								
								
									
										75
									
								
								src/components/common/IconSelect/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								src/components/common/IconSelect/index.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,75 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <n-popover placement="bottom-end" trigger="click">
 | 
			
		||||
    <template #trigger>
 | 
			
		||||
      <n-input v-model:value="modelValue" readonly placeholder="点击选择图标">
 | 
			
		||||
        <template #suffix>
 | 
			
		||||
          <Icon :icon="modelValue ? modelValue : 'mdi:apps'" class="text-30px p-5px" />
 | 
			
		||||
        </template>
 | 
			
		||||
      </n-input>
 | 
			
		||||
    </template>
 | 
			
		||||
    <template #header>
 | 
			
		||||
      <n-input v-model:value="searchValue" placeholder="搜索图标"></n-input>
 | 
			
		||||
    </template>
 | 
			
		||||
    <div v-if="iconsList.length > 0" class="grid grid-cols-9 h-auto overflow-auto">
 | 
			
		||||
      <template v-for="iconItem in iconsList" :key="iconItem">
 | 
			
		||||
        <Icon
 | 
			
		||||
          :icon="iconItem"
 | 
			
		||||
          class="border-1px border-[#d9d9d9] text-30px m-2px p-5px"
 | 
			
		||||
          :style="{ 'border-color': modelValue === iconItem ? theme.themeColor : '' }"
 | 
			
		||||
          @click="handleChange(iconItem)"
 | 
			
		||||
        />
 | 
			
		||||
      </template>
 | 
			
		||||
    </div>
 | 
			
		||||
    <n-empty v-else class="w-306px" description="你什么也找不到" />
 | 
			
		||||
  </n-popover>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script lang="ts" setup>
 | 
			
		||||
import { ref, computed } from 'vue';
 | 
			
		||||
import { NPopover, NInput, NEmpty } from 'naive-ui';
 | 
			
		||||
import { Icon } from '@iconify/vue';
 | 
			
		||||
import { useThemeStore } from '@/store';
 | 
			
		||||
 | 
			
		||||
interface Props {
 | 
			
		||||
  /** 绑定的图标 */
 | 
			
		||||
  value: string;
 | 
			
		||||
  /** 图标列表 */
 | 
			
		||||
  icons?: string[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface Emits {
 | 
			
		||||
  (e: 'update:value', val: string): void;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const props = withDefaults(defineProps<Props>(), {
 | 
			
		||||
  icons: () => []
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const emit = defineEmits<Emits>();
 | 
			
		||||
 | 
			
		||||
const theme = useThemeStore();
 | 
			
		||||
const searchValue = ref('');
 | 
			
		||||
 | 
			
		||||
const modelValue = computed({
 | 
			
		||||
  get() {
 | 
			
		||||
    return props.value;
 | 
			
		||||
  },
 | 
			
		||||
  set(val: string) {
 | 
			
		||||
    emit('update:value', val);
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const iconsList = computed(() => props.icons.filter(v => v.includes(searchValue.value)));
 | 
			
		||||
 | 
			
		||||
function handleChange(iconItem: string) {
 | 
			
		||||
  modelValue.value = iconItem;
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
<style lang="scss" scoped>
 | 
			
		||||
:deep(.n-input-wrapper) {
 | 
			
		||||
  padding-right: 0;
 | 
			
		||||
}
 | 
			
		||||
:deep(.n-input__suffix) {
 | 
			
		||||
  border: 1px solid #d9d9d9;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
@@ -4,5 +4,6 @@ import LoginBg from './LoginBg/index.vue';
 | 
			
		||||
import BannerSvg from './BannerSvg/index.vue';
 | 
			
		||||
import HoverContainer from './HoverContainer/index.vue';
 | 
			
		||||
import LoadingEmptyWrapper from './LoadingEmptyWrapper/index.vue';
 | 
			
		||||
import IconSelect from './IconSelect/index.vue';
 | 
			
		||||
 | 
			
		||||
export { NaiveProvider, SystemLogo, LoginBg, BannerSvg, HoverContainer, LoadingEmptyWrapper };
 | 
			
		||||
export { NaiveProvider, SystemLogo, LoginBg, BannerSvg, HoverContainer, LoadingEmptyWrapper, IconSelect };
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								src/views/plugin/icon/icons.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/views/plugin/icon/icons.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
export const icons = [
 | 
			
		||||
  'mdi:emoticon',
 | 
			
		||||
  'mdi:ab-testing',
 | 
			
		||||
  'ph:alarm',
 | 
			
		||||
  'ph:android-logo',
 | 
			
		||||
  'ph:align-bottom',
 | 
			
		||||
  'ph:archive-box-light',
 | 
			
		||||
  'uil:basketball',
 | 
			
		||||
  'uil:brightness-plus',
 | 
			
		||||
  'uil:capture',
 | 
			
		||||
  'mdi:apps-box',
 | 
			
		||||
  'mdi:alert',
 | 
			
		||||
  'mdi:airballoon',
 | 
			
		||||
  'mdi:airplane-edit',
 | 
			
		||||
  'mdi:alpha-f-box-outline',
 | 
			
		||||
  'mdi:arm-flex-outline',
 | 
			
		||||
  'ic:baseline-10mp',
 | 
			
		||||
  'ic:baseline-access-time',
 | 
			
		||||
  'ic:baseline-brightness-4',
 | 
			
		||||
  'ic:baseline-brightness-5',
 | 
			
		||||
  'ic:baseline-credit-card',
 | 
			
		||||
  'ic:baseline-filter-1',
 | 
			
		||||
  'ic:baseline-filter-2',
 | 
			
		||||
  'ic:baseline-filter-3',
 | 
			
		||||
  'ic:baseline-filter-4',
 | 
			
		||||
  'ic:baseline-filter-5',
 | 
			
		||||
  'ic:baseline-filter-6',
 | 
			
		||||
  'ic:baseline-filter-7',
 | 
			
		||||
  'ic:baseline-filter-8',
 | 
			
		||||
  'ic:baseline-filter-9',
 | 
			
		||||
  'ic:baseline-filter-9-plus'
 | 
			
		||||
];
 | 
			
		||||
@@ -1,11 +1,17 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <n-card title="Icon组件示例" class="shadow-sm rounded-16px">
 | 
			
		||||
      <div class="flex justify-around">
 | 
			
		||||
      <div class="grid grid-cols-10">
 | 
			
		||||
        <template v-for="item in icons" :key="item">
 | 
			
		||||
          <div class="mt-5px flex-x-center">
 | 
			
		||||
            <Icon :icon="item" class="text-30px" />
 | 
			
		||||
          </div>
 | 
			
		||||
        </template>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div class="mt-50px">
 | 
			
		||||
        <h1 class="mb-20px text-18px font-500">Icon图标选择器</h1>
 | 
			
		||||
        <icon-select v-model:value="selectVal" :icons="icons" />
 | 
			
		||||
      </div>
 | 
			
		||||
      <template #footer>
 | 
			
		||||
        <web-site-link label="iconify地址:" link="https://icones.js.org/" class="mt-10px" />
 | 
			
		||||
      </template>
 | 
			
		||||
@@ -14,20 +20,12 @@
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script lang="ts" setup>
 | 
			
		||||
import { ref } from 'vue';
 | 
			
		||||
import { NCard } from 'naive-ui';
 | 
			
		||||
import { Icon } from '@iconify/vue';
 | 
			
		||||
import { WebSiteLink } from '@/components';
 | 
			
		||||
import { IconSelect, WebSiteLink } from '@/components';
 | 
			
		||||
import { icons } from './icons';
 | 
			
		||||
 | 
			
		||||
const icons = [
 | 
			
		||||
  'mdi:emoticon',
 | 
			
		||||
  'mdi:ab-testing',
 | 
			
		||||
  'ph:alarm',
 | 
			
		||||
  'ph:android-logo',
 | 
			
		||||
  'ph:align-bottom',
 | 
			
		||||
  'ph:archive-box-light',
 | 
			
		||||
  'uil:basketball',
 | 
			
		||||
  'uil:brightness-plus',
 | 
			
		||||
  'uil:capture'
 | 
			
		||||
];
 | 
			
		||||
const selectVal = ref('');
 | 
			
		||||
</script>
 | 
			
		||||
<style scoped></style>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user