|
@@ -1,26 +1,33 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view
|
|
<view
|
|
|
- :style="styles"
|
|
|
|
|
|
|
+ :style="!showMax ? styles : maxStyles"
|
|
|
:class="classes"
|
|
:class="classes"
|
|
|
@click="activeAvatar(e)"
|
|
@click="activeAvatar(e)"
|
|
|
ref="avatarRef"
|
|
ref="avatarRef"
|
|
|
- v-if="!avatarGroup?.props?.maxCount || state.index <= avatarGroup?.props?.maxCount"
|
|
|
|
|
|
|
+ v-if="showMax || !avatarGroup?.props?.maxCount || index <= avatarGroup?.props?.maxCount"
|
|
|
>
|
|
>
|
|
|
- <template v-if="url">
|
|
|
|
|
- <img :src="url" :alt="alt" @error="onError" />
|
|
|
|
|
|
|
+ <template v-if="!avatarGroup?.props?.maxCount || index <= avatarGroup?.props?.maxCount">
|
|
|
|
|
+ <template v-if="url">
|
|
|
|
|
+ <img :src="url" :alt="alt" @error="onError" />
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <template v-else-if="icon">
|
|
|
|
|
+ <nut-icon class="icon" :name="iconStyles"></nut-icon>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <view class="text" v-if="isShowText">
|
|
|
|
|
+ <slot></slot>
|
|
|
|
|
+ </view>
|
|
|
</template>
|
|
</template>
|
|
|
- <template v-else-if="icon">
|
|
|
|
|
- <nut-icon class="icon" :name="iconStyles"></nut-icon>
|
|
|
|
|
|
|
+ <!-- 折叠头像 -->
|
|
|
|
|
+ <template v-if="showMax">
|
|
|
|
|
+ <view class="text">
|
|
|
|
|
+ {{
|
|
|
|
|
+ avatarGroup?.props?.maxContent
|
|
|
|
|
+ ? avatarGroup?.props?.maxContent
|
|
|
|
|
+ : `+ ${maxIndex - avatarGroup?.props?.maxCount}`
|
|
|
|
|
+ }}
|
|
|
|
|
+ </view>
|
|
|
</template>
|
|
</template>
|
|
|
- <view class="text" v-if="isShowText">
|
|
|
|
|
- <slot></slot>
|
|
|
|
|
- </view>
|
|
|
|
|
</view>
|
|
</view>
|
|
|
- <template v-if="avatarGroup?.props?.maxCount && state.showMax">
|
|
|
|
|
- <view :style="maxStyles" :class="classes" @click="activeMax(e)">
|
|
|
|
|
- <slot v-if="$slots.maxContent" name="maxContent"></slot>
|
|
|
|
|
- </view>
|
|
|
|
|
- </template>
|
|
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
import { toRefs, onMounted, computed, inject, reactive, ref } from 'vue';
|
|
import { toRefs, onMounted, computed, inject, reactive, ref } from 'vue';
|
|
@@ -57,7 +64,7 @@ export default create({
|
|
|
default: ''
|
|
default: ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- emits: ['active-avatar', 'active-max', 'onError'],
|
|
|
|
|
|
|
+ emits: ['active-avatar', 'onError'],
|
|
|
setup(props, { emit, slots }) {
|
|
setup(props, { emit, slots }) {
|
|
|
const { size, shape, bgColor, color, icon } = toRefs(props);
|
|
const { size, shape, bgColor, color, icon } = toRefs(props);
|
|
|
const sizeValue = ['large', 'normal', 'small'];
|
|
const sizeValue = ['large', 'normal', 'small'];
|
|
@@ -75,7 +82,7 @@ export default create({
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
const children = avatarGroup?.avatarGroupRef?.value?.children;
|
|
const children = avatarGroup?.avatarGroupRef?.value?.children;
|
|
|
if (children) {
|
|
if (children) {
|
|
|
- console.log('parent', avatarGroup);
|
|
|
|
|
|
|
+ // console.log('parent', avatarGroup);
|
|
|
avatarLength(children);
|
|
avatarLength(children);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -118,10 +125,6 @@ export default create({
|
|
|
const avatarLength = (children: any) => {
|
|
const avatarLength = (children: any) => {
|
|
|
state.maxIndex = children.length;
|
|
state.maxIndex = children.length;
|
|
|
for (let i = 0; i < children.length; i++) {
|
|
for (let i = 0; i < children.length; i++) {
|
|
|
- // if (children[i] && children[i].classList && children[i].classList[0] == 'nut-avatar') {
|
|
|
|
|
- // children[i].setAttribute('data-index', i + 1);
|
|
|
|
|
-
|
|
|
|
|
- // }
|
|
|
|
|
children[i].setAttribute('data-index', i + 1);
|
|
children[i].setAttribute('data-index', i + 1);
|
|
|
}
|
|
}
|
|
|
// state.index = avatarRef?.value?.dataset?.index;
|
|
// state.index = avatarRef?.value?.dataset?.index;
|
|
@@ -135,10 +138,6 @@ export default create({
|
|
|
emit('active-avatar', event);
|
|
emit('active-avatar', event);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const activeMax = (event: any) => {
|
|
|
|
|
- emit('active-max', event);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
const onError = (event: any) => {
|
|
const onError = (event: any) => {
|
|
|
emit('onError', event);
|
|
emit('onError', event);
|
|
|
};
|
|
};
|
|
@@ -154,8 +153,7 @@ export default create({
|
|
|
avatarGroup,
|
|
avatarGroup,
|
|
|
visible,
|
|
visible,
|
|
|
avatarRef,
|
|
avatarRef,
|
|
|
- state,
|
|
|
|
|
- activeMax
|
|
|
|
|
|
|
+ ...toRefs(state)
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|