Commit f0014bab by chenwq1

refactor(boutique): update swiper event handling for improved type safety

- Changed the type of the onSwiperChange event handler to UniSwiperChangeEvent for better type checking
- Simplified the onSwiperChange function to directly access the current index from the event detail
- Updated parseSwiperEventIndex function to handle different event types more effectively
1 parent 05f4c1c3
...@@ -27,7 +27,7 @@ export type BoutiqueLogic = { ...@@ -27,7 +27,7 @@ export type BoutiqueLogic = {
clearHistory: () => void; clearHistory: () => void;
jumpPage: (homeFrameRef: any, pid: string) => void; jumpPage: (homeFrameRef: any, pid: string) => void;
chooseCustomerType: (homeFrameRef: any, index: number) => void; chooseCustomerType: (homeFrameRef: any, index: number) => void;
onSwiperChange: (e: any) => void; onSwiperChange: (e: UniSwiperChangeEvent) => void;
onChangeTab: (index: number) => void; onChangeTab: (index: number) => void;
initIfNeeded: () => Promise<void>; initIfNeeded: () => Promise<void>;
getBoutiquePackageList: () => Promise<void>; getBoutiquePackageList: () => Promise<void>;
...@@ -146,15 +146,8 @@ export function useBoutiqueLogic(): BoutiqueLogic { ...@@ -146,15 +146,8 @@ export function useBoutiqueLogic(): BoutiqueLogic {
} }
}; };
const onSwiperChange = (e: any): void => { const onSwiperChange = (e: UniSwiperChangeEvent): void => {
if (e == null) return; currentSwiperIndex.value = e.detail.current;
const eventObj = e as UTSJSONObject;
const detail = eventObj["detail"] as null | UTSJSONObject;
if (detail == null) return;
const currentValue = detail["current"];
if (typeof currentValue === "number") {
currentSwiperIndex.value = currentValue;
}
}; };
const initIfNeeded = async (): Promise<void> => { const initIfNeeded = async (): Promise<void> => {
...@@ -362,4 +355,3 @@ export function useBoutiqueLogic(): BoutiqueLogic { ...@@ -362,4 +355,3 @@ export function useBoutiqueLogic(): BoutiqueLogic {
ensureLoginOrRelauch: ensureLoginOrRelauch ensureLoginOrRelauch: ensureLoginOrRelauch
}; };
} }
...@@ -393,33 +393,17 @@ function toPreview(item: any): void { ...@@ -393,33 +393,17 @@ function toPreview(item: any): void {
uni.navigateTo({ url: `/pages/equity/detail/index?id=${id}&type=preview` }); uni.navigateTo({ url: `/pages/equity/detail/index?id=${id}&type=preview` });
} }
function parseSwiperEventIndex(e: any): number { function parseSwiperEventIndex(e: number | UniSwiperChangeEvent | null): number {
if (e == null) { if (e == null) {
return 0; return 0;
} }
if (typeof e === "number") { if (typeof e === "number") {
return e as number; return e as number;
} }
const o = e as UTSJSONObject; return e.detail.current;
const top = o["current"];
if (typeof top === "number") {
return top as number;
}
const idx = o["index"];
if (typeof idx === "number") {
return idx as number;
}
const detail = o["detail"] as UTSJSONObject | null;
if (detail != null) {
const dc = detail["current"];
if (typeof dc === "number") {
return dc as number;
}
}
return 0;
} }
function onSwiperChange(e: any): void { function onSwiperChange(e: UniSwiperChangeEvent): void {
currentSwiperIndex.value = parseSwiperEventIndex(e); currentSwiperIndex.value = parseSwiperEventIndex(e);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!