feat: release

This commit is contained in:
zzc
2026-05-20 23:16:53 +08:00
parent 0143a08af7
commit 48c7cebac1
4 changed files with 142 additions and 26 deletions

View File

@@ -39,3 +39,73 @@ export const smartNavigateBack = (options = {}) => {
executeBack();
}
};
/**
* 对象转 URL 参数
* @param {Object} obj 要转换的对象
* @returns {string} 返回 a=1&b=2 格式的字符串
*/
export const objToUrlParams = (obj) => {
if (!obj || typeof obj !== 'object') return '';
const params = [];
for (let key in obj) {
if (obj.hasOwnProperty(key) && obj[key] !== undefined && obj[key] !== null) {
// 过滤掉 undefined 和 null 的参数
params.push(`${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`);
}
}
return params.join('&');
};
/**
* 封装带参数的跳转方法
* @param {string} url 跳转的页面路径
* @param {Object} params 要传递的参数对象
*/
export const navigateToWithParams = (url, params = {}) => {
const queryStr = objToUrlParams(params);
const finalUrl = queryStr ? `${url}${url.includes('?') ? '&' : '?'}${queryStr}` : url;
uni.navigateTo({
url: finalUrl
});
};
/**
* 获取当前页面的实例
* @returns {Object|null} 当前页面实例
*/
export const getCurrentPage = () => {
const pages = getCurrentPages();
return pages.length > 0 ? pages[pages.length - 1] : null;
};
/**
* 刷新当前页面(重新调用 onLoad 和 onShow
* 注意:部分复杂页面可能需要根据具体业务逻辑单独实现刷新机制
*/
export const refreshCurrentPage = () => {
const currentPage = getCurrentPage();
if (currentPage) {
if (typeof currentPage.onLoad === 'function') {
currentPage.onLoad(currentPage.options || {});
}
if (typeof currentPage.onShow === 'function') {
currentPage.onShow();
}
}
};
/**
* 检查当前是否是指定页面
* @param {string} route 页面路由,例如 'pages/index/index'
* @returns {boolean}
*/
export const isCurrentPage = (route) => {
const currentPage = getCurrentPage();
if (!currentPage) return false;
// 去除可能的首字符 '/'
const checkRoute = route.startsWith('/') ? route.substring(1) : route;
return currentPage.route === checkRoute;
};

View File

@@ -1,5 +1,5 @@
const BASE_URL = "https://api.ai-meng.com";
// const BASE_URL = 'http://127.0.0.1:3999'
// const BASE_URL = "https://api.ai-meng.com";
const BASE_URL = 'http://127.0.0.1:3999'
// const BASE_URL = "http://192.168.1.2:3999";
// const BASE_URL = "http://192.168.31.253:3999";
import { useUserStore } from "@/stores/user";
@@ -35,7 +35,7 @@ function hideLoading() {
function getHeaders() {
const userStore = useUserStore();
const headers = {
"x-app-id": "69665538a49b8ae3be50fe5d",
"x-app-id": "6a0d7dbe4c5de50f2ba66475",
"x-platform": platform,
"x-user-id": userStore?.userInfo?.id || "",
};