57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import Taro from "@tarojs/taro";
|
|
|
|
// 普通函数,不调用 useLoad
|
|
export const sceneRedirectLogic = (options, defaultPage: string) => {
|
|
if (!options.scene) return;
|
|
|
|
try {
|
|
const decoded = decodeURIComponent(options.scene || "");
|
|
const params: Record<string, string> = {};
|
|
|
|
decoded.split("&").forEach((pair) => {
|
|
const [key, value] = pair.split("=");
|
|
if (key) params[key] = value ? decodeURIComponent(value) : "";
|
|
});
|
|
|
|
const query = Object.entries(params)
|
|
.map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
|
|
.join("&");
|
|
|
|
Taro.redirectTo({
|
|
url: query ? `/${defaultPage}?${query}` : `/${defaultPage}`,
|
|
});
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
};
|
|
|
|
export function navto(url) {
|
|
Taro.navigateTo({
|
|
url: url,
|
|
});
|
|
}
|
|
|
|
export function toast(message) {
|
|
Taro.showToast({ title: message, icon: "none" });
|
|
}
|
|
|
|
// 将·作为连接符插入到标签文本之间
|
|
export function insertDotInTags(tags: string[]) {
|
|
if (!tags) return [];
|
|
return tags.join("-·-").split("-");
|
|
}
|
|
|
|
function formatNtrpDisplay(val) {
|
|
return Number(val).toFixed(1)
|
|
}
|
|
|
|
export function genNTRPRequirementText(min, max) {
|
|
if (min && max && min !== max) {
|
|
return `${formatNtrpDisplay(min)} - ${formatNtrpDisplay(max)} 之间`;
|
|
} else if (max === "1") {
|
|
return "无要求";
|
|
} else if (max) {
|
|
return `${formatNtrpDisplay(max)} 以上`;
|
|
}
|
|
return "-";
|
|
} |