function getCurrentUrl() {
// 获取页面栈
const pages = getCurrentPages();
if (pages.length === 0) return;
// 当前页面实例
const currentPage = pages[pages.length - 1];
// 页面路径(补全前缀)
const path = `/${currentPage.route}`;
// 处理参数(编码特殊字符)
const queryParams = currentPage.options || {};
const queryString = Object.keys(queryParams)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(queryParams[key])}`)
.join('&');
// 完整地址
const fullUrl = queryString ? `${path}?${queryString}` : path;
console.log('当前页面地址:', fullUrl); // 输出如:/pages/index/index?id=123
return fullUrl;
}