Commit c2ab0051 by liimin

perf(equity): 优化权益详情页性能

- 使用 swiper 组件替换 ModuleSwipeStack 提升滑动性能
- 添加横竖屏适配功能,根据屏幕方向动态调整图片显示模式
- 实现图片懒加载和错误处理机制
- 优化组件引用类型定义,提升类型安全性
- 移除废弃的调试代码和注释
- 重构 CSS 样式提高渲染效率
1 parent 802c492e
......@@ -83,6 +83,9 @@
onMounted(() => {
const systemInfo = uni.getSystemInfoSync();
screenWidth.value = systemInfo.screenWidth;
setTimeout(() => {
console.log(111111111111,props.items)
}, 5000);
});
/** 与 gl_tape 一致:500ms 后清 modeName(仅用于内部方向状态,动效由 un-transition 承担) */
......@@ -169,7 +172,7 @@
isTouching.value = true;
touchDiffX.value = 0;
console.log('[ModuleSwipeStack] 起始位置:', { startX: startX.value, startY: startY.value });
// 记录是否在左侧边缘区域(前 50px)
if (startX.value < 50) {
console.log('[ModuleSwipeStack] 在左侧边缘区域,允许右滑返回检测');
......@@ -265,7 +268,7 @@
const endY = touch.clientY != null ? touch.clientY : 0;
const diffX = endX - startX.value;
const diffY = endY - startY.value;
console.log('[ModuleSwipeStack] 滑动数据:', {
startX: startX.value,
startY: startY.value,
......
<template>
<view class="reception">
<scroll-view class="reception-scroll"
:scroll-y="true">
<un-image :src="getViewImageUrl()"
class="reception-image"
width="100%"
height="100%"
>
</un-image>
</scroll-view>
<!-- ✅ 性能优化:根据横竖屏动态切换图片模式 -->
<view :class="containerClass" :style="containerStyle">
<image :src="getViewImageUrl()"
class="reception-image"
:mode="imageMode"
@error="onImageError"
@load="onImageLoad" />
</view>
</template>
<script setup lang="uts">
import { state } from "@/store/index.uts";
import { computed, type ComputedRef } from "vue";
import { useOrientation } from "@/services/adapter/hooks/useOrientation.uts";
const props = defineProps({
views: {
......@@ -23,6 +22,33 @@
show: Boolean
});
// ✅ 横竖屏检测
const orientation = useOrientation();
const isPortrait = orientation.isPortrait as ComputedRef<boolean>;
// ✅ 根据横竖屏动态切换图片模式
// 横屏:aspectFill 铺满全屏(可能裁剪)
// 竖屏:widthFix 保持比例不变形
const imageMode = computed((): string => {
return isPortrait.value ? "widthFix" : "aspectFill";
});
// ✅ 根据横竖屏动态设置容器样式类
const containerClass = computed((): string => {
return isPortrait.value ? "reception reception-portrait" : "reception reception-landscape";
});
// ✅ 竖屏时动态计算容器高度
const containerStyle = computed((): UTSJSONObject => {
if (isPortrait.value) {
// 竖屏:不设置固定高度,让内容自适应
return {} as UTSJSONObject;
} else {
// 横屏:固定高度 100%
return { height: "100%" } as UTSJSONObject;
}
});
function getStringValue(value: any | null): string {
if (value != null && typeof value === "string") {
const str = value as string;
......@@ -162,23 +188,49 @@ function getPreferredObjectImage(obj: UTSJSONObject): string {
}
return "";
}
/** ✅ 性能优化:图片加载失败处理 */
function onImageError(e: any): void {
console.warn('[Reception] 图片加载失败:', e);
}
/** ✅ 调试:图片加载成功后输出尺寸 */
function onImageLoad(e: any): void {
const detail = (e as UTSJSONObject).detail as UTSJSONObject;
const width = detail.width as number;
const height = detail.height as number;
console.log('[Reception] 图片加载成功 - 模式:', imageMode.value, ', 尺寸:', width, 'x', height, ', 横竖屏:', isPortrait.value ? '竖屏' : '横屏');
}
</script>
<style lang="scss">
// ✅ 基础样式
.reception {
width: 100% !important;
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
background-color: #f5f5f5;
// ✅ 禁止滚动
overflow: hidden;
}
// ✅ 横屏:固定高度 100%,图片铺满
.reception-landscape {
align-items: stretch;
justify-content: stretch;
}
.reception-scroll {
flex: 1;
width: 100%;
height: 0;
min-height: 0;
// ✅ 竖屏:高度自适应图片内容,靠顶部对齐
.reception-portrait {
align-items: center;
justify-content: flex-start;
}
.reception-image {
width: 100%;
width: 100% !important;
// ✅ height 由 mode 动态控制
// aspectFill: 横屏铺满全屏(height: 100%)
// widthFix: 竖屏宽度铺满,高度自适应(height: auto)
height: auto;
display: block;
}
</style>
......@@ -11,23 +11,21 @@
:z-index="backZindex"
left-icon-color="#ffffff"
@leftClick="back" />
<!-- 模块滑动栈 -->
<ModuleSwipeStack v-model:current-id="id"
:draw-status="drawStatus"
:items="moduleList"
:product-model-status="productModelStatus"
:scale-value-object="scaleValueObject"
:tool-items="pageToolList"
@swipeBack="handleSwipeBack"
>
<template #item="{ item, active }">
<template v-if="(item as UTSJSONObject).componentName == 'reception'">
<Reception :show="active"
:title="title"
:views="(item as UTSJSONObject).receptionSourceDetailList" />
</template>
</template>
</ModuleSwipeStack>
<!-- ✅ 性能优化:使用 swiper 组件 -->
<swiper class="module-swipe-container"
:current="currentModuleIndex"
:duration="300"
:circular="true"
@change="onSwiperChange">
<swiper-item v-for="(item, index) in moduleList"
:key="(item as UTSJSONObject).id"
class="module-slide-item">
<!-- ✅ 预渲染所有模块 -->
<Reception v-if="(item as UTSJSONObject).componentName == 'reception'"
:title="title"
:views="(item as UTSJSONObject).receptionSourceDetailList" />
</swiper-item>
</swiper>
<template v-if="type != 'preview'">
<template v-if="backZindex">
<ToolBox :id="id"
......@@ -137,15 +135,18 @@ const type = ref<string>("");
const media = ref<Array<any>>([]);
const toolList = ref<Array<any>>([]);
const paymentTypeList = ref<Array<any>>([]);
const toolRef = ref(null);
const payRef = ref(null);
const stepRef = ref(null);
const backpressRef = ref(null);
const toolRef = ref<ComponentPublicInstance | null>(null);
const payRef = ref<ComponentPublicInstance | null>(null);
const stepRef = ref<ComponentPublicInstance | null>(null);
const backpressRef = ref<ComponentPublicInstance | null>(null);
// 用于存储动态ref 的对象
const mediaRefs = ref<UTSJSONObject>({});
const showForceExitModal = ref<boolean>(false);
// ✅ 性能优化:当前模块索引,用于控制横向滑动
const currentModuleIndex = ref<number>(0);
// 设置动态 ref 的函数
const setMediaRef = (id: number | string, component: any): void => {
if (component != null) {
......@@ -568,8 +569,21 @@ watch(watchStatus, () => {
watch(id, () => {
ensurePageToolList();
// ✅ 性能优化:同步更新当前模块索引
syncModuleIndex();
}, { immediate: true });
/** ✅ 性能优化:根据 id 同步 currentModuleIndex */
function syncModuleIndex(): void {
const list = moduleList.value;
for (let i = 0; i < list.length; i++) {
if ((list[i] as UTSJSONObject).id == id.value) {
currentModuleIndex.value = i;
return;
}
}
}
watch(moduleList, (list: Array<any>) => {
ensurePageToolList();
}, { deep: true, immediate: true });
......@@ -827,7 +841,18 @@ function scale(e: number) {
scaleValueObject.value[id.value] = e;
}
/** ✅ 性能优化:swiper 切换时更新当前模块 */
function onSwiperChange(e: any): void {
const detail = (e as UTSJSONObject).detail as UTSJSONObject;
const newIndex = detail.current as number;
if (newIndex >= 0 && newIndex < moduleList.value.length) {
const newItem = moduleList.value[newIndex] as UTSJSONObject;
const newId = newItem.id as string;
if (newId != id.value) {
id.value = newId;
}
}
}
// Android 返回键和导航栏返回按钮
......@@ -858,6 +883,23 @@ onBackPress((options: OnBackPressOptions) => {
height: 100%;
margin: 0 auto;
}
/* ✅ 性能优化:swiper 横向滑动容器 */
.module-swipe-container {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.module-slide-item {
width: 100% !important;
height: 100% !important;
display: flex;
flex-direction: column;
}
.pen-box {
position: fixed;
right: 20px;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!