这一版本优化了很多

This commit is contained in:
王利强
2026-06-03 10:16:37 +08:00
parent 8046316216
commit 2af9f1fd59
954 changed files with 58194 additions and 1609 deletions

View File

@@ -0,0 +1,17 @@
@import '../common/abstracts/variable';
@import '../common/abstracts/mixin';
@import '../wd-avatar/common';
@include b(avatar-group) {
display: inline-flex;
align-items: center;
gap: 0;
@include e(item) {
// 样式已在 common.scss 中定义
}
@include edeep(collapse) {
font-size: $-avatar-group-collapse-font-size;
}
}

View File

@@ -0,0 +1,63 @@
/*
* @Author: weisheng
* @Date: 2025-12-30
* @LastEditTime: 2025-12-30
* @LastEditors: weisheng
* @Description: AvatarGroup 头像组类型定义
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-avatar-group/types.ts
* 记得注释
*/
import type { ExtractPropTypes, PropType } from 'vue'
import type { InjectionKey } from 'vue'
import { baseProps, makeStringProp, makeNumericProp } from '../common/props'
import type { AvatarShape, AvatarSize } from '../wd-avatar/types'
export type AvatarGroupCascadingValue = 'left-up' | 'right-up'
export type AvatarGroupProvide = {
props: AvatarGroupProps
}
export const AVATAR_GROUP_KEY: InjectionKey<AvatarGroupProvide> = Symbol('wd-avatar-group')
export const avatarGroupProps = {
...baseProps,
/**
* 最多显示的头像数量
* 类型: string | number
* 默认值: undefined
*/
maxCount: makeNumericProp(undefined),
/**
* 头像层叠方向
* 可选值: left-up(左侧叠层) / right-up(右侧叠层)
* 类型: string
* 默认值: 'left-up'
*/
cascading: makeStringProp<AvatarGroupCascadingValue>('left-up'),
/**
* 统一设置组内所有头像的形状
* 类型: string
* 默认值: undefined
*/
shape: String as PropType<AvatarShape>,
/**
* 统一设置组内所有头像的尺寸
* 类型: string | number
* 默认值: undefined
*/
size: [String, Number] as PropType<number | string | AvatarSize>,
/**
* 超出最大数量时折叠头像显示的内容
* 类型: string
* 默认值: undefined
*/
collapseAvatar: makeStringProp('')
}
export type AvatarGroupProps = ExtractPropTypes<typeof avatarGroupProps>

View File

@@ -0,0 +1,98 @@
<!--
* @Author: North
* @Date: 2026-01-01
* @LastEditTime: 2026-01-01
* @LastEditors: North
* @Description: AvatarGroup 头像组组件用于将多个头像组合展示
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/components/wd-avatar-group/wd-avatar-group.vue
-->
<template>
<view :class="rootClass" :style="customStyle">
<slot></slot>
<!-- 折叠头像 -->
<view v-if="showCollapse" class="wd-avatar-group__item wd-avatar-group__collapse" :style="collapseStyle">
<wd-avatar _internal :text="collapseText" :shape="props.shape" :size="props.size" bg-color="#ebedf0" color="#969799" />
</view>
</view>
</template>
<script lang="ts">
export default {
name: 'wd-avatar-group',
options: {
addGlobalClass: true,
virtualHost: true,
styleIsolation: 'shared'
}
}
</script>
<script lang="ts" setup>
import { computed, type CSSProperties, type ComponentPublicInstance } from 'vue'
import wdAvatar from '../wd-avatar/wd-avatar.vue'
import { avatarGroupProps, AVATAR_GROUP_KEY, type AvatarGroupProvide } from './types'
import { useChildren } from '../composables/useChildren'
const props = defineProps(avatarGroupProps)
const { children, linkChildren } = useChildren<ComponentPublicInstance, AvatarGroupProvide>(AVATAR_GROUP_KEY)
linkChildren({ props })
/**
* 根节点类名
*/
const rootClass = computed(() => {
return `wd-avatar-group wd-avatar-group--${props.cascading} ${props.customClass}`
})
const maxCountValue = computed(() => {
if (!props.maxCount) {
return 0
}
const count = typeof props.maxCount === 'number' ? props.maxCount : parseInt(props.maxCount, 10)
return isNaN(count) || count <= 0 ? 0 : count
})
/**
* 是否显示折叠头像
*/
const showCollapse = computed(() => {
return maxCountValue.value > 0 && children.length > maxCountValue.value
})
/**
* 剩余未显示的数量
*/
const restCount = computed(() => {
if (maxCountValue.value <= 0) {
return 0
}
return Math.max(0, children.length - maxCountValue.value)
})
/**
* 折叠头像文本
*/
const collapseText = computed(() => {
return props.collapseAvatar || `+${restCount.value}`
})
/**
* 折叠头像样式
*/
const collapseStyle = computed(() => {
const style: CSSProperties = {}
if (props.cascading === 'left-up') {
const count = maxCountValue.value > 0 ? maxCountValue.value : children.length
style.zIndex = count + 1
} else {
style.zIndex = 0
}
return style
})
</script>
<style lang="scss" scoped>
@import './index.scss';
</style>