chore(视频号组件): 重构视频号组件,不单单是微信视频号
This commit is contained in:
190
components-diy/css/common-channel.scss
Normal file
190
components-diy/css/common-channel.scss
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
// 公共微信视频号样式
|
||||||
|
|
||||||
|
// CSS 变量
|
||||||
|
:root {
|
||||||
|
// 尺寸变量
|
||||||
|
--channel-play-btn-size: 80rpx;
|
||||||
|
--channel-play-btn-small-size: 60rpx;
|
||||||
|
--channel-play-btn-icon-size: 40rpx;
|
||||||
|
--channel-play-btn-icon-small-size: 30rpx;
|
||||||
|
--channel-avatar-size: 60rpx;
|
||||||
|
--channel-arrow-size: 24rpx;
|
||||||
|
--channel-border-radius: 12rpx;
|
||||||
|
--channel-stats-padding: 10rpx;
|
||||||
|
--channel-info-wrap-padding: 10rpx 0;
|
||||||
|
|
||||||
|
// 字体变量
|
||||||
|
--channel-name-font-size: 28rpx;
|
||||||
|
--channel-follow-font-size: 24rpx;
|
||||||
|
--video-title-font-size: 28rpx;
|
||||||
|
--video-title-small-font-size: 24rpx;
|
||||||
|
--video-stats-font-size: 24rpx;
|
||||||
|
--channel-stats-font-size: 20rpx;
|
||||||
|
|
||||||
|
// 颜色变量
|
||||||
|
--channel-name-color: #333;
|
||||||
|
--channel-follow-color: #07c160;
|
||||||
|
--video-title-color: #333;
|
||||||
|
--video-title-small-color: #666;
|
||||||
|
--video-stats-color: #999;
|
||||||
|
--channel-stats-color: #fff;
|
||||||
|
--channel-border-color: #f0f0f0;
|
||||||
|
--channel-play-btn-bg: rgba(0, 0, 0, 0.4);
|
||||||
|
--channel-stats-bg: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
|
||||||
|
|
||||||
|
// 间距变量
|
||||||
|
--channel-header-padding: 16rpx;
|
||||||
|
--channel-avatar-margin-right: 12rpx;
|
||||||
|
--channel-arrow-margin-left: 8rpx;
|
||||||
|
--channel-name-margin-bottom: 4rpx;
|
||||||
|
--video-title-margin-bottom: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 响应式设计
|
||||||
|
@media (max-width: 375px) {
|
||||||
|
:root {
|
||||||
|
--channel-play-btn-size: 70rpx;
|
||||||
|
--channel-play-btn-small-size: 50rpx;
|
||||||
|
--channel-play-btn-icon-size: 35rpx;
|
||||||
|
--channel-play-btn-icon-small-size: 25rpx;
|
||||||
|
--channel-avatar-size: 50rpx;
|
||||||
|
--channel-name-font-size: 24rpx;
|
||||||
|
--video-title-font-size: 24rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 750px) {
|
||||||
|
:root {
|
||||||
|
--channel-play-btn-size: 90rpx;
|
||||||
|
--channel-play-btn-small-size: 70rpx;
|
||||||
|
--channel-play-btn-icon-size: 45rpx;
|
||||||
|
--channel-play-btn-icon-small-size: 35rpx;
|
||||||
|
--channel-avatar-size: 70rpx;
|
||||||
|
--channel-name-font-size: 32rpx;
|
||||||
|
--video-title-font-size: 32rpx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 播放按钮样式
|
||||||
|
.channel-play-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
width: var(--channel-play-btn-size);
|
||||||
|
height: var(--channel-play-btn-size);
|
||||||
|
background-color: var(--channel-play-btn-bg);
|
||||||
|
border-radius: 50%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.play-icon {
|
||||||
|
width: var(--channel-play-btn-icon-size);
|
||||||
|
height: var(--channel-play-btn-icon-size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小尺寸播放按钮(用于列表)
|
||||||
|
.channel-play-btn.small {
|
||||||
|
width: var(--channel-play-btn-small-size);
|
||||||
|
height: var(--channel-play-btn-small-size);
|
||||||
|
|
||||||
|
.play-icon {
|
||||||
|
width: var(--channel-play-btn-icon-small-size);
|
||||||
|
height: var(--channel-play-btn-icon-small-size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频统计信息
|
||||||
|
.channel-stats {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background: var(--channel-stats-bg);
|
||||||
|
padding: var(--channel-stats-padding);
|
||||||
|
color: var(--channel-stats-color);
|
||||||
|
font-size: var(--channel-stats-font-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频信息容器
|
||||||
|
.channel-info-wrap {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
padding: var(--channel-info-wrap-padding);
|
||||||
|
|
||||||
|
.channel-name {
|
||||||
|
margin-bottom: var(--channel-name-margin-bottom);
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: var(--channel-name-font-size);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--channel-name-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-title {
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: var(--video-title-small-font-size);
|
||||||
|
color: var(--video-title-small-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频标题
|
||||||
|
.video-title {
|
||||||
|
font-size: var(--video-title-font-size);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--video-title-color);
|
||||||
|
margin-bottom: var(--video-title-margin-bottom);
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频统计信息(非绝对定位版本)
|
||||||
|
.video-stats {
|
||||||
|
font-size: var(--video-stats-font-size);
|
||||||
|
color: var(--video-stats-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 频道头部
|
||||||
|
.channel-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: var(--channel-header-padding);
|
||||||
|
border-bottom: 1rpx solid var(--channel-border-color);
|
||||||
|
|
||||||
|
.channel-avatar {
|
||||||
|
width: var(--channel-avatar-size);
|
||||||
|
height: var(--channel-avatar-size);
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: var(--channel-avatar-margin-right);
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-info {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
.channel-name {
|
||||||
|
font-size: var(--channel-name-font-size);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--channel-name-color);
|
||||||
|
margin-bottom: var(--channel-name-margin-bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-follow {
|
||||||
|
font-size: var(--channel-follow-font-size);
|
||||||
|
color: var(--channel-follow-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-arrow {
|
||||||
|
width: var(--channel-arrow-size);
|
||||||
|
height: var(--channel-arrow-size);
|
||||||
|
margin-left: var(--channel-arrow-margin-left);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
components-diy/diy-channel-header.vue
Normal file
45
components-diy/diy-channel-header.vue
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<template>
|
||||||
|
<view class="channel-header" @tap="handlerClick">
|
||||||
|
<image class="channel-avatar" :src="$util.img(value.avatarUrl)" mode="aspectFill"></image>
|
||||||
|
<view class="channel-info">
|
||||||
|
<view class="channel-name">{{ value.channelName }}</view>
|
||||||
|
<view class="channel-follow" v-if="value.showFollow">关注</view>
|
||||||
|
</view>
|
||||||
|
<image class="channel-arrow" v-if="arrowIcon" :src="$util.img(arrowIcon)" mode="aspectFill"></image>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import DiyMinx from './minx.js'
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { wechatChannelConfig } from './js/wechat-channel.js'
|
||||||
|
// #endif
|
||||||
|
export default {
|
||||||
|
name: 'diy-channel-header',
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mixins: [DiyMinx],
|
||||||
|
computed: {
|
||||||
|
arrowIcon() {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return wechatChannelConfig.icon.channelArrow
|
||||||
|
// #endif
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handlerClick() {
|
||||||
|
this.$emit('header-tap', this.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@import './css/common-channel.scss';
|
||||||
|
</style>
|
||||||
275
components-diy/diy-channel-list.vue
Normal file
275
components-diy/diy-channel-list.vue
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
<template>
|
||||||
|
<view :style="componentStyle">
|
||||||
|
<!-- 固定布局模式 -->
|
||||||
|
<view v-if="value.showStyle == 'fixed'" :class="['channel-list', 'row1-of' + value.rowCount]"
|
||||||
|
style="padding:20rpx;">
|
||||||
|
<view v-for="(item, index) in value.list" :key="index" class="channel-item">
|
||||||
|
<diy-channel-video :value="item" @video-play="playVideo(item)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<!-- 其他布局模式 -->
|
||||||
|
<scroll-view v-else :class="['channel-nav', value.showStyle == 'fixed' ? 'fixed-layout' : value.showStyle]"
|
||||||
|
:scroll-x="value.showStyle == 'singleSlide'">
|
||||||
|
<view class="uni-scroll-view-content">
|
||||||
|
<view v-for="(item, index) in value.list" :key="index" :class="['channel-nav-item', value.mode]"
|
||||||
|
:style="{ width: (100 / value.rowCount + '%') + ';' }">
|
||||||
|
<diy-channel-video :value="item" @video-play="playVideo(item)" />
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
import DiyMinx from './minx.js'
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { wechatChannelUtil, wechatChannelConfig } from './js/wechat-channel.js'
|
||||||
|
// #endif
|
||||||
|
export default {
|
||||||
|
name: 'diy-channel-list',
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mixins: [DiyMinx],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
pageWidth: '',
|
||||||
|
indicatorDots: false,
|
||||||
|
swiperCurrent: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
// 组件创建时的逻辑
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
componentRefresh(newValue) {
|
||||||
|
// 监听组件刷新
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
componentStyle() {
|
||||||
|
let style = '';
|
||||||
|
style += 'background-color:' + this.value.componentBgColor + ';';
|
||||||
|
|
||||||
|
if (this.value.componentAngle == 'round') {
|
||||||
|
style += 'border-top-left-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
||||||
|
style += 'border-top-right-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
||||||
|
style += 'border-bottom-left-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
||||||
|
style += 'border-bottom-right-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
||||||
|
}
|
||||||
|
|
||||||
|
style += 'box-shadow:' + (this.value.ornament.type == 'shadow' ? '0 0 10rpx ' + this.value.ornament.color : '') + ';';
|
||||||
|
style += 'border:' + (this.value.ornament.type == 'stroke' ? '2rpx solid ' + this.value.ornament.color : '') + ';';
|
||||||
|
|
||||||
|
return style;
|
||||||
|
},
|
||||||
|
|
||||||
|
swiperHeight() {
|
||||||
|
let height = 0;
|
||||||
|
|
||||||
|
if (this.value.mode == 'graphic') {
|
||||||
|
height = (49 + this.value.imageSize) * this.value.pageCount;
|
||||||
|
} else if (this.value.mode == 'img') {
|
||||||
|
height = (22 + this.value.imageSize) * this.value.pageCount;
|
||||||
|
} else if (this.value.mode == 'text') {
|
||||||
|
height = 43 * this.value.pageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'height:' + (2 * height) + 'rpx';
|
||||||
|
},
|
||||||
|
|
||||||
|
isIndicatorDots() {
|
||||||
|
return this.value.carousel.type != 'hide' &&
|
||||||
|
1 != Math.ceil(this.value.list.length / (this.value.pageCount * this.value.rowCount));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 播放视频
|
||||||
|
async playVideo(item) {
|
||||||
|
await this.__$emitEvent({
|
||||||
|
eventName: 'video-play', data: item, promiseCallback: async (event, handler, awaitedResult) => {
|
||||||
|
if (!awaitedResult) return;
|
||||||
|
try {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
await wechatChannelUtil.playVideo(item);
|
||||||
|
// #endif
|
||||||
|
} catch (err) {
|
||||||
|
console.error('打开视频号失败', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// 图片加载错误处理
|
||||||
|
imgError(index) {
|
||||||
|
// 图片加载失败的处理逻辑
|
||||||
|
console.log('图片加载失败:', index);
|
||||||
|
// 为失败的图片设置默认图片
|
||||||
|
const item = this.value.list[index];
|
||||||
|
if (item) {
|
||||||
|
// 使用默认图片替代加载失败的图片
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
item.coverUrl = wechatChannelConfig.video.defaultCoverUrl;
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
@import './css/common-channel.scss';
|
||||||
|
|
||||||
|
.channel-list {
|
||||||
|
&.row1-of3 {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.channel-item {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
margin-top: 20rpx;
|
||||||
|
width: calc(33.3333333% - 14rpx);
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
&:nth-child(3n + 3) {
|
||||||
|
width: calc(33.33% - 15rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-of-type(1),
|
||||||
|
&:nth-of-type(2),
|
||||||
|
&:nth-of-type(3) {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(3n) {
|
||||||
|
width: calc(33.3333333% - 15rpx);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-child(3n-1) {
|
||||||
|
margin-left: 20rpx;
|
||||||
|
margin-right: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-img-wrap {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 220rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-play-btn {
|
||||||
|
@extend .channel-play-btn.small;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.row1-of2 {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
.channel-item {
|
||||||
|
position: relative;
|
||||||
|
margin-top: 20rpx;
|
||||||
|
width: calc(50% - 10rpx);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
&:nth-child(2n) {
|
||||||
|
margin-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:nth-of-type(1),
|
||||||
|
&:nth-of-type(2) {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-img-wrap {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
height: 340rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-nav {
|
||||||
|
padding: 16rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
&.fixed-layout {
|
||||||
|
.uni-scroll-view-content {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.singleSlide {
|
||||||
|
.uni-scroll-view-content {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-nav-item {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-nav-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
padding: 14rpx 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
.channel-img {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 200rpx;
|
||||||
|
border-radius: 10rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-play-btn {
|
||||||
|
@extend .channel-play-btn.small;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-text {
|
||||||
|
padding-top: 12rpx;
|
||||||
|
line-height: 1.5;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
84
components-diy/diy-channel-video.vue
Normal file
84
components-diy/diy-channel-video.vue
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<template>
|
||||||
|
<view class="channel-video">
|
||||||
|
<!-- 嵌入式视频播放 -->
|
||||||
|
<native-component v-if="canUseEmbedMode">
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
<channel-video
|
||||||
|
:feed-id="value.feedId"
|
||||||
|
:finder-user-name="value.finderUserName"
|
||||||
|
:feed-token="value.feedToken"
|
||||||
|
style="width: 100%; height: 320rpx;">
|
||||||
|
</channel-video>
|
||||||
|
// #endif
|
||||||
|
</native-component>
|
||||||
|
|
||||||
|
<!-- 跳转式视频播放 -->
|
||||||
|
<view v-else @tap="playVideo">
|
||||||
|
<image class="video-cover" :src="$util.img(value.coverUrl)" mode="aspectFill"></image>
|
||||||
|
<view class="channel-play-btn">
|
||||||
|
<image class="play-icon" v-if="playIcon" :src="$util.img(playIcon)" mode="aspectFill"></image>
|
||||||
|
</view>
|
||||||
|
<view class="channel-stats">
|
||||||
|
<text>{{ value.viewCount }}次观看</text>
|
||||||
|
</view>
|
||||||
|
<view class="video-info">
|
||||||
|
<view class="video-title">{{ value.videoTitle }}</view>
|
||||||
|
<view class="video-stats">{{ value.viewCount }}次观看</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { wechatChannelUtil, wechatChannelConfig } from './js/wechat-channel.js'
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'diy-channel-video',
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
canUseEmbedMode() {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return this.value.embedMode && wechatChannelUtil.isEmbedModeSupported();
|
||||||
|
// #endif
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
playIcon() {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
return wechatChannelConfig.icon.playIcon
|
||||||
|
// #endif
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async playVideo() {
|
||||||
|
this.$emit('video-play', this.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@import './css/common-channel.scss';
|
||||||
|
|
||||||
|
.channel-video {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-cover {
|
||||||
|
width: 100%;
|
||||||
|
height: 320rpx;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-info {
|
||||||
|
padding: 16rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
95
components-diy/diy-channel.vue
Normal file
95
components-diy/diy-channel.vue
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<template>
|
||||||
|
<view class="diy-wechat-channel" :style="channelWarpCss">
|
||||||
|
<diy-channel-header :value="value" @header-tap="handlerClick" />
|
||||||
|
<diy-channel-video :value="value" @video-play="playVideo" />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// 微信视频号组件
|
||||||
|
import DiyMinx from './minx.js'
|
||||||
|
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
import { wechatChannelUtil } from './js/wechat-channel.js'
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'diy-channel',
|
||||||
|
props: {
|
||||||
|
value: {
|
||||||
|
type: Object
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {};
|
||||||
|
},
|
||||||
|
created() { },
|
||||||
|
mixins: [DiyMinx],
|
||||||
|
watch: {
|
||||||
|
// 组件刷新监听
|
||||||
|
componentRefresh: function (nval) { }
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
channelWarpCss: function () {
|
||||||
|
var obj = '';
|
||||||
|
if (this.value.componentAngle == 'round') {
|
||||||
|
obj += 'border-top-left-radius:' + this.value.topAroundRadius * 2 + 'rpx;';
|
||||||
|
obj += 'border-top-right-radius:' + this.value.topAroundRadius * 2 + 'rpx;';
|
||||||
|
obj += 'border-bottom-left-radius:' + this.value.bottomAroundRadius * 2 + 'rpx;';
|
||||||
|
obj += 'border-bottom-right-radius:' + this.value.bottomAroundRadius * 2 + 'rpx;';
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async handlerClick() {
|
||||||
|
await this.__$emitEvent({
|
||||||
|
eventName: 'channel-tap', data: this.value, promiseCallback: (event, handler, awaitedResult) => {
|
||||||
|
if (!awaitedResult) return;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async playVideo() {
|
||||||
|
await this.__$emitEvent({
|
||||||
|
eventName: 'video-play', data: this.value, promiseCallback: async (event, handler, awaitedResult) => {
|
||||||
|
if (!awaitedResult) return;
|
||||||
|
try {
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
await wechatChannelUtil.playVideo(this.value);
|
||||||
|
// #endif
|
||||||
|
} catch (err) {
|
||||||
|
console.error('打开视频号失败', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@import './css/common-channel.scss';
|
||||||
|
|
||||||
|
.diy-wechat-channel {
|
||||||
|
width: 100%;
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-video {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-cover {
|
||||||
|
width: 100%;
|
||||||
|
height: 320rpx;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-info {
|
||||||
|
padding: 16rpx;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -251,14 +251,14 @@
|
|||||||
<diy-icon :value="item"></diy-icon>
|
<diy-icon :value="item"></diy-icon>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="item.componentName == 'WechatChannel'">
|
<template v-if="item.componentName == 'Channel'">
|
||||||
<!-- 微信视频号 -->
|
<!-- 视频号 -->
|
||||||
<diy-wechat-channel :value="item"></diy-wechat-channel>
|
<diy-channel :value="item"></diy-channel>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-if="item.componentName == 'WechatChannelList'">
|
<template v-if="item.componentName == 'ChannelList'">
|
||||||
<!-- 微信视频号列表 -->
|
<!-- 视频号列表 -->
|
||||||
<diy-wechat-channel-list :value="item"></diy-wechat-channel-list>
|
<diy-channel-list :value="item"></diy-channel-list>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- 自定义扩展组件 -->
|
<!-- 自定义扩展组件 -->
|
||||||
|
|||||||
@@ -1,458 +0,0 @@
|
|||||||
<template>
|
|
||||||
<view :style="componentStyle">
|
|
||||||
<!-- 固定布局模式 -->
|
|
||||||
<view v-if="value.showStyle == 'fixed'" :class="['channel-list', 'row1-of' + value.rowCount]"
|
|
||||||
style="padding:20rpx;">
|
|
||||||
<view v-for="(item, index) in value.list" :key="index" class="channel-item" @tap="playVideo(item)">
|
|
||||||
<view class="channel-img-wrap">
|
|
||||||
<image class="channel-img" style="border-radius:10rpx;" :src="$util.img(item.coverUrl)"
|
|
||||||
mode="aspectFill" @error="imgError(index)"></image>
|
|
||||||
<view class="channel-play-btn">
|
|
||||||
<image class="play-icon" style="width:30rpx;" :src="$util.img('addon/personnel/shop/view/enterprise/play.png')"
|
|
||||||
mode="widthFix"></image>
|
|
||||||
</view>
|
|
||||||
<view class="channel-stats">
|
|
||||||
<text>{{ item.viewCount }}次观看</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
<view class="channel-info-wrap">
|
|
||||||
<view class="channel-name" :style="{
|
|
||||||
'font-size': (value.font.size * 2 + 'rpx') + ';',
|
|
||||||
'font-weight': value.font.weight + ';',
|
|
||||||
'color': value.font.color + ';'
|
|
||||||
}">{{ item.channelName }}</view>
|
|
||||||
<view class="video-title" :style="{
|
|
||||||
'font-size': (value.font.size * 1.8 + 'rpx') + ';',
|
|
||||||
'color': '#666;'
|
|
||||||
}">{{ item.videoTitle }}</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
|
|
||||||
<!-- 其他布局模式 -->
|
|
||||||
<scroll-view v-else :class="['channel-nav', value.showStyle == 'fixed' ? 'fixed-layout' : value.showStyle]"
|
|
||||||
:scroll-x="value.showStyle == 'singleSlide'">
|
|
||||||
<view class="uni-scroll-view-content">
|
|
||||||
<view v-for="(item, index) in value.list" :key="index" :class="['channel-nav-item', value.mode]"
|
|
||||||
:style="{ width: (100 / value.rowCount + '%') + ';' }" @tap="playVideo(item)">
|
|
||||||
<view class="channel-img">
|
|
||||||
<image :style="{
|
|
||||||
'max-width': '100%;',
|
|
||||||
'border-radius': '8rpx;'
|
|
||||||
}" :src="$util.img(item.coverUrl)" mode="aspectFill"
|
|
||||||
:show-menu-by-longpress="true"></image>
|
|
||||||
<view class="channel-play-btn">
|
|
||||||
<image class="play-icon" style="width:30rpx;" :src="$util.img('addon/personnel/shop/view/enterprise/play.png')"
|
|
||||||
mode="widthFix"></image>
|
|
||||||
</view>
|
|
||||||
<view class="channel-stats">
|
|
||||||
<text>{{ item.viewCount }}次观看</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
<view class="channel-text" :style="{
|
|
||||||
'margin-left': '16rpx;',
|
|
||||||
'font-size': (value.font.size * 2 + 'rpx') + ';',
|
|
||||||
'font-weight': value.font.weight + ';',
|
|
||||||
'color': value.font.color + ';'
|
|
||||||
}">{{ item.videoTitle }}</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</scroll-view>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
|
|
||||||
import DiyMinx from './minx.js'
|
|
||||||
export default {
|
|
||||||
name: 'diy-wechat-channel-list',
|
|
||||||
props: {
|
|
||||||
value: {
|
|
||||||
type: Object,
|
|
||||||
default: () => ({})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mixins: [DiyMinx],
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
pageWidth: '',
|
|
||||||
indicatorDots: false,
|
|
||||||
swiperCurrent: 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
// 组件创建时的逻辑
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
componentRefresh(newValue) {
|
|
||||||
// 监听组件刷新
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
componentStyle() {
|
|
||||||
let style = '';
|
|
||||||
style += 'background-color:' + this.value.componentBgColor + ';';
|
|
||||||
|
|
||||||
if (this.value.componentAngle == 'round') {
|
|
||||||
style += 'border-top-left-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
|
||||||
style += 'border-top-right-radius:' + (2 * this.value.topAroundRadius) + 'rpx;';
|
|
||||||
style += 'border-bottom-left-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
|
||||||
style += 'border-bottom-right-radius:' + (2 * this.value.bottomAroundRadius) + 'rpx;';
|
|
||||||
}
|
|
||||||
|
|
||||||
style += 'box-shadow:' + (this.value.ornament.type == 'shadow' ? '0 0 10rpx ' + this.value.ornament.color : '') + ';';
|
|
||||||
style += 'border:' + (this.value.ornament.type == 'stroke' ? '2rpx solid ' + this.value.ornament.color : '') + ';';
|
|
||||||
|
|
||||||
return style;
|
|
||||||
},
|
|
||||||
|
|
||||||
swiperHeight() {
|
|
||||||
let height = 0;
|
|
||||||
|
|
||||||
if (this.value.mode == 'graphic') {
|
|
||||||
height = (49 + this.value.imageSize) * this.value.pageCount;
|
|
||||||
} else if (this.value.mode == 'img') {
|
|
||||||
height = (22 + this.value.imageSize) * this.value.pageCount;
|
|
||||||
} else if (this.value.mode == 'text') {
|
|
||||||
height = 43 * this.value.pageCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'height:' + (2 * height) + 'rpx';
|
|
||||||
},
|
|
||||||
|
|
||||||
isIndicatorDots() {
|
|
||||||
return this.value.carousel.type != 'hide' &&
|
|
||||||
1 != Math.ceil(this.value.list.length / (this.value.pageCount * this.value.rowCount));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// 播放视频
|
|
||||||
async playVideo(item) {
|
|
||||||
await this.__$emitEvent({
|
|
||||||
eventName: 'video-play', data: item, promiseCallback: (event, handler, awaitedResult) => {
|
|
||||||
if (!awaitedResult) return;
|
|
||||||
// 检查微信环境
|
|
||||||
if (typeof wx === 'undefined') {
|
|
||||||
console.error('当前环境不是微信小程序');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 检查基础库版本
|
|
||||||
const systemInfo = wx.getSystemInfoSync();
|
|
||||||
const SDKVersion = systemInfo.SDKVersion;
|
|
||||||
const versionCompare = (v1, v2) => {
|
|
||||||
const arr1 = v1.split('.');
|
|
||||||
const arr2 = v2.split('.');
|
|
||||||
for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
|
|
||||||
const num1 = parseInt(arr1[i] || 0);
|
|
||||||
const num2 = parseInt(arr2[i] || 0);
|
|
||||||
if (num1 > num2) return 1;
|
|
||||||
if (num1 < num2) return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
if (versionCompare(SDKVersion, '2.19.2') < 0) {
|
|
||||||
console.error('当前微信基础库版本过低,需要 2.19.2 或以上版本');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 调用微信视频号播放API
|
|
||||||
if (wx.openChannelsActivity) {
|
|
||||||
wx.openChannelsActivity({
|
|
||||||
feedId: item.feedId,
|
|
||||||
finderUserName: item.finderUserName,
|
|
||||||
success: (res) => {
|
|
||||||
console.log('打开视频号成功', res);
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('打开视频号失败', err);
|
|
||||||
// 错误码处理
|
|
||||||
switch (err.errCode) {
|
|
||||||
case 40001:
|
|
||||||
console.error('错误:40001,检查主体要求或嵌入式打开的关联关系');
|
|
||||||
break;
|
|
||||||
case 40002:
|
|
||||||
console.error('错误:40002,参数错误,检查 feedId 和 finderUserName');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.error('错误:' + err.errCode + ',' + (err.errMsg || '未知错误'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error('当前环境不支持微信视频号');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
// 图片加载错误处理
|
|
||||||
imgError(index) {
|
|
||||||
// 图片加载失败的处理逻辑
|
|
||||||
console.log('图片加载失败:', index);
|
|
||||||
// 为失败的图片设置默认图片
|
|
||||||
const item = this.value.list[index];
|
|
||||||
if (item) {
|
|
||||||
// 使用默认图片替代加载失败的图片
|
|
||||||
item.coverUrl = 'addon/personnel/shop/view/enterprise/default-video-cover.png';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.channel-list {
|
|
||||||
&.row1-of3 {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
|
|
||||||
.channel-item {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
margin-top: 20rpx;
|
|
||||||
width: calc(33.3333333% - 14rpx);
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
&:nth-child(3n + 3) {
|
|
||||||
width: calc(33.33% - 15rpx);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-of-type(1),
|
|
||||||
&:nth-of-type(2),
|
|
||||||
&:nth-of-type(3) {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-child(3n) {
|
|
||||||
width: calc(33.3333333% - 15rpx);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-child(3n-1) {
|
|
||||||
margin-left: 20rpx;
|
|
||||||
margin-right: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-img-wrap {
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
height: 220rpx;
|
|
||||||
border-radius: 10rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-img {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-play-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
width: 60rpx;
|
|
||||||
height: 60rpx;
|
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
|
||||||
border-radius: 50%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-stats {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
|
|
||||||
padding: 10rpx;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-info-wrap {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
flex: 1;
|
|
||||||
padding: 10rpx 0;
|
|
||||||
|
|
||||||
.channel-name {
|
|
||||||
margin-bottom: 4rpx;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-title {
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.row1-of2 {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: space-between;
|
|
||||||
|
|
||||||
.channel-item {
|
|
||||||
position: relative;
|
|
||||||
margin-top: 20rpx;
|
|
||||||
width: calc(50% - 10rpx);
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
&:nth-child(2n) {
|
|
||||||
margin-right: 0 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:nth-of-type(1),
|
|
||||||
&:nth-of-type(2) {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-img-wrap {
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
height: 340rpx;
|
|
||||||
border-radius: 10rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-img {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-play-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
width: 80rpx;
|
|
||||||
height: 80rpx;
|
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
|
||||||
border-radius: 50%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-stats {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
|
|
||||||
padding: 10rpx;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 20rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-info-wrap {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
flex: 1;
|
|
||||||
padding: 10rpx 0;
|
|
||||||
|
|
||||||
.channel-name {
|
|
||||||
margin-bottom: 4rpx;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-title {
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-nav {
|
|
||||||
padding: 16rpx;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
&.fixed-layout {
|
|
||||||
.uni-scroll-view-content {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.singleSlide {
|
|
||||||
.uni-scroll-view-content {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-nav-item {
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-nav-item {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
padding: 14rpx 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
.channel-img {
|
|
||||||
position: relative;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 200rpx;
|
|
||||||
border-radius: 10rpx;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
image {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-play-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
width: 60rpx;
|
|
||||||
height: 60rpx;
|
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
|
||||||
border-radius: 50%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-stats {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
|
|
||||||
padding: 10rpx;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 20rpx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-text {
|
|
||||||
padding-top: 12rpx;
|
|
||||||
line-height: 1.5;
|
|
||||||
white-space: nowrap;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
overflow: hidden;
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
<template>
|
|
||||||
<!-- #ifdef MP-WEIXIN -->
|
|
||||||
<view class="diy-wechat-channel" :style="channelWarpCss">
|
|
||||||
<view class="channel-header" @tap="handlerClick">
|
|
||||||
<image class="channel-avatar" :src="$util.img(value.avatarUrl)" mode="aspectFill"></image>
|
|
||||||
<view class="channel-info">
|
|
||||||
<view class="channel-name">{{ value.channelName }}</view>
|
|
||||||
<view class="channel-follow" v-if="value.showFollow">关注</view>
|
|
||||||
</view>
|
|
||||||
<image class="channel-arrow" :src="$util.img('addon/personnel/shop/view/enterprise/arrow.png')" mode="aspectFill"></image>
|
|
||||||
</view>
|
|
||||||
<!-- 嵌入式视频播放 -->
|
|
||||||
<native-component v-if="value.embedMode && typeof wx !== 'undefined' && wx.canIUse('component.channel-video')">
|
|
||||||
<channel-video
|
|
||||||
:feed-id="value.feedId"
|
|
||||||
:finder-user-name="value.finderUserName"
|
|
||||||
:feed-token="value.feedToken"
|
|
||||||
style="width: 100%; height: 320rpx;">
|
|
||||||
</channel-video>
|
|
||||||
</native-component>
|
|
||||||
<!-- 跳转式视频播放 -->
|
|
||||||
<view v-else class="channel-video" @tap="playVideo">
|
|
||||||
<image class="video-cover" :src="$util.img(value.coverUrl)" mode="aspectFill"></image>
|
|
||||||
<view class="video-play-btn">
|
|
||||||
<image class="play-icon" :src="$util.img('addon/personnel/shop/view/enterprise/play.png')" mode="aspectFill"></image>
|
|
||||||
</view>
|
|
||||||
<view class="video-info">
|
|
||||||
<view class="video-title">{{ value.videoTitle }}</view>
|
|
||||||
<view class="video-stats">
|
|
||||||
<text>{{ value.viewCount }}次观看</text>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
</view>
|
|
||||||
<!-- #endif -->
|
|
||||||
</template>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
// 微信视频号组件
|
|
||||||
import DiyMinx from './minx.js'
|
|
||||||
export default {
|
|
||||||
name: 'diy-wechat-channel',
|
|
||||||
props: {
|
|
||||||
value: {
|
|
||||||
type: Object
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
created() { },
|
|
||||||
mixins: [DiyMinx],
|
|
||||||
watch: {
|
|
||||||
// 组件刷新监听
|
|
||||||
componentRefresh: function (nval) { }
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
channelWarpCss: function () {
|
|
||||||
var obj = '';
|
|
||||||
if (this.value.componentAngle == 'round') {
|
|
||||||
obj += 'border-top-left-radius:' + this.value.topAroundRadius * 2 + 'rpx;';
|
|
||||||
obj += 'border-top-right-radius:' + this.value.topAroundRadius * 2 + 'rpx;';
|
|
||||||
obj += 'border-bottom-left-radius:' + this.value.bottomAroundRadius * 2 + 'rpx;';
|
|
||||||
obj += 'border-bottom-right-radius:' + this.value.bottomAroundRadius * 2 + 'rpx;';
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async handlerClick() {
|
|
||||||
await this.__$emitEvent({
|
|
||||||
eventName: 'channel-tap', data: this.value, promiseCallback: (event, handler, awaitedResult) => {
|
|
||||||
if (!awaitedResult) return;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
async playVideo() {
|
|
||||||
await this.__$emitEvent({
|
|
||||||
eventName: 'video-play', data: this.value, promiseCallback: (event, handler, awaitedResult) => {
|
|
||||||
if (!awaitedResult) return;
|
|
||||||
// 检查微信环境
|
|
||||||
if (typeof wx === 'undefined') {
|
|
||||||
console.error('当前环境不是微信小程序');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 检查基础库版本
|
|
||||||
const systemInfo = wx.getSystemInfoSync();
|
|
||||||
const SDKVersion = systemInfo.SDKVersion;
|
|
||||||
const versionCompare = (v1, v2) => {
|
|
||||||
const arr1 = v1.split('.');
|
|
||||||
const arr2 = v2.split('.');
|
|
||||||
for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
|
|
||||||
const num1 = parseInt(arr1[i] || 0);
|
|
||||||
const num2 = parseInt(arr2[i] || 0);
|
|
||||||
if (num1 > num2) return 1;
|
|
||||||
if (num1 < num2) return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
if (versionCompare(SDKVersion, '2.19.2') < 0) {
|
|
||||||
console.error('当前微信基础库版本过低,需要 2.19.2 或以上版本');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 调用微信视频号播放API
|
|
||||||
if (wx.openChannelsActivity) {
|
|
||||||
wx.openChannelsActivity({
|
|
||||||
feedId: this.value.feedId,
|
|
||||||
finderUserName: this.value.finderUserName,
|
|
||||||
success: (res) => {
|
|
||||||
console.log('打开视频号成功', res);
|
|
||||||
},
|
|
||||||
fail: (err) => {
|
|
||||||
console.error('打开视频号失败', err);
|
|
||||||
// 错误码处理
|
|
||||||
switch (err.errCode) {
|
|
||||||
case 40001:
|
|
||||||
console.error('错误:40001,检查主体要求或嵌入式打开的关联关系');
|
|
||||||
break;
|
|
||||||
case 40002:
|
|
||||||
console.error('错误:40002,参数错误,检查 feedId 和 finderUserName');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.error('错误:' + err.errCode + ',' + (err.errMsg || '未知错误'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.error('当前环境不支持微信视频号');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.diy-wechat-channel {
|
|
||||||
width: 100%;
|
|
||||||
background-color: #fff;
|
|
||||||
border-radius: 12rpx;
|
|
||||||
overflow: hidden;
|
|
||||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-header {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
padding: 16rpx;
|
|
||||||
border-bottom: 1rpx solid #f0f0f0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-avatar {
|
|
||||||
width: 60rpx;
|
|
||||||
height: 60rpx;
|
|
||||||
border-radius: 50%;
|
|
||||||
margin-right: 12rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-info {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-name {
|
|
||||||
font-size: 28rpx;
|
|
||||||
font-weight: 500;
|
|
||||||
color: #333;
|
|
||||||
margin-bottom: 4rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-follow {
|
|
||||||
font-size: 24rpx;
|
|
||||||
color: #07c160;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-arrow {
|
|
||||||
width: 24rpx;
|
|
||||||
height: 24rpx;
|
|
||||||
margin-left: 8rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.channel-video {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-cover {
|
|
||||||
width: 100%;
|
|
||||||
height: 320rpx;
|
|
||||||
object-fit: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-play-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
left: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
width: 80rpx;
|
|
||||||
height: 80rpx;
|
|
||||||
background-color: rgba(0, 0, 0, 0.4);
|
|
||||||
border-radius: 50%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.play-icon {
|
|
||||||
width: 40rpx;
|
|
||||||
height: 40rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-info {
|
|
||||||
padding: 16rpx;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-title {
|
|
||||||
font-size: 28rpx;
|
|
||||||
font-weight: 500;
|
|
||||||
color: #333;
|
|
||||||
margin-bottom: 8rpx;
|
|
||||||
line-height: 1.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.video-stats {
|
|
||||||
font-size: 24rpx;
|
|
||||||
color: #999;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
179
components-diy/js/wechat-channel.js
Normal file
179
components-diy/js/wechat-channel.js
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
// 微信视频号组件配置
|
||||||
|
export const wechatChannelConfig = {
|
||||||
|
// 图标相关
|
||||||
|
icon: {
|
||||||
|
defaultSize: 80, // 默认图标尺寸(rpx)
|
||||||
|
smallSize: 60, // 小图标尺寸(rpx)
|
||||||
|
channelArrowSize: 24, // 频道箭头图标尺寸(rpx)
|
||||||
|
channelArrow: 'addon/personnel/shop/view/enterprise/arrow.png', // 频道箭头图标路径
|
||||||
|
playIcon: 'addon/personnel/shop/view/enterprise/play.png', // 播放按钮图标路径
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// 视频相关配置
|
||||||
|
video: {
|
||||||
|
defaultHeight: 320, // 默认视频高度(rpx)
|
||||||
|
minHeight: 200, // 最小视频高度(rpx)
|
||||||
|
maxHeight: 500, // 最大视频高度(rpx)
|
||||||
|
defaultCoverUrl: 'addon/personnel/shop/view/enterprise/default-video-cover.png', // 默认视频封面
|
||||||
|
},
|
||||||
|
|
||||||
|
// 播放按钮配置
|
||||||
|
playButton: {
|
||||||
|
size: 80, // 标准尺寸(rpx)
|
||||||
|
smallSize: 60, // 小尺寸(rpx)
|
||||||
|
iconSize: 40, // 标准图标尺寸(rpx)
|
||||||
|
smallIconSize: 30, // 小图标尺寸(rpx)
|
||||||
|
background: 'rgba(0, 0, 0, 0.4)', // 背景颜色
|
||||||
|
},
|
||||||
|
|
||||||
|
// 布局配置
|
||||||
|
layout: {
|
||||||
|
borderRadius: 12, // 圆角(rpx)
|
||||||
|
padding: 16, // 内边距(rpx)
|
||||||
|
margin: 10, // 外边距(rpx)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 字体配置
|
||||||
|
font: {
|
||||||
|
channelNameSize: 28, // 频道名称字体大小(rpx)
|
||||||
|
videoTitleSize: 28, // 视频标题字体大小(rpx)
|
||||||
|
statsSize: 24, // 统计信息字体大小(rpx)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 颜色配置
|
||||||
|
color: {
|
||||||
|
channelName: '#333', // 频道名称颜色
|
||||||
|
videoTitle: '#333', // 视频标题颜色
|
||||||
|
stats: '#999', // 统计信息颜色
|
||||||
|
border: '#f0f0f0', // 边框颜色
|
||||||
|
},
|
||||||
|
|
||||||
|
// 微信相关配置
|
||||||
|
wechat: {
|
||||||
|
minSdkVersion: '2.19.2', // 最小微信基础库版本
|
||||||
|
embedComponent: 'component.channel-video', // 嵌入式视频组件名称
|
||||||
|
},
|
||||||
|
|
||||||
|
// 错误提示配置
|
||||||
|
error: {
|
||||||
|
notWechat: '当前环境不是微信小程序',
|
||||||
|
lowVersion: '当前微信基础库版本过低,需要 2.19.2 或以上版本',
|
||||||
|
notSupported: '当前环境不支持微信视频号',
|
||||||
|
missingFields: '缺少必要字段: {field}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取配置项的辅助函数
|
||||||
|
export const getwechatChannelConfig = (key, defaultValue = null) => {
|
||||||
|
const keys = key.split('.');
|
||||||
|
let config = wechatChannelConfig;
|
||||||
|
|
||||||
|
for (const k of keys) {
|
||||||
|
if (config[k] === undefined) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
config = config[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 微信视频号工具函数
|
||||||
|
export const wechatChannelUtil = {
|
||||||
|
// 版本比较
|
||||||
|
versionCompare(v1, v2) {
|
||||||
|
const arr1 = v1.split('.');
|
||||||
|
const arr2 = v2.split('.');
|
||||||
|
for (let i = 0; i < Math.max(arr1.length, arr2.length); i++) {
|
||||||
|
const num1 = parseInt(arr1[i] || 0);
|
||||||
|
const num2 = parseInt(arr2[i] || 0);
|
||||||
|
if (num1 > num2) return 1;
|
||||||
|
if (num1 < num2) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 检查是否支持嵌入式播放
|
||||||
|
isEmbedModeSupported() {
|
||||||
|
return typeof wx !== 'undefined' && wx.canIUse(wechatChannelConfig.wechat.embedComponent);
|
||||||
|
},
|
||||||
|
|
||||||
|
// 获取默认视频封面
|
||||||
|
getDefaultCoverUrl() {
|
||||||
|
return wechatChannelConfig.video.defaultCoverUrl;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 数据校验
|
||||||
|
validateVideoData(item) {
|
||||||
|
const requiredFields = ['feedId', 'finderUserName'];
|
||||||
|
for (const field of requiredFields) {
|
||||||
|
if (!item[field]) {
|
||||||
|
throw new Error(`缺少必要字段: ${field}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
// 播放视频
|
||||||
|
playVideo(item) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
// 数据校验
|
||||||
|
this.validateVideoData(item);
|
||||||
|
} catch (err) {
|
||||||
|
reject(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查微信环境
|
||||||
|
if (typeof wx === 'undefined') {
|
||||||
|
reject(new Error(wechatChannelConfig.error.notWechat));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查基础库版本
|
||||||
|
const systemInfo = wx.getSystemInfoSync();
|
||||||
|
const SDKVersion = systemInfo.SDKVersion;
|
||||||
|
if (this.versionCompare(SDKVersion, wechatChannelConfig.wechat.minSdkVersion) < 0) {
|
||||||
|
reject(new Error(wechatChannelConfig.error.lowVersion));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用微信视频号播放API
|
||||||
|
if (wx.openChannelsActivity) {
|
||||||
|
wx.openChannelsActivity({
|
||||||
|
feedId: item.feedId,
|
||||||
|
finderUserName: item.finderUserName,
|
||||||
|
success: (res) => {
|
||||||
|
console.log('打开视频号成功', res);
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
this.handleError(err);
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reject(new Error(wechatChannelConfig.error.notSupported));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// 统一错误处理
|
||||||
|
handleError(err) {
|
||||||
|
console.error('微信视频号错误:', err);
|
||||||
|
// 可以添加错误上报或用户提示逻辑
|
||||||
|
switch (err.errCode) {
|
||||||
|
case 40001:
|
||||||
|
console.error('错误:40001,检查主体要求或嵌入式打开的关联关系');
|
||||||
|
break;
|
||||||
|
case 40002:
|
||||||
|
console.error('错误:40002,参数错误,检查 feedId 和 finderUserName');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error('错误:' + err.errCode + ',' + (err.errMsg || '未知错误'));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user