[新增] avatar 头像组件
This commit is contained in:
		
							parent
							
								
									899604b2d0
								
							
						
					
					
						commit
						ddfca5b3c7
					
				
							
								
								
									
										77
									
								
								docs/docs/zh-CN/components/avatar.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								docs/docs/zh-CN/components/avatar.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,77 @@
 | 
			
		||||
::: demo
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
  <lay-avatar :src="avatar"></lay-avatar>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { ref } from 'vue'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  setup() {
 | 
			
		||||
 | 
			
		||||
    const avatar = "https://portrait.gitee.com/uploads/avatars/user/2813/8441097_shaynas_1610801433.png"
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        avatar
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
:::
 | 
			
		||||
 | 
			
		||||
::: demo
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
  <lay-avatar :src="avatar" radius></lay-avatar>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { ref } from 'vue'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
 | 
			
		||||
    setup() {
 | 
			
		||||
 | 
			
		||||
        const avatar = "https://portrait.gitee.com/uploads/avatars/user/2813/8441097_shaynas_1610801433.png"
 | 
			
		||||
        
 | 
			
		||||
        return {
 | 
			
		||||
            avatar
 | 
			
		||||
        }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
:::
 | 
			
		||||
 | 
			
		||||
::: demo
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
  <lay-avatar :src="avatar" size="xs"></lay-avatar> 
 | 
			
		||||
  <lay-avatar :src="avatar" size="sm"></lay-avatar>
 | 
			
		||||
  <lay-avatar :src="avatar"></lay-avatar>
 | 
			
		||||
  <lay-avatar :src="avatar" size="lg"></lay-avatar>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import { ref } from 'vue'
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
    setup() {
 | 
			
		||||
 | 
			
		||||
        const avatar = "https://portrait.gitee.com/uploads/avatars/user/2813/8441097_shaynas_1610801433.png"
 | 
			
		||||
 | 
			
		||||
        return {
 | 
			
		||||
            avatar
 | 
			
		||||
        }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
:::
 | 
			
		||||
 | 
			
		||||
|  |  |  |
 | 
			
		||||
|--|--|--|
 | 
			
		||||
| src | 图源 | -- |
 | 
			
		||||
| size | 尺寸 | `xs` `sm` `lg`|
 | 
			
		||||
| radius | 圆形 | `true` `false`|
 | 
			
		||||
@ -81,6 +81,7 @@ export default {
 | 
			
		||||
      { id: 20, title: '颜色',subTitle:"color" ,path: '/zh-CN/components/color' },
 | 
			
		||||
      { id: 21, title: '手风琴',subTitle:"collapse" ,path: '/zh-CN/components/collapse' },
 | 
			
		||||
      { id: 22, title: '表格',subTitle:"table" ,path: '/zh-CN/components/table' },
 | 
			
		||||
      { id: 23, title: '头像',subTitle:"avatar" ,path: '/zh-CN/components/avatar' },
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    const selected = ref(1)
 | 
			
		||||
 | 
			
		||||
@ -116,6 +116,11 @@ const zhCN = [
 | 
			
		||||
        path: '/zh-CN/components/table',
 | 
			
		||||
        component: () => import('../../docs/zh-CN/components/table.md'),
 | 
			
		||||
        meta: { title: '表格' },
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        path: '/zh-CN/components/avatar',
 | 
			
		||||
        component: () => import('../../docs/zh-CN/components/avatar.md'),
 | 
			
		||||
        meta: { title: '头像' },
 | 
			
		||||
      }
 | 
			
		||||
    ],
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
@ -175,3 +175,7 @@ table th {
 | 
			
		||||
table td {
 | 
			
		||||
  white-space: nowrap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.source .layui-avatar {
 | 
			
		||||
  margin-right: 30px;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										42
									
								
								src/css/layui-vue.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/css/layui-vue.css
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
			
		||||
.layui-avatar {
 | 
			
		||||
    box-sizing: border-box;
 | 
			
		||||
    margin: 0;
 | 
			
		||||
    padding: 0;
 | 
			
		||||
    color: #000000d9;
 | 
			
		||||
    font-size: 14px;
 | 
			
		||||
    font-variant: tabular-nums;
 | 
			
		||||
    line-height: 1.5715;
 | 
			
		||||
    list-style: none;
 | 
			
		||||
    font-feature-settings: tnum;
 | 
			
		||||
    position: relative;
 | 
			
		||||
    display: inline-block;
 | 
			
		||||
    overflow: hidden;
 | 
			
		||||
    color: #fff;
 | 
			
		||||
    white-space: nowrap;
 | 
			
		||||
    text-align: center;
 | 
			
		||||
    vertical-align: middle;
 | 
			
		||||
    background: #ccc;
 | 
			
		||||
    width: 32px;
 | 
			
		||||
    height: 32px;
 | 
			
		||||
    line-height: 32px;
 | 
			
		||||
    border-radius: 4px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.layui-avatar.layui-avatar-radius {
 | 
			
		||||
    border-radius: 50%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.layui-avatar.layui-avatar-sm {
 | 
			
		||||
    height: 30px;
 | 
			
		||||
    width: 30px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.layui-avatar.layui-avatar-lg {
 | 
			
		||||
    height: 36px;
 | 
			
		||||
    width: 36px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.layui-avatar.layui-avatar-xs {
 | 
			
		||||
    height: 28px;
 | 
			
		||||
    width: 28px;
 | 
			
		||||
}
 | 
			
		||||
@ -2,6 +2,8 @@ import type { App } from 'vue'
 | 
			
		||||
import type { IDefineComponent, InstallOptions } from './module/type/index'
 | 
			
		||||
 | 
			
		||||
import "./css/layui.css"
 | 
			
		||||
import "./css/layui-vue.css"
 | 
			
		||||
import LayAvatar from './module/avatar/index'
 | 
			
		||||
import LayRadio from './module/radio/index'
 | 
			
		||||
import LayButton from './module/button/index'
 | 
			
		||||
import LayButtonContainer from './module/buttonContainer/index'
 | 
			
		||||
@ -71,7 +73,8 @@ const components: Record<string, IDefineComponent> = {
 | 
			
		||||
  LayCheckbox,
 | 
			
		||||
  LayForm,
 | 
			
		||||
  LayBreadcrumb,
 | 
			
		||||
  LayBreadcrumbItem
 | 
			
		||||
  LayBreadcrumbItem,
 | 
			
		||||
  LayAvatar
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const install = (app: App, options?: InstallOptions): void => {
 | 
			
		||||
@ -119,6 +122,7 @@ export {
 | 
			
		||||
  LayForm,
 | 
			
		||||
  LayBreadcrumb,
 | 
			
		||||
  LayBreadcrumbItem,
 | 
			
		||||
  LayAvatar,
 | 
			
		||||
  install,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								src/module/avatar/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								src/module/avatar/index.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
import type { App } from 'vue'
 | 
			
		||||
import Component from './index.vue'
 | 
			
		||||
import type { IDefineComponent } from '../type/index'
 | 
			
		||||
 | 
			
		||||
Component.install = (app: App) => {
 | 
			
		||||
  app.component(Component.name || 'LayAvatar', Component)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default Component as IDefineComponent
 | 
			
		||||
							
								
								
									
										14
									
								
								src/module/avatar/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/module/avatar/index.vue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
<template>
 | 
			
		||||
    <img :src="src" class="layui-avatar" :class="[radius ? 'layui-avatar-radius':'', size ? 'layui-avatar-' + size: '']"/>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup name="LayAvatar" lang="ts">
 | 
			
		||||
import { defineProps } from 'vue'
 | 
			
		||||
 | 
			
		||||
const props =
 | 
			
		||||
  defineProps<{
 | 
			
		||||
    src?: boolean
 | 
			
		||||
    radius?: boolean
 | 
			
		||||
    size?: string
 | 
			
		||||
  }>()
 | 
			
		||||
</script>
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
<template>
 | 
			
		||||
    <span :class="classList" :style="styleList">
 | 
			
		||||
        <slot v-if="type != 'dot'"></slot>
 | 
			
		||||
    </span>
 | 
			
		||||
  <span :class="classList" :style="styleList">
 | 
			
		||||
    <slot v-if="type != 'dot'"></slot>
 | 
			
		||||
  </span>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup name="LayBadge" lang="ts">
 | 
			
		||||
@ -9,18 +9,19 @@ import { defineProps } from 'vue'
 | 
			
		||||
 | 
			
		||||
const props =
 | 
			
		||||
  defineProps<{
 | 
			
		||||
   	type?: string
 | 
			
		||||
	  theme?: string
 | 
			
		||||
	  color?: string
 | 
			
		||||
    type?: string
 | 
			
		||||
    theme?: string
 | 
			
		||||
    color?: string
 | 
			
		||||
  }>()
 | 
			
		||||
 | 
			
		||||
const classList = [{
 | 
			
		||||
				    'layui-badge': !props.type,
 | 
			
		||||
                    'layui-badge-dot': props.type == 'dot',
 | 
			
		||||
                    'layui-badge-rim': props.type == 'rim',
 | 
			
		||||
                },
 | 
			
		||||
				'layui-bg-' + props.theme];
 | 
			
		||||
 | 
			
		||||
const styleList = props.color ? 'background-color: ' + props.color : '';
 | 
			
		||||
const classList = [
 | 
			
		||||
  {
 | 
			
		||||
    'layui-badge': !props.type,
 | 
			
		||||
    'layui-badge-dot': props.type == 'dot',
 | 
			
		||||
    'layui-badge-rim': props.type == 'rim',
 | 
			
		||||
  },
 | 
			
		||||
  'layui-bg-' + props.theme,
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
const styleList = props.color ? 'background-color: ' + props.color : ''
 | 
			
		||||
</script>
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user