Commit 65ae4a86 by chenwq1

refactor: 更新组件逻辑以提升可读性和性能

- 修改多个组件的状态管理,使用更简洁的计算属性
- 重构滑动组件的逻辑,优化数据获取方式
- 更新条件渲染逻辑,确保在不同状态下的正确显示
- 调整样式条件,提升用户交互体验
1 parent 733c8a6e
......@@ -3,7 +3,7 @@
"configurations" : [
{
"customPlaygroundType" : "local",
"playground" : "custom",
"playground" : "standard",
"type" : "uni-app:app-android"
},
{
......
......@@ -24,30 +24,30 @@
@change="onPackageSwiperChange"
@click="onPackageSwiperClick"
/>
<view v-if="currentPackageItem != null" class="package-swiper-overlay">
<view v-if="hasCurrentPackageOverlay" class="package-swiper-overlay">
<view class="swiper-name">
{{ logic.getPkg(currentPackageItem, "name") }}
{{ overlayGet("name") }}
</view>
<view class="swiper-content-box">
<view class="price price-1">
<text class="price-label">市场价</text>
<view class="num">
<text class="unit">¥</text>
<text>{{ logic.getPkg(currentPackageItem, "marketPrice") }}</text>
<text>{{ overlayGet("marketPrice") }}</text>
</view>
</view>
<view class="price price-2">
{{ logic.getPkg(currentPackageItem, "discountPrice") }}
{{ overlayGet("discountPrice") }}
</view>
<view class="price price-3">
<text class="price-label">套餐价</text>
<view class="num">
<text class="unit">¥</text>
<text>{{ logic.getPkg(currentPackageItem, "packagePrice") }}</text>
<text>{{ overlayGet("packagePrice") }}</text>
</view>
</view>
<view class="briefIntroduction">
{{ logic.getPkg(currentPackageItem, "briefIntroduction") }}
{{ overlayGet("briefIntroduction") }}
</view>
</view>
<view class="swiper-btn" @click="toDetailCurrent">
......@@ -151,15 +151,29 @@ const packageSwiperUrls = computed((): string[] => {
return out;
});
const currentPackageItem = computed((): any | null => {
const hasCurrentPackageOverlay = computed((): boolean => {
const list = logic.packageList.value;
const idx = logic.currentSwiperIndex.value;
if (idx >= 0 && idx < list.length) {
return list[idx];
}
return null;
return list.length > 0 && idx >= 0 && idx < list.length;
});
function overlayGet(key: string): string {
const list = logic.packageList.value;
const idx = logic.currentSwiperIndex.value;
if (idx < 0 || idx >= list.length) {
return "";
}
const item = list[idx];
if (item == null) {
return "";
}
const v = logic.getPkg(item, key);
if (v == null) {
return "";
}
return `${v}`;
}
function parsePackageSwiperIndex(e: any): number {
if (e == null) {
return 0;
......@@ -190,14 +204,6 @@ function onPackageSwiperChange(e: any): void {
logic.currentSwiperIndex.value = parsePackageSwiperIndex(e);
}
function onPackageSwiperClick(e: any): void {
toDetail(parsePackageSwiperIndex(e));
}
function toDetailCurrent(): void {
toDetail(logic.currentSwiperIndex.value);
}
const homeRef = ref(null);
const customerTypeRef = ref(null);
const packageRef = ref(null);
......@@ -227,6 +233,14 @@ function toDetail(index: number): void {
}
}
function onPackageSwiperClick(e: any): void {
toDetail(parsePackageSwiperIndex(e));
}
function toDetailCurrent(): void {
toDetail(logic.currentSwiperIndex.value);
}
function closePackageDetail(): void {
logic.chooseItem.value = {};
}
......
......@@ -25,12 +25,12 @@
@change="onSwiperChange"
@click="onEquitySwiperClick"
/>
<view v-if="equityCurrentModule != null" class="equity-swiper-overlay">
<view v-if="hasEquityOverlay()" class="equity-swiper-overlay">
<text class="swiper-name">
{{ getModuleName(equityCurrentModule) }}
{{ equityOverlayName() }}
</text>
<text class="swiper-desc">
{{ getModuleDesc(equityCurrentModule) }}
{{ equityOverlayDesc() }}
</text>
</view>
</view>
......@@ -82,25 +82,6 @@ const currentSwiperIndex = ref<number>(0);
const EQUITY_SWIPER_PLACEHOLDER = "/static/images/login/nothing.webp";
const equitySwiperUrls = computed((): string[] => {
const list = moduleList.value;
const out: string[] = [];
for (let i = 0; i < list.length; i++) {
const cover = getModuleCover(list[i]);
out.push(cover != "" ? cover : EQUITY_SWIPER_PLACEHOLDER);
}
return out;
});
const equityCurrentModule = computed((): any | null => {
const list = moduleList.value;
const idx = currentSwiperIndex.value;
if (idx >= 0 && idx < list.length) {
return list[idx];
}
return null;
});
function normalizeModuleItem(item: any): UTSJSONObject {
const obj = item as UTSJSONObject;
const detailTitle =
......@@ -321,18 +302,56 @@ function getToolCoverById(moduleId: any | null): string {
return "";
}
function getModuleCover(item: any): string {
const obj = item as UTSJSONObject;
const value = pickModuleCover(obj);
if (value != null && value != "") {
return value;
const equitySwiperUrls = computed((): string[] => {
const list = moduleList.value;
const out: string[] = [];
for (let i = 0; i < list.length; i++) {
const obj = list[i] as UTSJSONObject;
let cover = pickModuleCover(obj);
if (cover == null || cover == "") {
const receptionCover = getReceptionCover(obj);
if (receptionCover != "") {
cover = receptionCover;
} else {
const moduleId: any | null = obj.id;
cover = getToolCoverById(moduleId);
}
}
out.push(cover != "" ? cover : EQUITY_SWIPER_PLACEHOLDER);
}
const receptionCover = getReceptionCover(obj);
if (receptionCover != "") {
return receptionCover;
return out;
});
function hasEquityOverlay(): boolean {
const list = moduleList.value;
const idx = currentSwiperIndex.value;
return list.length > 0 && idx >= 0 && idx < list.length;
}
function equityOverlayName(): string {
const list = moduleList.value;
const idx = currentSwiperIndex.value;
if (idx < 0 || idx >= list.length) {
return "";
}
const item = list[idx];
if (item == null) {
return "";
}
return getModuleName(item);
}
function equityOverlayDesc(): string {
const list = moduleList.value;
const idx = currentSwiperIndex.value;
if (idx < 0 || idx >= list.length) {
return "";
}
const item = list[idx];
if (item == null) {
return "";
}
const moduleId: any | null = obj.id;
return getToolCoverById(moduleId);
return getModuleDesc(item);
}
function getCurrentModuleTitle(): string {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!