Commit c2ab0051 by liimin

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

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