功能:同步小程序流程

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
+141
View File
@@ -1,8 +1,20 @@
/**
* 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: waitingForAutoLoginNavigation supports navigation.js by holding or executing the waiting for auto login navigation page or API role.
* Usage: import, call, read, or update this let from the owning page/module while preserving the surrounding loading and permission flow.
*/
let waitingForAutoLoginNavigation = false
/**
* 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] !== '')
@@ -12,6 +24,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]
@@ -22,11 +38,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({
@@ -37,6 +61,10 @@ function navigate(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({
@@ -47,6 +75,10 @@ function switchTab(path) {
})
}
/**
* Purpose: normalizeActionPath supports navigation.js by holding or executing the normalize action path 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 normalizeActionPath(value) {
const rawPath = String(value || '').trim()
if (!rawPath || !rawPath.startsWith('/') || rawPath.startsWith('//')) {
@@ -59,6 +91,28 @@ function normalizeActionPath(value) {
return `/pages/orders/index${query}`
}
if (rawPath.startsWith('/product/')) {
const id = rawPath.split('/')[2] || ''
return buildUrl('/pages/product-detail/index', { id })
}
if (rawPath.startsWith('/shop/')) {
const id = rawPath.split('/')[2] || ''
return buildUrl('/pages/shop-detail/index', { id })
}
if (rawPath === '/coupons' || rawPath.startsWith('/coupons?')) {
return rawPath.replace('/coupons', '/pages/coupons/index')
}
if (rawPath === '/vip-center' || rawPath.startsWith('/vip-center?')) {
return rawPath.replace('/vip-center', '/pages/vip-center/index')
}
if (rawPath === '/cart' || rawPath.startsWith('/cart?')) {
return rawPath.replace('/cart', '/pages/cart/index')
}
if (rawPath.startsWith('/pages/')) {
return rawPath
}
@@ -66,6 +120,47 @@ function normalizeActionPath(value) {
return ''
}
/**
* Purpose: buildMessageActionPath converts backend system-message business fields into a mini-program route.
* Usage: call it when actionPath is absent so review and artist-change popup messages still land on orders.
*/
function buildMessageActionPath(message) {
if (!message) {
return ''
}
const actionPath = normalizeActionPath(message.actionPath)
if (actionPath) {
return actionPath
}
const businessType = String(message.businessType || '').toUpperCase()
const businessId = message.businessId || ''
if (businessType === 'ORDER_ARTIST_REVIEW' || businessType === 'ORDER_ARTIST_CHANGE' || businessType === 'ORDER') {
return buildUrl('/pages/orders/index', businessId ? { orderId: businessId } : {})
}
if (businessType === 'PRODUCT') {
return buildUrl('/pages/product-detail/index', businessId ? { id: businessId } : {})
}
if (businessType === 'SHOP') {
return buildUrl('/pages/shop-detail/index', businessId ? { id: businessId } : {})
}
if (businessType === 'VIP') {
return '/pages/vip-center/index'
}
if (businessType === 'COUPON') {
return '/pages/coupons/index'
}
if (businessType === 'CART') {
return '/pages/cart/index'
}
return ''
}
/**
* Purpose: openActionPath supports navigation.js by holding or executing the open action path 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 openActionPath(value) {
const target = normalizeActionPath(value)
if (!target) {
@@ -86,6 +181,18 @@ function openActionPath(value) {
})
}
/**
* Purpose: openSystemMessage opens a backend system-message action using actionPath first and business fields as fallback.
* Usage: pass a full system-message record from popup or notification list taps.
*/
function openSystemMessage(message) {
return openActionPath(buildMessageActionPath(message))
}
/**
* 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) {
@@ -105,6 +212,10 @@ function goBack(fallbackPath) {
})
}
/**
* Purpose: parseQuery supports navigation.js by holding or executing the parse query 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 parseQuery(url) {
const queryString = String(url || '').split('?')[1] || ''
if (!queryString) {
@@ -122,6 +233,10 @@ function parseQuery(url) {
}, {})
}
/**
* 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 || '')
@@ -140,6 +255,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(redirect) {
const target = redirect ? decodeRedirectValue(redirect) : ''
if (!target) {
@@ -166,12 +285,20 @@ function redirectAfterLogin(redirect) {
})
}
/**
* Purpose: openAuth supports navigation.js by holding or executing the open auth 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 openAuth(redirect) {
return navigate('/pages/auth/index', {
redirect: redirect || getCurrentPageUrl()
})
}
/**
* Purpose: showLoginToast supports navigation.js by holding or executing the show login toast 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 showLoginToast(actionText) {
wx.showToast({
title: `${actionText || '继续操作'}前请先登录`,
@@ -179,6 +306,10 @@ function showLoginToast(actionText) {
})
}
/**
* Purpose: scheduleOpenAuth supports navigation.js by holding or executing the schedule open auth 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 scheduleOpenAuth(actionText) {
showLoginToast(actionText)
setTimeout(() => {
@@ -186,6 +317,10 @@ function scheduleOpenAuth(actionText) {
}, 120)
}
/**
* 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
@@ -226,11 +361,17 @@ module.exports = {
navigate,
switchTab,
normalizeActionPath,
buildMessageActionPath,
openActionPath,
openSystemMessage,
goBack,
redirectAfterLogin,
openAuth,
ensureLogin,
/**
* Purpose: openProducts supports navigation.js by holding or executing the open products page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
openProducts(filter) {
const app = getApp()
app.globalData.pendingProductFilter = filter || {}