shukeSelectStoreNav.uts
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { apiShukeStoreList } from "@/api/user-api.uts";
import { storage } from "@/utils/storage.uts";
import { hideNativeTabBar } from "@/utils/tabBarShell.uts";
/** 选店页非 tabBar,统一 reLaunch;门店列表只依赖 pendingShukeStores,勿在 URL 上挂整段 JSON */
const SELECT_STORE_PAGE_URL = "/pages/common/selectStore/index";
function reLaunchSelectStoreWithStores(stores: any[]): void {
// 存储门店列表(storage.set 会自动处理序列化)
storage.set("pendingShukeStores", stores, 0);
uni.reLaunch({
url: SELECT_STORE_PAGE_URL,
success: (): void => {
hideNativeTabBar();
},
fail: (err: any): void => {
const msg = err != null ? `${err}` : "打开选店失败";
uni.showToast({ title: msg, icon: "none" });
}
});
}
/** 登录成功后进入选店页(从非 tab 栈打开,reLaunch + pending) */
export function switchTabSelectStoreWithStoresPayload(stores: any[]): void {
reLaunchSelectStoreWithStores(stores);
}
/**
* 与 simgle_app 侧栏切换门店:会话拉门店列表,`reLaunch` + pending。
* 确认门店凭据由选店页 `readLoginFormForSelectStore`(loginForm 或 `shukeLastConfirmForm`)提供。
*/
export async function navigateToSelectStoreWithSessionStores(): Promise<void> {
const spRaw = storage.get("shukeSpCode") as string | null;
const spCode = spRaw != null ? spRaw : "";
const storeListRes = await apiShukeStoreList({
spCode
} as UTSJSONObject);
if (storeListRes == null) {
throw new Error("获取门店列表失败");
}
const storeCodeRaw = storeListRes["code"] as number | string | null;
if (storeCodeRaw != null && `${storeCodeRaw}` === "500") {
const sm =
(storeListRes["msg"] as string | null) != null
? `${storeListRes["msg"]}`
: "获取门店列表失败";
throw new Error(sm);
}
const storeData = storeListRes["data"] as UTSJSONObject | null;
const stores = storeData != null ? (storeData["stores"] as any[] | null) : null;
if (stores == null || stores.length == 0) {
throw new Error("暂无门店信息,请联系管理员");
}
reLaunchSelectStoreWithStores(stores);
}