Commit d02c6104 by liimin

feat: 新增组件并优化现有功能

refactor(HomeFrame): 重构布局和动画性能
feat(ResultSelect): 新增接待结果选择组件
feat(CustomerTypeRadio): 新增客户类型单选组件
feat(ResultList): 新增结果列表组件
style(ButtonGroup): 优化按钮组样式和交互
perf(RecordList): 优化记录列表性能和数据格式化
refactor(FinishStep): 使用新组件重构完成步骤
perf(equity/detail): 优化滑动切换和渲染性能
refactor(equity/index): 优化数据获取和状态管理
refactor(saveRecord): 重构表单布局和验证逻辑
1 parent e01037b1
<template> <template>
<view class="button-group"> <view class="button-group">
<view <template v-for="(item, index) in selectList">
v-for="(item, index) in selectList" <view
:key="index" :key="index"
class="button-item" class="button-item"
:class="{ active: index === selectIndex }" :class="{ active: index === selectIndex }"
@click="chooseType(index, item)" @click="chooseType(index, item)"
:style="{ width: itemWidth + 'rpx', marginRight: index === selectList.length - 1 ? 0 : gap + 'rpx' }" :style="{ width: itemWidth + 'rpx' }"
> >
<text class="label">{{ item[labelKey] }}</text> <text class="label">{{ item[labelKey] }}</text>
<!-- 选中时的背景动画元素 --> <template v-if="item.dot && item.dot()">
<view class="active-bg" v-if="index === selectIndex"></view> <view class="dot"></view>
</view> </template>
<!-- 选中时的背景动画元素 -->
<view class="active-bg" v-if="index === selectIndex"></view>
</view>
<view class="divider" v-if="index < selectList.length - 1" :key="'divider-' + index"></view>
</template>
</view> </view>
</template> </template>
...@@ -30,8 +35,7 @@ export default { ...@@ -30,8 +35,7 @@ export default {
data() { data() {
return { return {
selectIndex: 0, selectIndex: 0,
itemWidth: 104, // 按钮固定宽度 itemWidth: 140, // 按钮固定宽度
gap: 16 // 按钮间距
} }
}, },
methods: { methods: {
...@@ -76,6 +80,17 @@ export default { ...@@ -76,6 +80,17 @@ export default {
z-index: 2; /* 文字在最上层 */ z-index: 2; /* 文字在最上层 */
} }
.dot {
position: absolute;
top: toRpx(8);
right: toRpx(16);
width: toRpx(12);
height: toRpx(12);
border-radius: 100%;
background: #f24724;
z-index: 3;
}
/* 激活状态的背景层 */ /* 激活状态的背景层 */
.active-bg { .active-bg {
position: absolute; position: absolute;
...@@ -95,6 +110,13 @@ export default { ...@@ -95,6 +110,13 @@ export default {
box-shadow: 0 toRpx(2) toRpx(8) rgba(55, 115, 248, 0.15); box-shadow: 0 toRpx(2) toRpx(8) rgba(55, 115, 248, 0.15);
} }
} }
.divider {
width: 1px;
height: toRpx(32);
background: #ebedf0;
margin: 0 toRpx(12);
}
} }
@keyframes pulse-fade { @keyframes pulse-fade {
......
<template>
<radio-group @change="handleChange" class="radio-group">
<template v-for="(item, index) in items">
<label class="radio" :key="index">
<radio :value="item.value" :checked="value == item.value" />
{{ item.label }}
</label>
</template>
</radio-group>
</template>
<script>
export default {
name: "CustomerTypeRadio",
props: {
value: {
type: [String, Number],
default: ''
},
items: {
type: Array,
default: () => [
{
label: "VIP",
value: 'VIP'
},
{
label: "潜客",
value: '潜客'
},
{
label: "普通",
value: '普通'
}
]
}
},
methods: {
handleChange(e) {
this.$emit('input', e.detail.value);
this.$emit('change', e);
}
}
}
</script>
<style scoped lang="scss">
.radio-group {
display: flex;
align-items: center;
height: 100%;
.radio {
display: flex;
align-items: center;
margin-right: toRpx(30);
}
}
</style>
...@@ -16,14 +16,7 @@ ...@@ -16,14 +16,7 @@
<input :type="i.inputType" :maxlength="i.maxlength" v-model="formData[i.key]" class="input" :placeholder="i.placeholder" :disabled="customerType == 0" @input="inputCustomer" placeholder-style="color:#c9c9c9;" /> <input :type="i.inputType" :maxlength="i.maxlength" v-model="formData[i.key]" class="input" :placeholder="i.placeholder" :disabled="customerType == 0" @input="inputCustomer" placeholder-style="color:#c9c9c9;" />
</template> </template>
<template v-else-if="i.type == 'radio'"> <template v-else-if="i.type == 'radio'">
<radio-group @change="radioChange"> <CustomerTypeRadio :value="formData[i.key]" @change="radioChange" />
<template v-for="(item, index) in i.items">
<label class="radio" :key="index">
<radio :value="item.value" :checked="formData[i.key] == item.value" />
{{ item.label }}
</label>
</template>
</radio-group>
</template> </template>
<!-- <template v-else> <!-- <template v-else>
<view <view
...@@ -46,14 +39,7 @@ ...@@ -46,14 +39,7 @@
</template> </template>
<template v-else> <template v-else>
<view class="pop-tips">请完善本次接待结果</view> <view class="pop-tips">请完善本次接待结果</view>
<view class="choose-box"> <ResultList :list="resultList" :value="receptionStatus" @change="chooseResult" />
<template v-for="(i, index) in resultList">
<view :class="['choose-item', `${i.status == receptionStatus ? (i.status == 1 ? 'success' : 'error') : ''}`]" :key="index" @click="chooseResult(i.status)">
<view :class="['sprite-icon', `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon}`]"></view>
{{ i.text }}
</view>
</template>
</view>
</template> </template>
</view> </view>
</MessageBox> </MessageBox>
...@@ -65,9 +51,15 @@ ...@@ -65,9 +51,15 @@
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
import { mapMutations } from "vuex"; import { mapMutations } from "vuex";
import ResultList from '@/components/ResultList.vue'
import CustomerTypeRadio from '@/components/CustomerTypeRadio.vue'
const phoneRex = /^[1]([2-9])[0-9]{9}$/; const phoneRex = /^[1]([2-9])[0-9]{9}$/;
export default { export default {
name: 'FinishStep', name: 'FinishStep',
components: {
ResultList,
CustomerTypeRadio
},
props: { props: {
sceneType: { sceneType: {
type: Number, type: Number,
...@@ -105,20 +97,6 @@ export default { ...@@ -105,20 +97,6 @@ export default {
label: "客户类型", label: "客户类型",
key: "customerType", key: "customerType",
type: "radio", type: "radio",
items: [
{
label: "VIP",
value: 'VIP'
},
{
label: "潜客",
value: '潜客'
},
{
label: "普通",
value: '普通'
}
],
placeholder: '请输入客户类型', placeholder: '请输入客户类型',
required: true required: true
}, },
...@@ -407,30 +385,4 @@ export default { ...@@ -407,30 +385,4 @@ export default {
} }
} }
} }
.choose-box {
display: flex;
flex-direction: column;
align-items: center;
.choose-item {
width: 100%;
height: toRpx(128);
border: toRpx(2) solid #e8e8e8;
border-radius: toRpx(16);
display: flex;
align-items: center;
justify-content: center;
margin-top: toRpx(24);
.sprite-icon {
margin-right: toRpx(16);
}
}
.success {
background: #14cc681a;
border-color: #14cc681a;
}
.error {
background: #f247241a;
border-color: #f247241a;
}
}
</style> </style>
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<view class="module-box box-class"> <view class="module-box box-class">
<view class="common-title"> <view class="common-title">
<text class="title-text"> <text class="title-text">
<text class="highlight-type">{{ currentType.typeName }}</text> <text class="highlight-type" @click="changeType">{{ currentType.typeName }}</text>
产品介绍 产品介绍
</text> </text>
<view class="switch-btn flex" @click="changeType"> <view class="switch-btn flex" @click="changeType">
......
...@@ -122,7 +122,7 @@ export default { ...@@ -122,7 +122,7 @@ export default {
]), ]),
uploadTypeList: Object.freeze([ uploadTypeList: Object.freeze([
{ label: '待上传' }, { label: '待上传' },
{ label: '待提交' }, { label: '待提交', dot: () => this.preRecordFailList.length },
]), ]),
itemObject: Object.freeze([ itemObject: Object.freeze([
// { label: '接待结果', key: 'result' }, // { label: '接待结果', key: 'result' },
...@@ -194,6 +194,7 @@ export default { ...@@ -194,6 +194,7 @@ export default {
item = { item = {
"id": null, "id": null,
"merchantId": "44210895", "merchantId": "44210895",
customerType: 'VIP',
"customerName": "1211第五", "customerName": "1211第五",
"phoneNumber": "13512110555", "phoneNumber": "13512110555",
"salesUuid": "77936e318e9844e4af0b099c7ccc98e4", "salesUuid": "77936e318e9844e4af0b099c7ccc98e4",
...@@ -287,11 +288,18 @@ export default { ...@@ -287,11 +288,18 @@ export default {
}, },
async getPreRecordNum () { async getPreRecordNum () {
const preRecordList = await this.recorder.getRecords() const preRecordList = await this.recorder.getRecords()
this.preRecordFailList = preRecordList this.preRecordFailList =this.formatRecordList(preRecordList)
//[{
// result: '',
// customerPhone: '',
// customerType: 'VIP',
// customerName: '',
// carType: '',
// startTime: '',
// endTime: '' }]
}, },
getRecordFail () { formatRecordList(list) {
this.getRecordNum() return list.map(record => {
this.list[0] = this.recordFailList.map(record => {
return { return {
result: record.result, result: record.result,
customerPhone: record.customerPhone, customerPhone: record.customerPhone,
...@@ -303,6 +311,10 @@ export default { ...@@ -303,6 +311,10 @@ export default {
endTime: record.endTime endTime: record.endTime
} }
}) })
},
getRecordFail () {
this.getRecordNum()
this.list[0] = this.formatRecordList(this.recordFailList)
this.flag = true this.flag = true
this.isPrePage = false this.isPrePage = false
this.nothing = !!this.recordFailList.length this.nothing = !!this.recordFailList.length
...@@ -396,24 +408,7 @@ export default { ...@@ -396,24 +408,7 @@ export default {
async submitRecord (val) { async submitRecord (val) {
this.flag = false this.flag = false
delete val.duration delete val.duration
delete val.startTime // delete val.startTime
const { maxUploadNum = 10 } = uni.$storage.get('mock_data')
if (val.recordUrlList.length > maxUploadNum) {
const userInfo = uni.$storage.get('userInfo')
const { customerName, phoneNumber, carModel, salesName } = val || {}
const { name } = userInfo || {}
uni.$logger.error({
msg: `员工: ${name}, 客户: ${customerName}`,
extra: {
'手机号: ': phoneNumber,
'姓名: ': customerName,
'销售: ': salesName,
'车型: ': carModel,
'原因: ': '录音文件过长,数量' + val.recordUrlList.length
}
})
}
val.recordUrlList = val.recordUrlList.slice(0, maxUploadNum)
await this.recorder.save(val) await this.recorder.save(val)
this.getRecordNum() this.getRecordNum()
await this.getPreRecordFail() await this.getPreRecordFail()
......
<template> <template>
<view class="container" @click="handleTouchStart"> <view class="container" @click="handleTouchStart">
<view :class="['home', { show: !id && showHome }]"> <view :class="['home', { show: !activeDetailId && showHome }]">
<left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" ref="leftBox" @changeTab="changeTab" @stopAudio="stopAudio" @showReadCountTips="showReadCountTips" @closeTips="closeTips" /> <left-side :userInfo="userInfo" :tabIndex.sync="tabIndex" ref="leftBox" @changeTab="changeTab" @stopAudio="stopAudio" @showReadCountTips="showReadCountTips" @closeTips="closeTips" />
<view class="tips-box" :style="tipsObject.style" @click.stop="closeTips">{{ tipsObject.text }}</view> <view class="tips-box" :style="tipsObject.style" @click.stop="closeTips">{{ tipsObject.text }}</view>
<view class="right-side"> <view class="right-side">
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
</view> </view>
<store-address v-if="footerBox" /> <store-address v-if="footerBox" />
</view> </view>
<view :class="['detail', { show: id }]"> <view :class="['detail', { show: activeDetailId }]">
<slot name="detail" /> <slot name="detail" />
</view> </view>
<view class="point-page" v-if="!showHome && !activeDetailId">
<component :is="pointComponentName" :transfer="transfer" @close="showHome = true" />
</view>
<!-- 未点击开始接待,弹窗 --> <!-- 未点击开始接待,弹窗 -->
<MessageBox ref="previewRef" @confirm="previewHandler('preview', true)" :popupW="704" content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」" confirmBtnText="预览素材" @cancel="previewHandler('previewCancel')" @close="previewHandler('previewClose')"></MessageBox> <MessageBox ref="previewRef" @confirm="previewHandler('preview', true)" :popupW="704" content="直接点击素材可进行预览,若面向车主展示,请点击「开始接待」" confirmBtnText="预览素材" @cancel="previewHandler('previewCancel')" @close="previewHandler('previewClose')"></MessageBox>
<finish-reception-dialog ref="finish" @confirm="$emit('openStep')" @cancel="$emit('backHome')" /> <finish-reception-dialog ref="finish" @confirm="$emit('openStep')" @cancel="$emit('backHome')" />
...@@ -37,14 +40,19 @@ import recorder from '@/mixin/record/recorder' ...@@ -37,14 +40,19 @@ import recorder from '@/mixin/record/recorder'
import uploader from '@/mixin/record/uploader.js' import uploader from '@/mixin/record/uploader.js'
import versionCheck from '@/mixin/versionCheck.js' import versionCheck from '@/mixin/versionCheck.js'
import LeftSide from './components/LeftSide.vue' import LeftSide from './components/LeftSide.vue'
import Material from '@/components/MaterialIndex.vue'
import HomeSlot from './components/HomeSlot.vue' import HomeSlot from './components/HomeSlot.vue'
import Order from './components/Order/index.vue' import Order from './components/Order/index.vue'
const TAB_COMPONENTS = {
1: 'ReceptionCenter',
2: 'Order'
}
export default { export default {
mixins: [recorder, uploader, timeout, versionCheck], mixins: [recorder, uploader, timeout, versionCheck],
components: { LeftSide, Material, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order }, components: { LeftSide, ReceptionCenter, FinishReceptionDialog, StoreAddress, HomeSlot, Order },
props: { props: {
id: [String, Number], activeDetailId: [String, Number],
finishDoneText: String, finishDoneText: String,
finishContene: { finishContene: {
type: String, type: String,
...@@ -97,8 +105,7 @@ export default { ...@@ -97,8 +105,7 @@ export default {
return this.$refs.finish return this.$refs.finish
}, },
componentName() { componentName() {
let tabs = this.$refs.leftBox?.tabs return TAB_COMPONENTS[this.tabIndex] || ''
return tabs ? tabs[this.tabIndex].name : ''
} }
}, },
methods: { methods: {
...@@ -161,6 +168,7 @@ export default { ...@@ -161,6 +168,7 @@ export default {
text-align: left; text-align: left;
display: none; display: none;
opacity: 0; opacity: 0;
will-change: opacity, display; // 优化动画性能
} }
&::after { &::after {
...@@ -173,10 +181,10 @@ export default { ...@@ -173,10 +181,10 @@ export default {
background-image: url('@/assets/images/common/home-bg-1.webp'); background-image: url('@/assets/images/common/home-bg-1.webp');
background-size: 100% 100%; background-size: 100% 100%;
z-index: 1; z-index: 1;
pointer-events: none; // 避免背景图阻挡交互
} }
.home, .home {
.detail {
position: fixed; position: fixed;
width: 100%; width: 100%;
height: 100%; height: 100%;
...@@ -185,6 +193,29 @@ export default { ...@@ -185,6 +193,29 @@ export default {
left: 0; left: 0;
visibility: hidden; visibility: hidden;
opacity: 0; opacity: 0;
will-change: opacity, visibility; // 提示浏览器提前优化
// 使用3D加速,避免重绘
transform: translateZ(0);
}
.detail {
position: fixed;
width: 100vw;
height: 100vh;
left: 0;
top: 0;
z-index: -1;
visibility: hidden;
transform: translateX(100%);
transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), visibility 0.5s;
will-change: transform, visibility; // 提示浏览器提前优化
&.show {
z-index: 2;
visibility: visible;
transform: translateX(0);
}
} }
.point-page { .point-page {
...@@ -250,41 +281,44 @@ export default { ...@@ -250,41 +281,44 @@ export default {
z-index: 2; z-index: 2;
visibility: visible; visibility: visible;
animation: show-content-left 0.15s forwards; animation: show-content-left 0.15s forwards;
will-change: transform;
} }
} }
@keyframes show-content-left { @keyframes show-content-left {
0% { 0% {
left: 100%; transform: translateX(100%);
} }
100% { 100% {
left: 0; transform: translateX(0);
} }
} }
.right-side { .right-side {
flex: 1; flex: 1;
position: relative;
width: calc(100vw - #{toRpx(240)});
.right-content {
height: 100vh;
box-sizing: border-box;
position: relative; position: relative;
animation: show-box 0.15s forwards; width: calc(100vw - #{toRpx(240)});
overflow: hidden; contain: layout style; // 限制样式和布局计算范围
}
@keyframes show-box { .right-content {
0% { height: 100vh;
left: 100%; box-sizing: border-box;
position: relative;
animation: show-box 0.15s forwards;
overflow: hidden;
will-change: transform; // 优化动画
} }
100% { @keyframes show-box {
left: 0; 0% {
transform: translateX(100%);
}
100% {
transform: translateX(0);
}
} }
}
.start { .start {
height: toRpx(232); height: toRpx(232);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
:type="position" :type="position"
:is-mask-click="false" :is-mask-click="false"
:animation="animation" :animation="animation"
:mask-background-color="maskBackgroundColor"
> >
<view <view
class="tips-wrapper" class="tips-wrapper"
...@@ -111,6 +112,10 @@ export default { ...@@ -111,6 +112,10 @@ export default {
showCancelBtn: { showCancelBtn: {
type: Boolean, type: Boolean,
default: true, default: true,
},
maskBackgroundColor: {
type: String,
default: 'rgba(0, 0, 0, 0.4)'
} }
}, },
methods: { methods: {
...@@ -135,8 +140,10 @@ export default { ...@@ -135,8 +140,10 @@ export default {
<style scoped lang="scss"> <style scoped lang="scss">
.tips-wrapper { .tips-wrapper {
background: #ffffff; background: #ffffff;
border-radius: toRpx(20); border-radius: toRpx(24);
height: 100%; height: 100%;
box-shadow: 0 toRpx(12) toRpx(48) rgba(0, 0, 0, 0.16), 0 toRpx(4) toRpx(16) rgba(0, 0, 0, 0.08);
border: 1px solid rgba(0, 0, 0, 0.06);
.tips-content { .tips-content {
padding: toRpx(48); padding: toRpx(48);
box-sizing: border-box; box-sizing: border-box;
......
<template>
<view class="choose-box">
<template v-for="(i, index) in list">
<view :class="['choose-item', `${i.status == value ? (i.status == '完成' || i.status == 1 ? 'success' : 'error') : ''}`]" :key="index" @click="chooseResult(i.status)">
<view :class="['sprite-icon', `icon-face-${i.status == value ? `${i.icon}-active` : i.icon}`]"></view>
{{ i.text }}
</view>
</template>
</view>
</template>
<script>
export default {
name: "ResultList",
props: {
list: {
type: Array,
default: () => []
},
value: {
type: [String, Number],
default: -1
}
},
methods: {
chooseResult(val) {
this.$emit('input', val);
this.$emit('change', val);
}
}
}
</script>
<style scoped lang="scss">
.choose-box {
display: flex;
flex-direction: column;
align-items: center;
.choose-item {
width: 100%;
height: toRpx(128);
border: toRpx(2) solid #e8e8e8;
border-radius: toRpx(16);
display: flex;
align-items: center;
justify-content: center;
margin-top: toRpx(24);
.sprite-icon {
margin-right: toRpx(16);
}
}
.success {
background: #14cc681a;
border-color: #14cc681a;
}
.error {
background: #f247241a;
border-color: #f247241a;
}
}
</style>
<template>
<MessageBox ref="popup" title="接待结果" :popupW="704" :isFooter="false" :maskBackgroundColor="maskBackgroundColor">
<ResultList :list="list" :value="value" @change="handleChange" />
</MessageBox>
</template>
<script>
import ResultList from './ResultList.vue'
export default {
name: "ResultSelect",
components: {
ResultList
},
props: {
list: {
type: Array,
default: () => [
{
icon: 'success',
text: '结果完美,成交了',
status: "完成"
},
{
icon: 'error',
text: '仍需努力,战败了',
status: "未完成"
}
]
},
value: {
type: [String, Number],
default: -1
},
maskBackgroundColor: {
type: String,
default: 'rgba(0, 0, 0, 0.4)'
}
},
methods: {
open() {
this.$refs.popup.open()
},
close() {
this.$refs.popup.close()
},
handleChange(val) {
this.$emit('input', val);
this.$emit('change', val);
}
}
}
</script>
...@@ -377,7 +377,12 @@ export default { ...@@ -377,7 +377,12 @@ export default {
try { try {
if (str && (str.includes('=') || str.length > 50)) { if (str && (str.includes('=') || str.length > 50)) {
const decrypted = decryptAES(str) const decrypted = decryptAES(str)
if (decrypted) return decrypted if (decrypted) {
if (label == 'Region' && decrypted.includes('.')) {
decrypted = decrypted.split('.')[0]
}
}
return decrypted
} }
} catch (e) { } catch (e) {
console.error(`${label} decryption error`, e) console.error(`${label} decryption error`, e)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* @Author: huyue * @Author: huyue
* @Date: 2024-04-08 11:30:30 * @Date: 2024-04-08 11:30:30
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2025-12-29 08:46:10 * @LastEditTime: 2025-12-29 11:40:42
--> -->
<template> <template>
<view class="detail-box" :key="dateilKey"> <view class="detail-box" :key="dateilKey">
...@@ -13,9 +13,12 @@ ...@@ -13,9 +13,12 @@
</view> </view>
</view> </view>
<template v-for="(item, index) in moduleList"> <template v-for="(item, index) in moduleList">
<view :class="['view', getViewClass(item)]" :key="index" @touchstart.stop="touchStart" <view :class="['view', getViewClass(item)]" :style="{ 'animation-duration': swipeConfig.animDuration + 'ms' }" :key="index" @touchstart.stop="touchStart"
@touchend.stop="touchEnd"> @touchend.stop="touchEnd">
<component @full="handleFull" :detail="item" :is="item.componentName" <!-- 优化:仅渲染当前页、上一页、下一页,减少DOM节点 -->
<component
v-if="shouldRender(item)"
@full="handleFull" :detail="item" :is="item.componentName"
:views="item.receptionSourceDetailList || []" :penSwitch="penSwitch" :show="id == item.id" :views="item.receptionSourceDetailList || []" :penSwitch="penSwitch" :show="id == item.id"
:ref="'media' + item.id" :title="item.materialName || ''" :madiaId="item.id" @scale="scale" :ref="'media' + item.id" :title="item.materialName || ''" :madiaId="item.id" @scale="scale"
:ulList="item.ulList" :screenList="item.screenList" @onProductModel="productModelStatus = $event" :ulList="item.ulList" :screenList="item.screenList" @onProductModel="productModelStatus = $event"
...@@ -412,38 +415,42 @@ export default { ...@@ -412,38 +415,42 @@ export default {
}, },
touchEnd(e) { touchEnd(e) {
if (this.modeName || this.isAnimating) return if (this.modeName || this.isAnimating) return
try {
let { pageToolList, drawStatus, startX, screenWidth, id, scaleValueObject, productModelStatus } = this const { pageToolList, drawStatus, startX, screenWidth, id, scaleValueObject, productModelStatus } = this
if (!e || !e.changedTouches || drawStatus || pageToolList.length == 0 || e.changedTouches.length === 0) return // 快速前置检查
if (!e?.changedTouches?.length || drawStatus || !pageToolList.length) return
let touch = e.changedTouches[0]
let diffX = touch.pageX - startX const touch = e.changedTouches[0]
const diffX = touch.pageX - startX
let isDistanceSignificant = Math.abs(diffX) > screenWidth / this.swipeConfig.sensitivity
let index = pageToolList.findIndex(item => item.id == id) // 垂直滑动过大则忽略水平滑动,避免误触
if (Math.abs(this.startY - touch.pageY) > this.swipeConfig.verticalLimit) return
if (Math.abs(this.startY - touch.pageY) > this.swipeConfig.verticalLimit) return
if (!scaleValueObject[id]) scaleValueObject[id] = 1 // 距离检查
if (Math.abs(diffX) <= screenWidth / this.swipeConfig.sensitivity) return
if (isDistanceSignificant && index != -1 && scaleValueObject[id] == 1 && !productModelStatus) {
const isNext = diffX < 0 const index = pageToolList.findIndex(item => item.id == id)
if (index === -1) return
let nextIndex
if (isNext) { // 缩放状态或打开产品弹窗时不切换
nextIndex = index === pageToolList.length - 1 ? 0 : index + 1 if ((scaleValueObject[id] && scaleValueObject[id] !== 1) || productModelStatus) return
this.pendingDirection = 'next'
} else { const isNext = diffX < 0
nextIndex = index === 0 ? pageToolList.length - 1 : index - 1 let nextIndex
this.pendingDirection = 'prev' if (isNext) {
} nextIndex = index === pageToolList.length - 1 ? 0 : index + 1
this.pendingDirection = 'next'
const nextItem = pageToolList[nextIndex] } else {
this.$emit('update:id', nextItem.id) nextIndex = index === 0 ? pageToolList.length - 1 : index - 1
uni.$logger.local.info(`预览${nextItem.title}`) this.pendingDirection = 'prev'
}
} catch (error) {
console.log(error)
} }
const nextItem = pageToolList[nextIndex]
// 使用 nextTick 确保状态更新
this.$nextTick(() => {
this.$emit('update:id', nextItem.id)
})
uni.$logger.local.info(`预览${nextItem.title}`)
}, },
getViewClass(item) { getViewClass(item) {
const isCurrent = item.id == this.id const isCurrent = item.id == this.id
...@@ -502,6 +509,29 @@ export default { ...@@ -502,6 +509,29 @@ export default {
this.$emit('update:id', jumpItem ? jumpItem.id : moduleList[0].id) this.$emit('update:id', jumpItem ? jumpItem.id : moduleList[0].id)
} }
this.currentMediaId = id this.currentMediaId = id
},
// 判断是否应该渲染该组件(性能优化)
shouldRender(item) {
// 如果列表很短,直接全部渲染
if (this.moduleList.length <= 3) return true
const currentIndex = this.moduleList.findIndex(i => i.id == this.id)
if (currentIndex === -1) return false
const targetIndex = this.moduleList.findIndex(i => i.id == item.id)
// 渲染当前页
if (currentIndex === targetIndex) return true
// 渲染上一页(考虑循环)
const prevIndex = currentIndex === 0 ? this.moduleList.length - 1 : currentIndex - 1
if (prevIndex === targetIndex) return true
// 渲染下一页(考虑循环)
const nextIndex = currentIndex === this.moduleList.length - 1 ? 0 : currentIndex + 1
if (nextIndex === targetIndex) return true
return false
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!