Commit 4a85c67b by 胡悦

feat: 新增MediaComponent组件并集成到详情页

refactor(HomeFrame): 替换SwiperComponent为MaterialIndex组件

feat: 添加MaterialIndex轮播组件实现自动播放与手势滑动

feat(equity/index): 添加默认素材数据和工具列表

chore(env): 修改默认环境索引为1
1 parent 50288c5e
<template>
<view class="material-box">
<!-- 轮播容器:使用 movable-area 实现自定义滑动与自动播放 -->
<movable-area class="swiper-carousel" @touchstart="starts" @touchend="ends">
<!-- 展示位:根据 item.class 切换左/中/右位置,只有中间可拖拽/点击 -->
<movable-view v-for="(item, index) in imagelist" :key="index" :class="['carousel-block', item.class]"
direction="horizontal" :disabled="item.class != 'block-center' || moduleList.length == 1"
:x="item.class != 'block-center' ? 0 : viewX" @change="change" @click.stop="handleClick(item)">
<image class="image-block" :src="item.imgUrl" />
</movable-view>
</movable-area>
<!-- 标题:与当前中心卡片 materialName 联动 -->
<view class="module-title flex">
{{ moduleTitle }}
</view>
<!-- 指示点:与 currentIndex 同步高亮 -->
<view class="module-dots flex">
<template v-for="(i, index) in moduleList">
<div :class="['dot', { 'active': index == currentIndex }]" :key="index">
</div>
</template>
</view>
</view>
</template>
<script>
export default {
// 自定义三卡片轮播组件:实现自动播放与手势滑动
name: 'MaterialIndex',
data() {
return {
// 素材数据源(示例数据,可替换为真实接口)
moduleList: [
{
id: 1,
materialName: '素材1',
materialUrl: 'https://img.pconline.com.cn/images/upload/upc/tx/wallpaper/1305/16/c4/20990657_1368686545122.jpg'
},
{
id: 2,
materialName: '素材2',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 3,
materialName: '素材3',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 4,
materialName: '素材4',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 5,
materialName: '素材5',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
}
],
// 轮播数据快照(与 moduleList 同步)
datalist: [],
// 渲染用的三卡片列表(左/中/右)
imagelist: [],
// 三卡片位置与类名映射
style_object: [
{ index: 0, class: 'block-left' },
{ index: 1, class: 'block-center' },
{ index: 2, class: 'block-right' }
],
// 拖拽与位置控制
blockX: 0,
viewX: 0,
ismove: 0,
// 自动播放控制参数与状态
autoplay: true,
interval: 3000,
autoPlayTimer: null,
endTimer: null,
playStatus: true,
currentIndex: 0
}
},
computed: {
// 当前模块标题与中心卡片联动
moduleTitle() {
return this.moduleList[this.currentIndex]?.materialName || ''
}
},
mounted() {
// 初始化轮播并开启自动播放
this.getDatalist()
if (this.autoplay) this.autoPlayFunction()
},
methods: {
// 初始化 imagelist(最多三项)并更新 currentIndex
getDatalist() {
this.datalist = this.moduleList
const list = JSON.parse(JSON.stringify(this.style_object))
const len = this.datalist.length
if (!len) {
this.imagelist = []
return
}
if (len === 1) {
this.imagelist = [
{ isToor: 1, class: 'block-center', imgUrl: this.datalist[0].materialUrl, isIndex: 0, index: 1 }
]
return
}
const count = Math.min(3, len)
this.imagelist = Array.from({ length: count }).map((_, i) => {
const cfg = list[i]
return {
isToor: cfg.index,
class: cfg.class,
imgUrl: this.datalist[i].materialUrl,
isIndex: i,
index: cfg.index
}
})
const ci = this.imagelist.findIndex(item => item.index === 1)
if (ci !== -1) this.currentIndex = this.imagelist[ci].isIndex
},
// 自动播放控制:递归定时触发 updateCarouselPositions
autoPlayFunction() {
if (!this.autoplay) return
if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer)
this.autoPlayTimer = setTimeout(() => {
if (!this.playStatus) {
clearTimeout(this.autoPlayTimer)
this.autoPlayTimer = null
return
}
this.updateCarouselPositions('left')
this.autoPlayFunction()
}, this.interval)
},
// 根据滑动方向更新三卡片位置与索引
updateCarouselPositions(direction = 'left') {
const { imagelist, datalist } = this
const len = datalist.length - 1
const list = JSON.parse(JSON.stringify(this.style_object))
if (datalist.length === 2) {
this.imagelist.forEach((item, index) => {
if (index !== 0) {
const toor = item.isToor === 1 ? 2 : 1
item.isToor = toor
item.imgUrl = ''
item.class = list[toor].class
item.x = 0
const isIndex = item.isIndex
item.isIndex = isIndex
item.imgUrl = datalist[isIndex].materialUrl || ''
item.index = list[toor].index
}
})
} else {
this.imagelist.forEach(item => {
const toor = direction === 'left'
? (item.isToor - 1) < 0 ? imagelist.length - 1 : item.isToor - 1
: (item.isToor + 1) > imagelist.length - 1 ? 0 : item.isToor + 1
item.isToor = toor
item.imgUrl = ''
item.class = list[toor].class
item.x = 0
let isIndex = item.isIndex
if (direction === 'left' && item.class === 'block-right') {
if (isIndex === len) isIndex = 2
else if (isIndex === len - 1) isIndex = 1
else isIndex += 3
if (isIndex > len) isIndex = 0
}
if (direction === 'right' && item.class === 'block-left') {
if (isIndex === 1) isIndex = len - 1
else if (isIndex === 0) isIndex = len - 2
else isIndex -= 3
if (isIndex < 0) isIndex = len
}
item.isIndex = isIndex
item.imgUrl = datalist[isIndex].materialUrl || ''
item.index = list[toor].index
})
}
const ci = this.imagelist.findIndex(item => item.index === 1)
if (ci !== -1) this.currentIndex = this.imagelist[ci].isIndex
},
// 触摸开始:暂停自动播放、记录起点
starts(e) {
this.ismove = e.touches[0].pageX
this.playStatus = false
if (this.endTimer) {
clearTimeout(this.endTimer)
this.endTimer = null
return
}
},
// 触摸结束:判断滑动阈值,切换或回弹,并恢复自动播放
ends(e) {
if (this.moduleList.length === 1) return
const pageX = e.changedTouches[0].pageX
const nums = this.ismove - pageX
if (nums === 0) return
if (!(nums > 50 || this.blockX < -30) || !(nums < -50 || this.blockX > 30)) {
this.viewX = -10
setTimeout(() => { this.viewX = 0 }, 16)
}
if (nums > 50 || this.blockX < -30) this.updateCarouselPositions('left')
if (nums < -50 || this.blockX > 30) this.updateCarouselPositions('right')
this.endTimer = setTimeout(() => {
if (!this.playStatus) {
this.playStatus = true
this.autoPlayFunction()
}
}, this.interval)
},
// movable-view 位移变化回调,记录偏移值
change(e) {
const { x } = e.detail
this.blockX = x
},
// 点击中心卡片,向父组件抛出 itemClick
handleClick(item) {
console.log(item)
if (item.class !== 'block-center') return
const data = this.moduleList[item.isIndex]
this.$emit('itemClick', data, item.isIndex)
}
}
}
</script>
<style scoped lang="scss">
/* 布局容器 */
.material-box {
width: 100%;
height: 100%;
text-align: center;
}
/* 轮播外层:宽度 90%,上下留边距 */
.swiper-carousel {
width: 90%;
height: calc(90% - #{toRpx(96)});
position: relative;
overflow: hidden;
margin: toRpx(60) auto;
}
/* 三卡片基础样式 */
.carousel-block {
position: absolute;
overflow: hidden;
transition: all 0.2s ease;
border: toRpx(2) solid #ffffffb3;
box-shadow: 0 toRpx(3) toRpx(12) 0 #5294ff33;
border-radius: toRpx(24);
}
.image-block {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
/* 三个展示位:左/中/右的定位容器 */
.block-left,
.block-right,
.block-center {
position: absolute;
}
.block-left {
left: 0%;
top: 10%;
width: 80%;
height: 80%;
z-index: 10;
opacity: 0.9;
}
.block-right {
left: 20%;
top: 10%;
width: 80%;
height: 80%;
z-index: 15;
opacity: 0.9;
}
.block-center {
left: 14%;
top: 2%;
width: 72%;
height: 96%;
z-index: 20;
}
/* 标题与指示点区域 */
.module-title {
color: #333333;
font-size: toRpx(24);
margin-top: toRpx(24);
justify-content: center;
position: relative;
}
/* 指示点:靠右下角排列 */
.module-dots {
position: absolute;
bottom: toRpx(116);
right: toRpx(98);
gap: toRpx(12);
.dot {
width: toRpx(12);
height: toRpx(12);
opacity: 1;
background: #0007400d;
border-radius: 100%;
}
.active {
background: #000740;
}
}
</style>
const target = ['ip', 'dev', 'uat', 'prod', 'beta'] const target = ['ip', 'dev', 'uat', 'prod', 'beta']
const index = 2 const index = 1
/** /**
* *
0本地 0本地
......
<!--
* @Author: yangming@didihu.com.cn yangming@didihu.com.cn
* @Date: 2024-11-22 20:45:03
* @LastEditors: yangming@didihu.com.cn yangming@didihu.com.cn
* @LastEditTime: 2025-05-19 15:15:22
* @FilePath: \gl-tape\pages\equity\detail\components\MediaComponent.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<view :class="['layout']">
<wnCanvas
:drawStatus="penSwitch"
:canvasId="`c-${madiaId}`"
custom
@scale="$emit('scale', $event)"
ref="canvasRef"
>
<template slot="customContent">
<view class="layout-content">
<template v-if="hasCarBrand">
<image
:key="viewKey"
class="content"
:src="views[customerInfo.carModelId] || require('@/assets/images/media/nothing.webp')"
/>
</template>
<template v-else>
<template v-if="views">
<image
v-if="views.detailUrl"
class="content"
:src="views.detailUrl"
/>
<!-- <image
v-if="views.bgUrl"
class="bg"
:src="views.bgUrl"
/> -->
</template>
</template>
</view>
</template>
</wnCanvas>
</view>
</template>
<script type="text/ecmascript-6">
export default {
props: {
views: [Array, Object],
penSwitch: Boolean,
title: String,
madiaId: Number,
isByd: Boolean,
show: Boolean,
hasCarBrand: Boolean
},
components: {
},
name: 'MediaComponent',
data () {
return {
}
},
watch: {
},
computed: {
customerInfo () {
return this.$store.state.user.customerInfo
},
viewKey () {
return this.$store.state.user.viewKey
}
},
mounted () {
},
methods: {
}
}
</script>
<style scoped lang="scss">
.layout {
width: 100%;
height: 100%;
&-content {
height: 100%;
position: relative;
margin: $margin;
}
.content {
position: absolute;
width: 100%;
height: 100%;
z-index: 1;
}
.bg {
width: 100vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
}
}
</style>
...@@ -13,6 +13,17 @@ ...@@ -13,6 +13,17 @@
:loadComplete="loadComplete" :loadComplete="loadComplete"
> >
<template slot="detail"> <template slot="detail">
<detail
:id.sync="id"
:media="moduleList"
:type.sync="type"
:toolList="toolList"
:aitoCarModelIds="aitoCarModelIds"
@back="back"
@done="done"
ref="detail"
:mediaId="mediaId"
/>
</template> </template>
<template slot="content"> <template slot="content">
</template> </template>
...@@ -20,16 +31,58 @@ ...@@ -20,16 +31,58 @@
</view> </view>
</template> </template>
<script> <script>
import detail from './detail/detail'
import { mapMutations } from 'vuex' import { mapMutations } from 'vuex'
import HomeFrame from '@/components/HomeFrame/index.vue' import HomeFrame from '@/components/HomeFrame/index.vue'
// import storge from "@/mixin/storge"; // import storge from "@/mixin/storge";
export default { export default {
// mixins: [storge], // mixins: [storge],
components: { HomeFrame }, components: { HomeFrame, detail },
data () { data () {
return { return {
moduleList: [], moduleList:[
toolList: [], {
id: 6,
thumbnail: 'https://img02.glsx.com.cn/weapp/resource/app-tape/media/benz/6.webp',
title: '保修升级产品保障范围',
class: 'landscape',
style: 'width: calc(100vw * (1282 / 2346));height: calc(100vmin * (1173 / 768) * (304 / 2346));',
showAlt: false,
componentName: 'media-component',
detailTitle: '保修升级产品保障范围',
receptionSourceDetailList: [{
detailUrl: 'https://img02.glsx.com.cn/weapp/resource/app-tape/media/benz/page/6-1.webp',
}]
},
{
id: 2,
materialName: '素材2',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 3,
materialName: '素材3',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 4,
materialName: '素材4',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
},
{
id: 5,
materialName: '素材5',
materialUrl: 'https://seopic.699pic.com/photo/50073/0161.jpg_wh1200.jpg'
}
],
toolList: [
{
id: 6,
shortTitle: '保障范围',
title: '保修升级产品保障范围',
shortTitleUrl: 'https://img02.glsx.com.cn/weapp/resource/app-tape/tool/6.png'
}
],
id: '', id: '',
type: '', type: '',
chooseItem: {}, chooseItem: {},
...@@ -41,18 +94,6 @@ export default { ...@@ -41,18 +94,6 @@ export default {
} }
}, },
computed: { computed: {
channelType () {
const { channelType } = uni.$storage.get('userInfo')
return channelType || 1 //默认问界
},
shopMerchantId () {
const { shopMerchantId } = uni.$storage.get('userInfo')
return shopMerchantId
},
sceneType () {
const { sceneType } = uni.$storage.get('userInfo')
return 1
}
}, },
onBackPress (options) { onBackPress (options) {
if (options.from === 'backbutton') { if (options.from === 'backbutton') {
...@@ -76,14 +117,14 @@ export default { ...@@ -76,14 +117,14 @@ export default {
// this.$refs.home.updateApp(true) // this.$refs.home.updateApp(true)
}, },
async onShow () { async onShow () {
this.init() // this.init()
}, },
methods: { methods: {
...mapMutations('audio', ['setReceptionStatus']), ...mapMutations('audio', ['setReceptionStatus']),
init () { // init () {
// this.findPayInfo() // // this.findPayInfo()
if (this.requested && !this.id) this.$refs.home.updateApp() // if (this.requested && !this.id) this.$refs.home.updateApp()
}, // },
/**获取车型&销售数据 */ /**获取车型&销售数据 */
get_Vehicle_Sales_Data () { get_Vehicle_Sales_Data () {
const userInfo = uni.$storage.get('userInfo'), const userInfo = uni.$storage.get('userInfo'),
...@@ -141,23 +182,24 @@ export default { ...@@ -141,23 +182,24 @@ export default {
}, },
async start () { async start () {
if (!this.moduleList.length) return uni.showToast({ // if (!this.moduleList.length) return uni.showToast({
title: '该场景尚未配置素材,请联系总部人员', // title: '该场景尚未配置素材,请联系总部人员',
icon: 'none' // icon: 'none'
}) // })
const isPermision = await this.$refs.home.isPermission() // const isPermision = await this.$refs.home.isPermission()
if (this.recording || !isPermision) return // if (this.recording || !isPermision) return
uni.showLoading({ // uni.showLoading({
mask: true // mask: true
}) // })
this.$refs.home.startAudio() // this.$refs.home.startAudio()
this.clearHistory() // this.clearHistory()
this.id = this.moduleList[0].id // this.id = this.moduleList[0].id
this.id = 6
this.type = 'edit' this.type = 'edit'
this.recording = true this.recording = true
setTimeout(() => { // setTimeout(() => {
uni.hideLoading() // uni.hideLoading()
}, 1e3) // }, 1e3)
}, },
toDetail (index) { toDetail (index) {
let item = this.moduleList[index] let item = this.moduleList[index]
...@@ -200,7 +242,7 @@ export default { ...@@ -200,7 +242,7 @@ export default {
this.id = '' this.id = ''
this.type = '' this.type = ''
this.clearHistory() this.clearHistory()
this.init() // this.init()
this.recording = false this.recording = false
this.$refs.home.$refs.leftBox.getMessageInfo() this.$refs.home.$refs.leftBox.getMessageInfo()
}, },
...@@ -245,7 +287,7 @@ export default { ...@@ -245,7 +287,7 @@ export default {
this.$store.dispatch('setPaymentType', paymentType) this.$store.dispatch('setPaymentType', paymentType)
}, },
changeTab (index) { changeTab (index) {
if (index == 0) this.init() // if (index == 0) this.init()
}, },
/**按序加载车型 */ /**按序加载车型 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!