| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <template>
- <view
- :class="rootClass"
- :style="barStyle">
- <view :class="userInfoSectionClass">
- <template v-if="!scene">
- <image
- v-if="showType === 2"
- :class="backIconClass"
- src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/userapp/images/return3.png"
- @click="onBack" />
- <image
- v-if="showType === 1"
- :class="backIconClassHorizontal"
- src="/static/images/live/back.png"
- @click="onBack" />
- </template>
- <view :class="avatarContainerClass">
- <u-avatar
- v-if="variant === 'outside'"
- :src="avatarUrl"
- :size="32" />
- <view
- v-else
- class="cover-avatar-round cover-avatar-round--host">
- <image
- class="cover-avatar-round__img"
- :src="avatarUrl" />
- </view>
- <view :class="userNameClass">{{ displayName }}</view>
- </view>
- </view>
- <view
- v-if="Array.isArray(viewers)"
- :class="viewersSectionClass">
- <view :class="viewersInnerClass">
- <view
- v-for="(item, index) in (viewers || [])"
- v-if="item"
- :key="viewerKeyPrefix + index"
- :class="viewerAvatarClass"
- :style="variant === 'overlay' ? viewerAvatarClipStyle : null">
- <image
- :class="viewerImgClass"
- :src="item" />
- </view>
- <view :class="viewerCountClass">{{ watchCount || 0 }}</view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'LiveTopInfoBar',
- props: {
- variant: {
- type: String,
- default: 'overlay'
- },
- showType: {
- type: Number,
- default: 2
- },
- liveName: {
- type: String,
- default: ''
- },
- avatarUrl: {
- type: String,
- default: ''
- },
- viewers: {
- type: Array,
- default: () => []
- },
- watchCount: {
- type: [String, Number],
- default: 0
- },
- scene: {
- type: Boolean,
- default: false
- },
- paddingTop: {
- type: String,
- default: ''
- },
- viewerKeyPrefix: {
- type: String,
- default: 'ltib-'
- }
- },
- computed: {
- displayName() {
- const name = this.liveName || '未命名';
- return this.truncateString(name, 8);
- },
- themeClass() {
- return this.showType === 1 ?
- 'cover-top-info-bar--light' :
- 'cover-top-info-bar--dark';
- },
- rootClass() {
- if (this.variant === 'outside') {
- return ['top-info-bar-inner'];
- }
- return ['cover-top-info-bar', this.themeClass];
- },
- barStyle() {
- if (this.variant !== 'overlay') return {};
- const top = this.paddingTop || '0px';
- return {
- paddingTop: top,
- paddingLeft: '24rpx',
- paddingRight: '24rpx',
- boxSizing: 'border-box'
- };
- },
- userInfoSectionClass() {
- return this.variant === 'outside' ?
- 'user-info-section' :
- 'cover-user-info-section';
- },
- backIconClass() {
- return this.variant === 'outside' ?
- 'back-icon mr4' :
- 'cover-back-icon';
- },
- backIconClassHorizontal() {
- return this.variant === 'outside' ?
- 'w48 h48 mr4' :
- 'cover-back-icon-sm';
- },
- avatarContainerClass() {
- return this.variant === 'outside' ?
- 'user-avatar-container' :
- 'cover-user-avatar-container';
- },
- userNameClass() {
- return this.variant === 'outside' ?
- 'user-name ml10 mr6' :
- 'cover-user-name';
- },
- viewersSectionClass() {
- return this.variant === 'outside' ?
- 'viewers-section' :
- 'cover-viewers-section';
- },
- viewersInnerClass() {
- return this.variant === 'outside' ?
- 'viewers-inner' :
- 'cover-viewers-inner';
- },
- viewerAvatarClass() {
- if (this.variant === 'outside') {
- return 'viewer-avatar mr4';
- }
- return 'cover-avatar-round cover-avatar-round--sm';
- },
- viewerImgClass() {
- return this.variant === 'outside' ?
- '' :
- 'cover-avatar-round__img';
- },
- viewerCountClass() {
- return this.variant === 'outside' ?
- 'viewer-count' :
- 'cover-viewer-count';
- },
- viewerAvatarClipStyle() {
- return {
- width: '52rpx',
- height: '52rpx',
- borderRadius: '26rpx',
- overflow: 'hidden',
- marginRight: '8rpx'
- };
- }
- },
- methods: {
- onBack() {
- this.$emit('back');
- },
- truncateString(str, maxLength) {
- if (typeof str !== 'string' || str.length <= maxLength) {
- return str;
- }
- return str.slice(0, maxLength) + '...';
- }
- }
- };
- </script>
- <style scoped lang="scss">
- /* 叠加在视频上 */
- .cover-top-info-bar {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: center;
- z-index: 99999;
- box-sizing: border-box;
- }
- .cover-top-info-bar--dark .cover-user-avatar-container,
- .cover-top-info-bar--dark .cover-viewer-count {
- background-color: rgba(0, 0, 0, 0.3);
- }
- .cover-top-info-bar--dark .cover-user-name {
- color: #ffffff;
- }
- .cover-top-info-bar--light .cover-user-avatar-container,
- .cover-top-info-bar--light .cover-viewer-count {
- background-color: #ffffff;
- }
- .cover-top-info-bar--light .cover-user-name {
- color: #333333;
- }
- .cover-user-info-section {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .cover-back-icon {
- width: 60rpx;
- height: 64rpx;
- margin-right: 8rpx;
- }
- .cover-back-icon-sm {
- width: 42rpx;
- height: 42rpx;
- margin-right: 8rpx;
- }
- .cover-user-avatar-container {
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 6rpx 16rpx 6rpx 6rpx;
- border-radius: 32rpx;
- }
- .cover-avatar-round {
- overflow: hidden;
- margin-right: 10rpx;
- }
- .cover-avatar-round--host {
- width: 32px;
- height: 32px;
- border-radius: 50px;
- }
- .cover-avatar-round--sm {
- width: 52rpx;
- height: 52rpx;
- margin-right: 8rpx;
- }
- .cover-avatar-round__img {
- width: 100%;
- height: 100%;
- display: block;
- }
- .cover-user-name {
- font-size: 28rpx;
- line-height: 64rpx;
- max-width: 240rpx;
- overflow: hidden;
- white-space: nowrap;
- }
- .cover-viewers-section {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .cover-viewers-inner {
- display: flex;
- flex-direction: row;
- align-items: center;
- }
- .cover-viewer-count {
- min-width: 80rpx;
- height: 52rpx;
- border-radius: 26rpx;
- font-size: 30rpx;
- text-align: center;
- line-height: 52rpx;
- padding: 0 8rpx;
- }
- /* 视频区外(横屏或降级) */
- .top-info-bar-inner {
- width: 100%;
- display: flex;
- justify-content: space-between;
- flex-direction: row;
- align-items: center;
- }
- .user-info-section {
- display: flex;
- align-items: center;
- .back-icon {
- width: 60rpx;
- height: 64rpx;
- }
- .user-avatar-container {
- padding: 6rpx 8rpx;
- height: 64rpx;
- background: var(--normal-bg);
- border-radius: 32rpx;
- display: flex;
- align-items: center;
- .user-name {
- color: var(--text-color);
- }
- }
- }
- .viewers-section {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- }
- .viewers-inner {
- display: flex;
- align-items: center;
- }
- .viewer-avatar {
- width: 52rpx;
- height: 52rpx;
- border-radius: 26rpx;
- overflow: hidden;
- image{
- width: 100%;
- height: 100%;
- }
- }
- .viewer-count {
- width: 80rpx;
- height: 52rpx;
- background: var(--normal-bg);
- border-radius: 26rpx;
- font-size: 30rpx;
- color: var(--text-color);
- text-align: center;
- line-height: 52rpx;
- }
- </style>
|