flat: 暂存
This commit is contained in:
@@ -51,18 +51,77 @@ const prePage = () => {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 页面跳转封装,支持 query 参数传递和返回回调
|
||||
* @param {string} url - 跳转路径
|
||||
* @param {object} options
|
||||
* @param {boolean} options.needLogin - 是否需要登录
|
||||
* @param {object} options.query - 携带参数
|
||||
* @param {function} options.onBack - 页面返回时的回调(目标页调用 uni.navigateBack 时传递数据)
|
||||
*/
|
||||
export const navTo = function(url, {
|
||||
needLogin = false,
|
||||
query = {},
|
||||
onBack = null
|
||||
} = {}) {
|
||||
const userStore = useUserStore();
|
||||
|
||||
const navTo = function(url, needLogin) {
|
||||
if (needLogin && useUserStore().hasLogin) {
|
||||
if (needLogin && !userStore.hasLogin) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
const queryStr = Object.entries(query)
|
||||
.map(([key, val]) => `${key}=${encodeURIComponent(val)}`)
|
||||
.join('&');
|
||||
const finalUrl = queryStr ? `${url}?${queryStr}` : url;
|
||||
|
||||
if (onBack) {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
currentPage.__onBackCallback__ = onBack;
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url
|
||||
url: finalUrl
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const navBack = function({
|
||||
delta = 1,
|
||||
data = null,
|
||||
fallbackUrl = '/pages/index/index'
|
||||
} = {}) {
|
||||
const pages = getCurrentPages();
|
||||
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages[pages.length - 1 - delta];
|
||||
|
||||
// 如果上一页存在回调函数,调用
|
||||
if (data && prevPage?.__onBackCallback__) {
|
||||
prevPage.__onBackCallback__(data);
|
||||
}
|
||||
|
||||
uni.navigateBack({
|
||||
delta
|
||||
});
|
||||
} else {
|
||||
// 没有可返回的页面,直接跳转 fallback 页面
|
||||
uni.reLaunch({
|
||||
url: fallbackUrl
|
||||
});
|
||||
}
|
||||
};
|
||||
// // 默认返回上一页
|
||||
// navBack();
|
||||
|
||||
// // 返回上两层
|
||||
// navBack(2);
|
||||
|
||||
// // 没有历史页面时跳转首页
|
||||
// navBack(1, '/pages/home/home');
|
||||
|
||||
function getdeviceInfo() {
|
||||
const globalData = {
|
||||
@@ -247,33 +306,33 @@ class CustomSystem {
|
||||
const customSystem = new CustomSystem()
|
||||
|
||||
function setCheckedNodes(nodes, ids) {
|
||||
// 处理每个第一层节点
|
||||
const isClear = ids.length === 0;
|
||||
|
||||
nodes.forEach((firstLayer) => {
|
||||
// 初始化或重置计数器
|
||||
// 每次处理都先重置
|
||||
firstLayer.checkednumber = 0;
|
||||
|
||||
// 递归处理子树
|
||||
const traverse = (node) => {
|
||||
// 设置当前节点选中状态
|
||||
const shouldCheck = ids.includes(node.id);
|
||||
if (shouldCheck) node.checked = true;
|
||||
if (isClear) {
|
||||
node.checked = false;
|
||||
} else {
|
||||
node.checked = ids.includes(node.id);
|
||||
}
|
||||
|
||||
// 统计后代节点(排除首层自身)
|
||||
if (node !== firstLayer && node.checked) {
|
||||
firstLayer.checkednumber++;
|
||||
}
|
||||
|
||||
// 递归子节点
|
||||
if (node.children) {
|
||||
node.children.forEach((child) => traverse(child));
|
||||
if (node.children && node.children.length) {
|
||||
node.children.forEach(child => traverse(child));
|
||||
}
|
||||
};
|
||||
|
||||
// 启动当前首层节点的遍历
|
||||
traverse(firstLayer);
|
||||
});
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
const formatTotal = (total) => {
|
||||
if (total < 10) return total.toString(); // 直接返回小于 10 的数
|
||||
|
||||
@@ -496,6 +555,7 @@ export const $api = {
|
||||
export default {
|
||||
$api,
|
||||
navTo,
|
||||
navBack,
|
||||
cloneDeep,
|
||||
formatDate,
|
||||
getdeviceInfo,
|
||||
@@ -513,5 +573,6 @@ export default {
|
||||
getWeeksOfMonth,
|
||||
isFutureDate,
|
||||
parseQueryParams,
|
||||
appendScriptTagElement
|
||||
appendScriptTagElement,
|
||||
insertSortData
|
||||
}
|
Reference in New Issue
Block a user