chore: import WonderQ project
This commit is contained in:
commit
f5a9e4403a
452 files changed
+34173
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { productKey } from "./data";
|
||||
import { requireLogin } from "./auth";
|
||||
import type { Product } from "./types";
|
||||
|
||||
type QueryValue = string | number | boolean | undefined | null;
|
||||
|
||||
function withQuery(path: string, query: Record<string, QueryValue> = {}) {
|
||||
const params = Object.entries(query)
|
||||
.filter(([, value]) => value !== undefined && value !== null && value !== "")
|
||||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
||||
.join("&");
|
||||
return params ? `${path}?${params}` : path;
|
||||
}
|
||||
|
||||
export function go(path: string, query?: Record<string, QueryValue>) {
|
||||
uni.navigateTo({ url: withQuery(path, query) });
|
||||
}
|
||||
|
||||
export function goRoot(path: string, query?: Record<string, QueryValue>) {
|
||||
uni.reLaunch({ url: withQuery(path, query) });
|
||||
}
|
||||
|
||||
export function goBack(fallback = "/pages/home/index") {
|
||||
const pages = getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
uni.navigateBack();
|
||||
return;
|
||||
}
|
||||
goRoot(fallback);
|
||||
}
|
||||
|
||||
export function goSearch(keyword = "贵州") {
|
||||
go("/pages/search/index", { keyword });
|
||||
}
|
||||
|
||||
export function goCampaign(type: string) {
|
||||
go("/pages/campaign/index", { type });
|
||||
}
|
||||
|
||||
export function goDetail(product: Product) {
|
||||
go("/pages/detail/index", { product: productKey(product) });
|
||||
}
|
||||
|
||||
export function goBooking(product: Product) {
|
||||
go("/pages/booking/index", { product: productKey(product) });
|
||||
}
|
||||
|
||||
export function goDemand(destination?: string, product?: Product) {
|
||||
go("/pages/demand/index", { destination, product: product ? productKey(product) : undefined });
|
||||
}
|
||||
|
||||
export function goMine() {
|
||||
if (requireLogin("/pages/mine/index")) {
|
||||
goRoot("/pages/mine/index");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user