feat: 首页查看更多

This commit is contained in:
R524809
2026-04-30 17:19:04 +08:00
parent 7126d3a941
commit 44182d011d
5 changed files with 65 additions and 14 deletions
+35
View File
@@ -40,3 +40,38 @@ const formatNumber = (n: number) => {
const s = n.toString();
return s[1] ? s : '0' + s;
};
export type MiniProgramQuery = Record<string, string>;
export function parseMiniProgramUrl(input: string) {
const trimmed = input.trim();
const pathPart = trimmed.split(/[?#]/, 1)[0] || '';
const query: MiniProgramQuery = {};
const questionIndex = trimmed.indexOf('?');
const hashIndex = trimmed.indexOf('#');
const queryStart =
questionIndex >= 0 && (hashIndex < 0 || questionIndex < hashIndex)
? questionIndex + 1
: -1;
const queryEnd = hashIndex >= 0 ? hashIndex : trimmed.length;
if (queryStart >= 0 && queryStart <= queryEnd) {
const queryString = trimmed.slice(queryStart, queryEnd);
for (const pair of queryString.split('&')) {
if (!pair) continue;
const [rawKey, rawValue = ''] = pair.split('=', 2);
if (!rawKey) continue;
const decode = (v: string) => {
try {
return decodeURIComponent(v.replace(/\+/g, ' '));
} catch {
return v;
}
};
query[decode(rawKey)] = decode(rawValue);
}
}
return { path: pathPart, query };
}