功能:同步小程序流程

This commit is contained in:
xiaowang
2026-05-23 18:45:41 +08:00
parent 844516988b
commit 30ae763e18
117 changed files with 8823 additions and 76 deletions
@@ -1,6 +1,14 @@
/**
* Purpose: auth supports navigation.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('./auth')
const { TAB_PAGES } = require('./config')
/**
* Purpose: buildUrl supports navigation.js by holding or executing the build url page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildUrl(path, params) {
const query = Object.keys(params || {})
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
@@ -10,6 +18,10 @@ function buildUrl(path, params) {
return query ? `${path}?${query}` : path
}
/**
* Purpose: getCurrentPageUrl supports navigation.js by holding or executing the get current page url page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getCurrentPageUrl() {
const pages = getCurrentPages()
const current = pages[pages.length - 1]
@@ -20,11 +32,19 @@ function getCurrentPageUrl() {
return buildUrl(`/${current.route}`, current.options || {})
}
/**
* Purpose: isTabPage supports navigation.js by holding or executing the is tab page page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function isTabPage(path) {
const purePath = String(path || '').split('?')[0]
return TAB_PAGES.includes(purePath)
}
/**
* Purpose: navigate supports navigation.js by holding or executing the navigate page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function navigate(path, params) {
return new Promise((resolve, reject) => {
wx.navigateTo({
@@ -35,6 +55,10 @@ function navigate(path, params) {
})
}
/**
* Purpose: redirect supports navigation.js by holding or executing the redirect page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function redirect(path, params) {
return new Promise((resolve, reject) => {
wx.redirectTo({
@@ -45,6 +69,10 @@ function redirect(path, params) {
})
}
/**
* Purpose: switchTab supports navigation.js by holding or executing the switch tab page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function switchTab(path) {
return new Promise((resolve, reject) => {
wx.switchTab({
@@ -55,6 +83,10 @@ function switchTab(path) {
})
}
/**
* Purpose: goBack supports navigation.js by holding or executing the go back page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function goBack(fallbackPath) {
const pages = getCurrentPages()
if (pages.length > 1) {
@@ -71,6 +103,10 @@ function goBack(fallbackPath) {
wx.redirectTo({ url: target })
}
/**
* Purpose: decodeRedirectValue supports navigation.js by holding or executing the decode redirect value page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function decodeRedirectValue(value) {
let current = String(value || '')
@@ -89,6 +125,10 @@ function decodeRedirectValue(value) {
return current
}
/**
* Purpose: redirectAfterLogin supports navigation.js by holding or executing the redirect after login page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function redirectAfterLogin(redirectValue) {
const target = redirectValue ? decodeRedirectValue(redirectValue) : ''
if (!target) {
@@ -109,12 +149,20 @@ function redirectAfterLogin(redirectValue) {
})
}
/**
* Purpose: openLogin supports navigation.js by holding or executing the open login page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function openLogin(redirectPath) {
return navigate('/pages/login/index', {
redirect: redirectPath || getCurrentPageUrl()
})
}
/**
* Purpose: ensureLogin supports navigation.js by holding or executing the ensure login page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function ensureLogin(actionText) {
if (auth.isLoggedIn()) {
return true