Commit 65ae4a86 by chenwq1

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

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