mirror of
				https://github.com/soybeanjs/soybean-admin.git
				synced 2025-11-04 15:53:43 +08:00 
			
		
		
		
	Merge pull request #51 from Lsq128/main
feat(components): svgIcon,添加type,调整size方案
This commit is contained in:
		@@ -1,43 +1,31 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <svg :style="svgStyle" class="svg-icon" aria-hidden="true">
 | 
			
		||||
  <svg class="svg-icon" aria-hidden="true">
 | 
			
		||||
    <use :xlink:href="symbolId" :fill="fill" />
 | 
			
		||||
  </svg>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { computed } from 'vue';
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  prefix: {
 | 
			
		||||
    type: String,
 | 
			
		||||
    default: 'icon'
 | 
			
		||||
  },
 | 
			
		||||
  name: {
 | 
			
		||||
    type: String,
 | 
			
		||||
    required: true
 | 
			
		||||
  },
 | 
			
		||||
  size: {
 | 
			
		||||
    type: [String, Number],
 | 
			
		||||
    default: 30
 | 
			
		||||
  },
 | 
			
		||||
  color: {
 | 
			
		||||
    type: String,
 | 
			
		||||
    default: ''
 | 
			
		||||
interface Props {
 | 
			
		||||
  /** icon前缀 */
 | 
			
		||||
  prefix?: string;
 | 
			
		||||
  /** icon 名称 */
 | 
			
		||||
  name: string;
 | 
			
		||||
  /** 填充颜色 */
 | 
			
		||||
  color?: string;
 | 
			
		||||
}
 | 
			
		||||
});
 | 
			
		||||
const svgStyle = computed(() => {
 | 
			
		||||
  const { size } = props;
 | 
			
		||||
  let s = `${size}`;
 | 
			
		||||
  s = `${s.replace('px', '')}px`;
 | 
			
		||||
  return {
 | 
			
		||||
    width: s,
 | 
			
		||||
    height: s
 | 
			
		||||
  };
 | 
			
		||||
const props = withDefaults(defineProps<Props>(), {
 | 
			
		||||
  prefix: 'icon',
 | 
			
		||||
  name: '',
 | 
			
		||||
  color: ''
 | 
			
		||||
});
 | 
			
		||||
const fill = computed(() => props.color || 'currentColor');
 | 
			
		||||
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
 | 
			
		||||
</script>
 | 
			
		||||
<style scoped>
 | 
			
		||||
.svg-icon {
 | 
			
		||||
  width: 1em;
 | 
			
		||||
  height: 1em;
 | 
			
		||||
  vertical-align: -0.15em;
 | 
			
		||||
  overflow: hidden;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +0,0 @@
 | 
			
		||||
import type { App } from 'vue';
 | 
			
		||||
import { SvgIcon } from '@/components';
 | 
			
		||||
 | 
			
		||||
/** 注册全局svg-icon组件 */
 | 
			
		||||
export default function setupNaiveUI(app: App) {
 | 
			
		||||
  app.component('SvgIcon', SvgIcon);
 | 
			
		||||
}
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
      <div class="grid grid-cols-10">
 | 
			
		||||
        <template v-for="item in svgIcons" :key="item">
 | 
			
		||||
          <div class="mt-5px flex-x-center">
 | 
			
		||||
            <svg-icon :name="item" />
 | 
			
		||||
            <svg-icon :name="item" class="text-30px" />
 | 
			
		||||
          </div>
 | 
			
		||||
        </template>
 | 
			
		||||
      </div>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user