功能:同步小程序流程
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
/**
|
||||
* Purpose: inflightScopes supports action-guard.js by holding or executing the inflight scopes 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 inflightScopes = new Map()
|
||||
|
||||
/**
|
||||
* Purpose: resolveScopeId supports action-guard.js by holding or executing the resolve scope id 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 resolveScopeId(scope) {
|
||||
if (scope && typeof scope === 'string') {
|
||||
return scope
|
||||
@@ -17,6 +25,10 @@ function resolveScopeId(scope) {
|
||||
return 'global'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getScopeMap supports action-guard.js by holding or executing the get scope map 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 getScopeMap(scopeId) {
|
||||
if (!inflightScopes.has(scopeId)) {
|
||||
inflightScopes.set(scopeId, new Map())
|
||||
@@ -24,6 +36,10 @@ function getScopeMap(scopeId) {
|
||||
return inflightScopes.get(scopeId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: createGuardError supports action-guard.js by holding or executing the create guard error 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 createGuardError(message, scopeId, actionKey) {
|
||||
const error = new Error(message || '\u64cd\u4f5c\u8fdb\u884c\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u70b9\u51fb')
|
||||
error.isActionGuardError = true
|
||||
@@ -32,6 +48,10 @@ function createGuardError(message, scopeId, actionKey) {
|
||||
return error
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: run supports action-guard.js by holding or executing the run 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.
|
||||
*/
|
||||
async function run(scope, actionKey, task, options) {
|
||||
const scopeId = resolveScopeId(scope)
|
||||
const normalizedKey = String(actionKey || 'default')
|
||||
@@ -52,6 +72,10 @@ async function run(scope, actionKey, task, options) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isRunning supports action-guard.js by holding or executing the is running 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 isRunning(scope, actionKey) {
|
||||
const scopeId = resolveScopeId(scope)
|
||||
const scopeMap = inflightScopes.get(scopeId)
|
||||
@@ -61,10 +85,18 @@ function isRunning(scope, actionKey) {
|
||||
return Boolean(scopeMap.get(String(actionKey || 'default')))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearScope supports action-guard.js by holding or executing the clear scope 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 clearScope(scope) {
|
||||
inflightScopes.delete(resolveScopeId(scope))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isGuardError supports action-guard.js by holding or executing the is guard error 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 isGuardError(error) {
|
||||
return Boolean(error && error.isActionGuardError)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
const { STORAGE_KEYS, getStorage, removeStorage, setStorage } = require('./storage')
|
||||
/**
|
||||
* Purpose: SIGNED_URL_SAFE_BUFFER_MS supports auth.js by holding or executing the signed url safe buffer ms 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 SIGNED_URL_SAFE_BUFFER_MS = 60 * 1000
|
||||
|
||||
/**
|
||||
* Purpose: parseSignedUrlExpireAt supports auth.js by holding or executing the parse signed url expire at 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 parseSignedUrlExpireAt(url) {
|
||||
const rawUrl = String(url || '').trim()
|
||||
if (!rawUrl || rawUrl.indexOf('?') < 0) {
|
||||
@@ -42,6 +50,10 @@ function parseSignedUrlExpireAt(url) {
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sanitizeStoredUserInfo supports auth.js by holding or executing the sanitize stored user info 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 sanitizeStoredUserInfo(userInfo) {
|
||||
if (!userInfo || typeof userInfo !== 'object') {
|
||||
return userInfo
|
||||
@@ -57,14 +69,26 @@ function sanitizeStoredUserInfo(userInfo) {
|
||||
return nextUserInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getAccessToken supports auth.js by holding or executing the get access token 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 getAccessToken() {
|
||||
return getStorage(STORAGE_KEYS.ACCESS_TOKEN, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getRefreshToken supports auth.js by holding or executing the get refresh token 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 getRefreshToken() {
|
||||
return getStorage(STORAGE_KEYS.REFRESH_TOKEN, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getStoredUserInfo supports auth.js by holding or executing the get stored user info 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 getStoredUserInfo() {
|
||||
const userInfo = sanitizeStoredUserInfo(getStorage(STORAGE_KEYS.USER_INFO, null))
|
||||
if (userInfo) {
|
||||
@@ -73,18 +97,34 @@ function getStoredUserInfo() {
|
||||
return userInfo
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getNeedSetPassword supports auth.js by holding or executing the get need set password 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 getNeedSetPassword() {
|
||||
return Boolean(getStorage(STORAGE_KEYS.NEED_SET_PASSWORD, false))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getPreferredMiniLoginShopId supports auth.js by holding or executing the get preferred mini login shop id 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 getPreferredMiniLoginShopId() {
|
||||
return getStorage(STORAGE_KEYS.PREFERRED_MINI_LOGIN_SHOP_ID, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isLoggedIn supports auth.js by holding or executing the is logged in 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 isLoggedIn() {
|
||||
return Boolean(getAccessToken())
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setSession supports auth.js by holding or executing the set session 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 setSession(payload) {
|
||||
if (!payload || !payload.accessToken || !payload.refreshToken) {
|
||||
return
|
||||
@@ -104,6 +144,10 @@ function setSession(payload) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: updateStoredUserInfo supports auth.js by holding or executing the update stored user info 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 updateStoredUserInfo(userInfo) {
|
||||
if (!userInfo) {
|
||||
removeStorage(STORAGE_KEYS.USER_INFO)
|
||||
@@ -113,6 +157,10 @@ function updateStoredUserInfo(userInfo) {
|
||||
setStorage(STORAGE_KEYS.USER_INFO, sanitizeStoredUserInfo(userInfo))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setNeedSetPassword supports auth.js by holding or executing the set need set password 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 setNeedSetPassword(value) {
|
||||
if (value) {
|
||||
setStorage(STORAGE_KEYS.NEED_SET_PASSWORD, true)
|
||||
@@ -122,6 +170,10 @@ function setNeedSetPassword(value) {
|
||||
removeStorage(STORAGE_KEYS.NEED_SET_PASSWORD)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearSession supports auth.js by holding or executing the clear session 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 clearSession() {
|
||||
removeStorage(STORAGE_KEYS.ACCESS_TOKEN)
|
||||
removeStorage(STORAGE_KEYS.REFRESH_TOKEN)
|
||||
@@ -129,6 +181,10 @@ function clearSession() {
|
||||
removeStorage(STORAGE_KEYS.NEED_SET_PASSWORD)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setPreferredMiniLoginShopId supports auth.js by holding or executing the set preferred mini login shop id 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 setPreferredMiniLoginShopId(shopId) {
|
||||
if (shopId === undefined || shopId === null || shopId === '') {
|
||||
removeStorage(STORAGE_KEYS.PREFERRED_MINI_LOGIN_SHOP_ID)
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
/**
|
||||
* Purpose: CACHE_PREFIX supports cache.js by holding or executing the cache prefix 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 CACHE_PREFIX = 'miniCache:'
|
||||
/**
|
||||
* Purpose: memoryCache supports cache.js by holding or executing the memory cache 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 memoryCache = {}
|
||||
/**
|
||||
* Purpose: inflightCache supports cache.js by holding or executing the inflight cache 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 inflightCache = {}
|
||||
|
||||
/**
|
||||
* Purpose: now supports cache.js by holding or executing the now 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 now() {
|
||||
return Date.now()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildKey supports cache.js by holding or executing the build key 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 buildKey(key) {
|
||||
return `${CACHE_PREFIX}${key}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearExpiredEntry supports cache.js by holding or executing the clear expired entry 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 clearExpiredEntry(key, entry) {
|
||||
if (!entry) {
|
||||
return
|
||||
@@ -22,6 +46,10 @@ function clearExpiredEntry(key, entry) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCache supports cache.js by holding or executing the get cache 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 getCache(key, defaultValue) {
|
||||
if (!key) {
|
||||
return defaultValue
|
||||
@@ -45,6 +73,10 @@ function getCache(key, defaultValue) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setCache supports cache.js by holding or executing the set cache 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 setCache(key, value, ttlMs) {
|
||||
if (!key) {
|
||||
return value
|
||||
@@ -61,6 +93,10 @@ function setCache(key, value, ttlMs) {
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeCache supports cache.js by holding or executing the remove cache 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 removeCache(key) {
|
||||
if (!key) {
|
||||
return
|
||||
@@ -71,6 +107,10 @@ function removeCache(key) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeByPrefix supports cache.js by holding or executing the remove by prefix 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 removeByPrefix(prefix) {
|
||||
Object.keys(memoryCache).forEach(key => {
|
||||
if (key.startsWith(prefix)) {
|
||||
@@ -82,6 +122,10 @@ function removeByPrefix(prefix) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: remember supports cache.js by holding or executing the remember 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 remember(key, ttlMs, loader) {
|
||||
const cached = getCache(key, undefined)
|
||||
if (cached !== undefined) {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: safeRequire supports config.js by holding or executing the safe require 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 safeRequire(modulePath) {
|
||||
try {
|
||||
return require(modulePath)
|
||||
@@ -6,6 +10,10 @@ function safeRequire(modulePath) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getEnvVersion supports config.js by holding or executing the get env version 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 getEnvVersion() {
|
||||
if (typeof wx === 'undefined') {
|
||||
return 'develop'
|
||||
@@ -30,6 +38,10 @@ function getEnvVersion() {
|
||||
return 'develop'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getRuntimePlatform supports config.js by holding or executing the get runtime platform 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 getRuntimePlatform() {
|
||||
if (typeof wx === 'undefined') {
|
||||
return 'devtools'
|
||||
@@ -56,6 +68,10 @@ function getRuntimePlatform() {
|
||||
return 'unknown'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: normalizeDomain supports config.js by holding or executing the normalize domain 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 normalizeDomain(value, fallbackValue) {
|
||||
const target = String(value || fallbackValue || '').trim()
|
||||
if (!target) {
|
||||
@@ -64,6 +80,10 @@ function normalizeDomain(value, fallbackValue) {
|
||||
return target.replace(/\/+$/, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: ensureHttps supports config.js by holding or executing the ensure https 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 ensureHttps(value, envVersion) {
|
||||
if (!value) {
|
||||
throw new Error(`Missing API domain for ${envVersion}`)
|
||||
@@ -74,11 +94,31 @@ function ensureHttps(value, envVersion) {
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: localOverride supports config.js by holding or executing the local override 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 localOverride = safeRequire('./config.local')
|
||||
/**
|
||||
* Purpose: ENV_VERSION supports config.js by holding or executing the env version 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 ENV_VERSION = getEnvVersion()
|
||||
/**
|
||||
* Purpose: RUNTIME_PLATFORM supports config.js by holding or executing the runtime platform 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 RUNTIME_PLATFORM = getRuntimePlatform()
|
||||
/**
|
||||
* Purpose: IS_DEVTOOLS supports config.js by holding or executing the is devtools 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 IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools'
|
||||
|
||||
/**
|
||||
* Purpose: DEFAULT_DOMAINS supports config.js by holding or executing the default domains 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 DEFAULT_DOMAINS = {
|
||||
local: 'http://127.0.0.1:80',
|
||||
tunnel: 'https://yunail.art',
|
||||
@@ -87,13 +127,29 @@ const DEFAULT_DOMAINS = {
|
||||
release: 'https://yunail.art'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: DOMAIN_MAP supports config.js by holding or executing the domain map 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 DOMAIN_MAP = {
|
||||
...DEFAULT_DOMAINS,
|
||||
...(localOverride.domains || {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: DEFAULT_DEVELOP_TARGET supports config.js by holding or executing the default develop target 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 DEFAULT_DEVELOP_TARGET = IS_DEVTOOLS ? 'local' : 'dev-remote'
|
||||
/**
|
||||
* Purpose: DEVELOP_TARGET supports config.js by holding or executing the develop target 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 DEVELOP_TARGET = String(localOverride.developTarget || DEFAULT_DEVELOP_TARGET)
|
||||
/**
|
||||
* Purpose: API_DOMAIN supports config.js by holding or executing the api domain 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 API_DOMAIN = ensureHttps(
|
||||
ENV_VERSION === 'develop'
|
||||
? normalizeDomain(DOMAIN_MAP[DEVELOP_TARGET], DOMAIN_MAP['dev-remote'])
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: utf8ToBytes supports crypto.js by holding or executing the utf8 to bytes 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 utf8ToBytes(text) {
|
||||
const encoded = unescape(encodeURIComponent(String(text || '')))
|
||||
const bytes = []
|
||||
@@ -7,14 +11,26 @@ function utf8ToBytes(text) {
|
||||
return bytes
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: bytesToHex supports crypto.js by holding or executing the bytes to hex 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 bytesToHex(bytes) {
|
||||
return (Array.isArray(bytes) ? bytes : []).map(item => item.toString(16).padStart(2, '0')).join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: rightRotate supports crypto.js by holding or executing the right rotate 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 rightRotate(value, amount) {
|
||||
return (value >>> amount) | (value << (32 - amount))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sha256Bytes supports crypto.js by holding or executing the sha256 bytes 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 sha256Bytes(messageBytes) {
|
||||
const k = [
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
@@ -113,10 +129,18 @@ function sha256Bytes(messageBytes) {
|
||||
return output
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sha256Hex supports crypto.js by holding or executing the sha256 hex 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 sha256Hex(text) {
|
||||
return bytesToHex(sha256Bytes(utf8ToBytes(text)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hmacSha256Hex supports crypto.js by holding or executing the hmac sha256 hex 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 hmacSha256Hex(secret, message) {
|
||||
let keyBytes = utf8ToBytes(secret)
|
||||
if (keyBytes.length > 64) {
|
||||
@@ -137,6 +161,10 @@ function hmacSha256Hex(secret, message) {
|
||||
return bytesToHex(sha256Bytes(outer.concat(innerDigest)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildCanonicalParams supports crypto.js by holding or executing the build canonical params 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 buildCanonicalParams(input) {
|
||||
const source = input || {}
|
||||
const keys = Object.keys(source)
|
||||
@@ -154,6 +182,10 @@ function buildCanonicalParams(input) {
|
||||
}).join('&')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildJsonPayload supports crypto.js by holding or executing the build json payload 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 buildJsonPayload(data) {
|
||||
if (data === undefined || data === null || data === '') {
|
||||
return ''
|
||||
@@ -164,6 +196,10 @@ function buildJsonPayload(data) {
|
||||
return JSON.stringify(data)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: randomNonce supports crypto.js by holding or executing the random nonce 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 randomNonce() {
|
||||
return `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
const { STORAGE_KEYS, getStorage, setStorage } = require('./storage')
|
||||
|
||||
/**
|
||||
* Purpose: createDeviceId supports device.js by holding or executing the create device id 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 createDeviceId() {
|
||||
const randomText = Math.random().toString(36).slice(2, 10)
|
||||
return `mini-device-${Date.now()}-${randomText}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getDeviceId supports device.js by holding or executing the get device id 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 getDeviceId() {
|
||||
let value = getStorage(STORAGE_KEYS.DEVICE_ID, '')
|
||||
if (value) {
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
/**
|
||||
* Purpose: fileApi supports file.js by holding or executing the file api 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 fileApi = require('../api/file')
|
||||
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
|
||||
const { CACHE_TTL } = require('./config')
|
||||
const { splitCsv } = require('./format')
|
||||
|
||||
/**
|
||||
* Purpose: urlCache supports file.js by holding or executing the url cache 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 urlCache = {}
|
||||
|
||||
/**
|
||||
* Purpose: getSignedUrl supports file.js by holding or executing the get signed 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.
|
||||
*/
|
||||
async function getSignedUrl(fileId) {
|
||||
const key = String(fileId || '')
|
||||
if (!key) {
|
||||
@@ -24,6 +36,10 @@ async function getSignedUrl(fileId) {
|
||||
return urlCache[key].value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: extractLegacyFileId supports file.js by holding or executing the extract legacy file id 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 extractLegacyFileId(value) {
|
||||
const match = String(value || '')
|
||||
.replace(/<[^>]*>/g, '')
|
||||
@@ -32,6 +48,10 @@ function extractLegacyFileId(value) {
|
||||
return match && match[1] ? match[1] : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveImageList supports file.js by holding or executing the resolve image list 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.
|
||||
*/
|
||||
async function resolveImageList(fileIds, fallbackImage) {
|
||||
const ids = Array.isArray(fileIds) ? fileIds : splitCsv(fileIds)
|
||||
if (!ids.length) {
|
||||
@@ -49,6 +69,10 @@ async function resolveImageList(fileIds, fallbackImage) {
|
||||
return urls.length ? urls : [fallbackImage || DEFAULT_PRODUCT_IMAGE]
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveLegacyImage supports file.js by holding or executing the resolve legacy image 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.
|
||||
*/
|
||||
async function resolveLegacyImage(value, fallbackImage) {
|
||||
const fileId = extractLegacyFileId(value)
|
||||
if (!fileId) {
|
||||
@@ -63,11 +87,41 @@ async function resolveLegacyImage(value, fallbackImage) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: previewImagesSafely opens wx.previewImage with a user-facing fallback when signed URLs expire or preview fails.
|
||||
* Usage: pass the current image URL and full URL list from image tap handlers instead of calling wx.previewImage directly.
|
||||
*/
|
||||
function previewImagesSafely(current, urls) {
|
||||
const list = (Array.isArray(urls) ? urls : [current]).filter(Boolean)
|
||||
if (!current || !list.length) {
|
||||
wx.showToast({
|
||||
title: '图片暂不可预览',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
wx.previewImage({
|
||||
current,
|
||||
urls: list,
|
||||
fail: () => {
|
||||
wx.showToast({
|
||||
title: '图片预览失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSignedUrl,
|
||||
extractLegacyFileId,
|
||||
resolveImageList,
|
||||
resolveLegacyImage,
|
||||
previewImagesSafely,
|
||||
/**
|
||||
* Purpose: clearSignedUrlCache supports file.js by holding or executing the clear signed url cache 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.
|
||||
*/
|
||||
clearSignedUrlCache(fileId) {
|
||||
if (fileId === undefined || fileId === null || fileId === '') {
|
||||
Object.keys(urlCache).forEach(key => delete urlCache[key])
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/**
|
||||
* Purpose: DRAFT_PREFIX supports form-draft.js by holding or executing the draft prefix 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 DRAFT_PREFIX = 'miniDraft:'
|
||||
|
||||
/**
|
||||
* Purpose: buildDraftKey supports form-draft.js by holding or executing the build draft key 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 buildDraftKey(key) {
|
||||
return `${DRAFT_PREFIX}${key}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: loadDraft supports form-draft.js by holding or executing the load draft 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 loadDraft(key, defaultValue) {
|
||||
if (!key) {
|
||||
return defaultValue
|
||||
@@ -16,6 +28,10 @@ function loadDraft(key, defaultValue) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: saveDraft supports form-draft.js by holding or executing the save draft 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 saveDraft(key, value) {
|
||||
if (!key) {
|
||||
return
|
||||
@@ -28,6 +44,10 @@ function saveDraft(key, value) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearDraft supports form-draft.js by holding or executing the clear draft 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 clearDraft(key) {
|
||||
if (!key) {
|
||||
return
|
||||
@@ -37,6 +57,10 @@ function clearDraft(key) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getDraftValue supports form-draft.js by holding or executing the get draft 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 getDraftValue(key, defaultValue) {
|
||||
const record = loadDraft(key, null)
|
||||
if (!record || typeof record !== 'object' || !Object.prototype.hasOwnProperty.call(record, 'value')) {
|
||||
@@ -45,6 +69,10 @@ function getDraftValue(key, defaultValue) {
|
||||
return record.value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: scheduleDraftSave supports form-draft.js by holding or executing the schedule draft save 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 scheduleDraftSave(context, key, buildValue, delay) {
|
||||
if (!context) {
|
||||
return
|
||||
@@ -57,6 +85,10 @@ function scheduleDraftSave(context, key, buildValue, delay) {
|
||||
}, delay || 300)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearDraftTimer supports form-draft.js by holding or executing the clear draft timer 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 clearDraftTimer(context) {
|
||||
if (context && context.__draftSaveTimer) {
|
||||
clearTimeout(context.__draftSaveTimer)
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
/**
|
||||
* Purpose: formatPrice supports format.js by holding or executing the format price 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 formatPrice(value) {
|
||||
return Number(value || 0).toFixed(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getProductTitle supports format.js by holding or executing the get product title 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 getProductTitle(product) {
|
||||
return (product && (product.title || product.name)) || '未命名作品'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: splitCsv supports format.js by holding or executing the split csv 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 splitCsv(value) {
|
||||
return String(value || '')
|
||||
.split(',')
|
||||
@@ -13,10 +25,18 @@ function splitCsv(value) {
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: sameId supports format.js by holding or executing the same id 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 sameId(left, right) {
|
||||
return String(left || '') === String(right || '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formatDateTime supports format.js by holding or executing the format date time 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 formatDateTime(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
@@ -24,6 +44,10 @@ function formatDateTime(value) {
|
||||
return String(value).replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: parseAppointmentParts supports format.js by holding or executing the parse appointment parts 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 parseAppointmentParts(value) {
|
||||
const text = formatDateTime(value)
|
||||
if (!text) {
|
||||
@@ -40,6 +64,10 @@ function parseAppointmentParts(value) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildAppointmentValue supports format.js by holding or executing the build appointment 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 buildAppointmentValue(date, clock) {
|
||||
if (!date || !clock) {
|
||||
return ''
|
||||
@@ -47,6 +75,10 @@ function buildAppointmentValue(date, clock) {
|
||||
return `${date} ${clock}:00`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isPastAppointment supports format.js by holding or executing the is past appointment 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 isPastAppointment(value) {
|
||||
if (!value) {
|
||||
return false
|
||||
@@ -54,6 +86,10 @@ function isPastAppointment(value) {
|
||||
return new Date(String(value).replace(' ', 'T')).getTime() < Date.now() + 5 * 60 * 1000
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getMinDateText supports format.js by holding or executing the get min date text 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 getMinDateText() {
|
||||
const now = new Date()
|
||||
const year = now.getFullYear()
|
||||
@@ -62,6 +98,10 @@ function getMinDateText() {
|
||||
return `${year}-${month}-${date}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getOrderStatusText supports format.js by holding or executing the get order status text 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 getOrderStatusText(order) {
|
||||
if (order && order.statusText) {
|
||||
return order.statusText
|
||||
@@ -77,6 +117,10 @@ function getOrderStatusText(order) {
|
||||
return '已取消'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getOrderStatusClass supports format.js by holding or executing the get order status class 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 getOrderStatusClass(order) {
|
||||
const status = Number(order && order.status)
|
||||
if (status === 1) {
|
||||
|
||||
@@ -1,11 +1,43 @@
|
||||
/**
|
||||
* Purpose: options supports idle-session.js by holding or executing the options 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 options = null
|
||||
/**
|
||||
* Purpose: timer supports idle-session.js by holding or executing the timer 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 timer = null
|
||||
/**
|
||||
* Purpose: warningShown supports idle-session.js by holding or executing the warning shown 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 warningShown = false
|
||||
/**
|
||||
* Purpose: loggingOut supports idle-session.js by holding or executing the logging out 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 loggingOut = false
|
||||
/**
|
||||
* Purpose: hiddenAt supports idle-session.js by holding or executing the hidden at 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 hiddenAt = 0
|
||||
/**
|
||||
* Purpose: lastActiveAt supports idle-session.js by holding or executing the last active at 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 lastActiveAt = Date.now()
|
||||
/**
|
||||
* Purpose: pagePatched supports idle-session.js by holding or executing the page patched 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 pagePatched = false
|
||||
|
||||
/**
|
||||
* Purpose: shouldTrackMethod supports idle-session.js by holding or executing the should track method 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 shouldTrackMethod(name) {
|
||||
return ![
|
||||
'onHide',
|
||||
@@ -15,6 +47,10 @@ function shouldTrackMethod(name) {
|
||||
].includes(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: ensurePagePatched supports idle-session.js by holding or executing the ensure page patched 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 ensurePagePatched() {
|
||||
if (pagePatched || typeof Page !== 'function') {
|
||||
return
|
||||
@@ -40,6 +76,10 @@ function ensurePagePatched() {
|
||||
pagePatched = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: start supports idle-session.js by holding or executing the start 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 start() {
|
||||
stop()
|
||||
if (!options) {
|
||||
@@ -48,6 +88,10 @@ function start() {
|
||||
timer = setInterval(check, 15000)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: stop supports idle-session.js by holding or executing the stop 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 stop() {
|
||||
if (timer) {
|
||||
clearInterval(timer)
|
||||
@@ -55,10 +99,18 @@ function stop() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isLoggedIn supports idle-session.js by holding or executing the is logged in 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 isLoggedIn() {
|
||||
return options && typeof options.isLoggedIn === 'function' ? Boolean(options.isLoggedIn()) : false
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: markActive supports idle-session.js by holding or executing the mark active 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 markActive() {
|
||||
if (!options || !isLoggedIn() || loggingOut) {
|
||||
return
|
||||
@@ -67,6 +119,10 @@ function markActive() {
|
||||
warningShown = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: onAppShow supports idle-session.js by holding or executing the on app show 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 onAppShow() {
|
||||
if (!options) {
|
||||
return
|
||||
@@ -83,11 +139,19 @@ function onAppShow() {
|
||||
start()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: onAppHide supports idle-session.js by holding or executing the on app hide 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 onAppHide() {
|
||||
hiddenAt = Date.now()
|
||||
stop()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: check supports idle-session.js by holding or executing the check 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 check() {
|
||||
if (!options || !isLoggedIn() || loggingOut) {
|
||||
return
|
||||
@@ -102,6 +166,10 @@ function check() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: showWarning supports idle-session.js by holding or executing the show warning 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 showWarning() {
|
||||
if (!options || warningShown || loggingOut) {
|
||||
return
|
||||
@@ -129,6 +197,10 @@ function showWarning() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: forceLogout supports idle-session.js by holding or executing the force logout 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 forceLogout() {
|
||||
if (!options || loggingOut) {
|
||||
return
|
||||
@@ -145,6 +217,10 @@ function forceLogout() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: init supports idle-session.js by holding or executing the init 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 init(nextOptions) {
|
||||
options = nextOptions || null
|
||||
lastActiveAt = Date.now()
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
/**
|
||||
* Purpose: DEFAULT_CURSOR_SPACING supports keyboard-safe.js by holding or executing the default cursor spacing 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 DEFAULT_CURSOR_SPACING = 96
|
||||
/**
|
||||
* Purpose: DEFAULT_SPACER_EXTRA_RPX supports keyboard-safe.js by holding or executing the default spacer extra rpx 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 DEFAULT_SPACER_EXTRA_RPX = 48
|
||||
/**
|
||||
* Purpose: DEFAULT_SCROLL_DELAY supports keyboard-safe.js by holding or executing the default scroll delay 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 DEFAULT_SCROLL_DELAY = 32
|
||||
/**
|
||||
* Purpose: MAX_CURSOR_SPACING supports keyboard-safe.js by holding or executing the max cursor spacing 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 MAX_CURSOR_SPACING = 180
|
||||
|
||||
/**
|
||||
* Purpose: getWindowWidth supports keyboard-safe.js by holding or executing the get window width 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 getWindowWidth() {
|
||||
try {
|
||||
if (typeof wx.getWindowInfo === 'function') {
|
||||
@@ -18,10 +38,18 @@ function getWindowWidth() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: pxToRpx supports keyboard-safe.js by holding or executing the px to rpx 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 pxToRpx(px) {
|
||||
return Math.round((Number(px) || 0) * 750 / getWindowWidth())
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: createKeyboardSafeData supports keyboard-safe.js by holding or executing the create keyboard safe data 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 createKeyboardSafeData(options = {}) {
|
||||
const cursorSpacing = Number(options.cursorSpacing) > 0
|
||||
? Math.round(Number(options.cursorSpacing))
|
||||
@@ -36,6 +64,10 @@ function createKeyboardSafeData(options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearKeyboardTimers supports keyboard-safe.js by holding or executing the clear keyboard timers 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 clearKeyboardTimers(state) {
|
||||
if (!state) {
|
||||
return
|
||||
@@ -52,6 +84,10 @@ function clearKeyboardTimers(state) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: queueAnchorScroll supports keyboard-safe.js by holding or executing the queue anchor scroll 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 queueAnchorScroll(page, anchorId) {
|
||||
const state = page && page.__keyboardSafe
|
||||
if (!page || !state || !anchorId) {
|
||||
@@ -83,6 +119,10 @@ function queueAnchorScroll(page, anchorId) {
|
||||
state.anchorTimer = setTimeout(updateAnchor, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: attachKeyboardSafe supports keyboard-safe.js by holding or executing the attach keyboard safe 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 attachKeyboardSafe(page, options = {}) {
|
||||
if (!page) {
|
||||
return
|
||||
@@ -141,6 +181,10 @@ function attachKeyboardSafe(page, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: detachKeyboardSafe supports keyboard-safe.js by holding or executing the detach keyboard safe 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 detachKeyboardSafe(page) {
|
||||
if (!page || !page.__keyboardSafe) {
|
||||
return
|
||||
@@ -158,6 +202,10 @@ function detachKeyboardSafe(page) {
|
||||
delete page.__keyboardSafe
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleKeyboardFocus supports keyboard-safe.js by holding or executing the handle keyboard focus 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 handleKeyboardFocus(page, event) {
|
||||
const state = page && page.__keyboardSafe
|
||||
if (!page || !state) {
|
||||
@@ -191,6 +239,10 @@ function handleKeyboardFocus(page, event) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resetKeyboardSafe supports keyboard-safe.js by holding or executing the reset keyboard safe 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 resetKeyboardSafe(page, options = {}) {
|
||||
if (!page) {
|
||||
return
|
||||
@@ -215,6 +267,10 @@ function resetKeyboardSafe(page, options = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleKeyboardBlur supports keyboard-safe.js by holding or executing the handle keyboard blur 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 handleKeyboardBlur(page) {
|
||||
const state = page && page.__keyboardSafe
|
||||
if (!page || !state) {
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
/**
|
||||
* Purpose: activeLoadingCount supports loading.js by holding or executing the active loading count 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 activeLoadingCount = 0
|
||||
|
||||
/**
|
||||
* Purpose: showLoading supports loading.js by holding or executing the show loading 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 showLoading(options) {
|
||||
const config = options || {}
|
||||
activeLoadingCount += 1
|
||||
@@ -14,6 +22,10 @@ function showLoading(options) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hideLoading supports loading.js by holding or executing the hide loading 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 hideLoading() {
|
||||
activeLoadingCount = Math.max(0, activeLoadingCount - 1)
|
||||
|
||||
@@ -26,6 +38,10 @@ function hideLoading() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resetLoading supports loading.js by holding or executing the reset loading 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 resetLoading() {
|
||||
activeLoadingCount = 0
|
||||
wx.hideLoading({
|
||||
@@ -33,6 +49,10 @@ function resetLoading() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: runWithLoading supports loading.js by holding or executing the run with loading 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 runWithLoading(task, options) {
|
||||
showLoading(options)
|
||||
|
||||
|
||||
@@ -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 || {}
|
||||
|
||||
@@ -2,6 +2,10 @@ const { formatPrice, getProductTitle } = require('./format')
|
||||
const { resolveImageList } = require('./file')
|
||||
const { DEFAULT_PRODUCT_IMAGE } = require('./config')
|
||||
|
||||
/**
|
||||
* Purpose: getProductTags supports product.js by holding or executing the get product tags 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 getProductTags(product) {
|
||||
if (Array.isArray(product && product.tagInfos)) {
|
||||
return product.tagInfos
|
||||
@@ -13,6 +17,10 @@ function getProductTags(product) {
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildProductCard supports product.js by holding or executing the build product card 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.
|
||||
*/
|
||||
async function buildProductCard(product) {
|
||||
const images = await resolveImageList(product && product.imageFileIds, DEFAULT_PRODUCT_IMAGE)
|
||||
return {
|
||||
@@ -28,6 +36,10 @@ async function buildProductCard(product) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildProductCards supports product.js by holding or executing the build product cards 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.
|
||||
*/
|
||||
async function buildProductCards(products) {
|
||||
const list = Array.isArray(products) ? products : []
|
||||
return Promise.all(list.map(item => buildProductCard(item)))
|
||||
|
||||
@@ -1,21 +1,73 @@
|
||||
/**
|
||||
* Purpose: auth supports request.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')
|
||||
/**
|
||||
* Purpose: actionGuard supports request.js by holding or executing the action guard 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 actionGuard = require('./action-guard')
|
||||
/**
|
||||
* Purpose: idleSession supports request.js by holding or executing the idle session 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 idleSession = require('./idle-session')
|
||||
const { API_BASE_URL, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
|
||||
const { getDeviceId } = require('./device')
|
||||
const { sha256Hex, hmacSha256Hex, buildCanonicalParams, buildJsonPayload, randomNonce } = require('./crypto')
|
||||
|
||||
/**
|
||||
* Purpose: HEADER_TIMESTAMP supports request.js by holding or executing the header timestamp 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 HEADER_TIMESTAMP = 'X-Timestamp'
|
||||
/**
|
||||
* Purpose: HEADER_NONCE supports request.js by holding or executing the header nonce 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 HEADER_NONCE = 'X-Nonce'
|
||||
/**
|
||||
* Purpose: HEADER_SIGNATURE supports request.js by holding or executing the header signature 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 HEADER_SIGNATURE = 'X-Signature'
|
||||
/**
|
||||
* Purpose: HEADER_SIGNATURE_VERSION supports request.js by holding or executing the header signature version 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 HEADER_SIGNATURE_VERSION = 'X-Sign-Version'
|
||||
/**
|
||||
* Purpose: DEVICE_ID_HEADER supports request.js by holding or executing the device id header 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 DEVICE_ID_HEADER = 'X-Device-Id'
|
||||
|
||||
/**
|
||||
* Purpose: isRefreshing supports request.js by holding or executing the is refreshing 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 isRefreshing = false
|
||||
/**
|
||||
* Purpose: requestQueue supports request.js by holding or executing the request queue 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 requestQueue = []
|
||||
/**
|
||||
* Purpose: redirectingToAuth supports request.js by holding or executing the redirecting to auth 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 redirectingToAuth = false
|
||||
/**
|
||||
* Purpose: inflightRequests supports request.js by holding or executing the inflight requests 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 inflightRequests = {}
|
||||
|
||||
/**
|
||||
* Purpose: buildRequestUrl supports request.js by holding or executing the build request 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 buildRequestUrl(url, params) {
|
||||
const query = Object.keys(params || {})
|
||||
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
|
||||
@@ -26,6 +78,10 @@ function buildRequestUrl(url, params) {
|
||||
return query ? `${target}${target.includes('?') ? '&' : '?'}${query}` : target
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isWhitelistedPath supports request.js by holding or executing the is whitelisted 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 isWhitelistedPath(url) {
|
||||
return [
|
||||
'/user/login',
|
||||
@@ -48,6 +104,10 @@ function isWhitelistedPath(url) {
|
||||
].some(path => String(url || '').includes(path))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: normalizeError supports request.js by holding or executing the normalize error 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 normalizeError(message, statusCode, raw) {
|
||||
const error = new Error(message || '\u8bf7\u6c42\u5931\u8d25')
|
||||
error.statusCode = statusCode
|
||||
@@ -55,6 +115,10 @@ function normalizeError(message, statusCode, raw) {
|
||||
return error
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: rawRequest supports request.js by holding or executing the raw request 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 rawRequest(options) {
|
||||
idleSession.markActive()
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -66,6 +130,10 @@ function rawRequest(options) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: queueRequest supports request.js by holding or executing the queue request 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 queueRequest(retry) {
|
||||
return new Promise((resolve, reject) => {
|
||||
requestQueue.push({
|
||||
@@ -76,6 +144,10 @@ function queueRequest(retry) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: flushQueue supports request.js by holding or executing the flush queue 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 flushQueue(error) {
|
||||
const queue = requestQueue.slice()
|
||||
requestQueue = []
|
||||
@@ -89,6 +161,10 @@ function flushQueue(error) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: redirectToAuth supports request.js by holding or executing the redirect to 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 redirectToAuth() {
|
||||
if (redirectingToAuth) {
|
||||
return
|
||||
@@ -119,6 +195,10 @@ function redirectToAuth() {
|
||||
}, 300)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildSignatureHeaders supports request.js by holding or executing the build signature headers 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 buildSignatureHeaders(options) {
|
||||
const headers = {
|
||||
[DEVICE_ID_HEADER]: getDeviceId()
|
||||
@@ -156,6 +236,10 @@ function buildSignatureHeaders(options) {
|
||||
return headers
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: refreshToken supports request.js by holding or executing the refresh token 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.
|
||||
*/
|
||||
async function refreshToken() {
|
||||
const refreshTokenValue = auth.getRefreshToken()
|
||||
if (!refreshTokenValue) {
|
||||
@@ -191,6 +275,10 @@ async function refreshToken() {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: handleUnauthorized supports request.js by holding or executing the handle unauthorized 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.
|
||||
*/
|
||||
async function handleUnauthorized(options) {
|
||||
if (isWhitelistedPath(options.url)) {
|
||||
throw normalizeError('\u8bf7\u6c42\u9700\u8981\u767b\u5f55\uff0c\u4f46\u5f53\u524d\u9875\u9762\u5141\u8bb8\u533f\u540d\u67e5\u770b', 401)
|
||||
@@ -235,6 +323,10 @@ async function handleUnauthorized(options) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: unwrapResponse supports request.js by holding or executing the unwrap response 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.
|
||||
*/
|
||||
async function unwrapResponse(res, options) {
|
||||
idleSession.markActive()
|
||||
|
||||
@@ -261,6 +353,10 @@ async function unwrapResponse(res, options) {
|
||||
return payload
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildDedupeKey supports request.js by holding or executing the build dedupe key 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 buildDedupeKey(options, method) {
|
||||
if (options.skipDedupe) {
|
||||
return ''
|
||||
@@ -274,10 +370,18 @@ function buildDedupeKey(options, method) {
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isSafeMethod supports request.js by holding or executing the is safe method 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 isSafeMethod(method) {
|
||||
return ['GET', 'HEAD', 'OPTIONS'].includes(method)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildActionFingerprint supports request.js by holding or executing the build action fingerprint 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 buildActionFingerprint(options, method) {
|
||||
const paramsText = buildCanonicalParams(options.params)
|
||||
const payloadText = isSafeMethod(method) ? '' : buildJsonPayload(options.data)
|
||||
@@ -288,6 +392,10 @@ function buildActionFingerprint(options, method) {
|
||||
].join('\n'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveRepeatMessage supports request.js by holding or executing the resolve repeat message 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 resolveRepeatMessage(url) {
|
||||
const path = String(url || '')
|
||||
if (
|
||||
@@ -320,6 +428,10 @@ function resolveRepeatMessage(url) {
|
||||
return '\u64cd\u4f5c\u8fdb\u884c\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u70b9\u51fb'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildActionGuardConfig supports request.js by holding or executing the build action guard config 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 buildActionGuardConfig(options, method) {
|
||||
if (options.skipActionGuard || isSafeMethod(method)) {
|
||||
return null
|
||||
@@ -332,6 +444,10 @@ function buildActionGuardConfig(options, method) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: request supports request.js by holding or executing the request 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 request(options) {
|
||||
const method = String(options.method || 'GET').toUpperCase()
|
||||
const dedupeKey = buildDedupeKey(options, method)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: STORAGE_KEYS supports storage.js by holding or executing the storage keys 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 STORAGE_KEYS = {
|
||||
ACCESS_TOKEN: 'accessToken',
|
||||
REFRESH_TOKEN: 'refreshToken',
|
||||
@@ -7,6 +11,10 @@ const STORAGE_KEYS = {
|
||||
DEVICE_ID: 'miniDeviceId'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getStorage supports storage.js by holding or executing the get storage 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 getStorage(key, defaultValue) {
|
||||
try {
|
||||
const value = wx.getStorageSync(key)
|
||||
@@ -16,10 +24,18 @@ function getStorage(key, defaultValue) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setStorage supports storage.js by holding or executing the set storage 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 setStorage(key, value) {
|
||||
wx.setStorageSync(key, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeStorage supports storage.js by holding or executing the remove storage 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 removeStorage(key) {
|
||||
wx.removeStorageSync(key)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
/**
|
||||
* Purpose: HEX_COLOR_PATTERN supports theme.js by holding or executing the hex color pattern 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 HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/
|
||||
|
||||
/**
|
||||
* Purpose: normalizeHexColor supports theme.js by holding or executing the normalize hex color 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 normalizeHexColor(value) {
|
||||
if (!value || typeof value !== 'string') {
|
||||
return ''
|
||||
@@ -8,6 +16,10 @@ function normalizeHexColor(value) {
|
||||
return HEX_COLOR_PATTERN.test(normalized) ? normalized.toUpperCase() : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hexToRgb supports theme.js by holding or executing the hex to rgb 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 hexToRgb(color) {
|
||||
const value = color.replace('#', '')
|
||||
return {
|
||||
@@ -17,14 +29,26 @@ function hexToRgb(color) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: toHex supports theme.js by holding or executing the to hex 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 toHex(value) {
|
||||
return Math.min(255, Math.max(0, value)).toString(16).padStart(2, '0').toUpperCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: rgbToHex supports theme.js by holding or executing the rgb to hex 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 rgbToHex(rgb) {
|
||||
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: mixColor supports theme.js by holding or executing the mix color 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 mixColor(foreground, background, backgroundWeight) {
|
||||
const fg = hexToRgb(foreground)
|
||||
const bg = hexToRgb(background)
|
||||
@@ -36,6 +60,10 @@ function mixColor(foreground, background, backgroundWeight) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildStyleVars supports theme.js by holding or executing the build style vars 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 buildStyleVars(theme) {
|
||||
const styleVars = [
|
||||
`--theme-primary: ${theme.primaryColor};`,
|
||||
@@ -58,6 +86,10 @@ function buildStyleVars(theme) {
|
||||
return styleVars.join(' ')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveShopTheme supports theme.js by holding or executing the resolve shop theme 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 resolveShopTheme(source) {
|
||||
const themeSource = source || {}
|
||||
const normalizedPrimaryColor = normalizeHexColor(themeSource.themePrimaryColor)
|
||||
@@ -95,6 +127,10 @@ function resolveShopTheme(source) {
|
||||
return theme
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: DEFAULT_SHOP_THEME supports theme.js by holding or executing the default shop theme 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 DEFAULT_SHOP_THEME = {
|
||||
primaryColor: '#C6597D',
|
||||
secondaryColor: '#E9B7C7',
|
||||
@@ -111,6 +147,10 @@ const DEFAULT_SHOP_THEME = {
|
||||
|
||||
DEFAULT_SHOP_THEME.styleVars = buildStyleVars(DEFAULT_SHOP_THEME)
|
||||
|
||||
/**
|
||||
* Purpose: pageThemeData supports theme.js by holding or executing the page theme data 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 pageThemeData(theme, backgroundImageUrl) {
|
||||
const resolved = theme || DEFAULT_SHOP_THEME
|
||||
const themeData = backgroundImageUrl
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
/**
|
||||
* Purpose: assert supports theme.test.js by holding or executing the assert 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 assert = require('assert')
|
||||
/**
|
||||
* Purpose: theme supports theme.test.js by holding or executing the theme 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 theme = require('./theme')
|
||||
|
||||
/**
|
||||
* Purpose: customized supports theme.test.js by holding or executing the customized 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 customized = theme.resolveShopTheme({
|
||||
themePrimaryColor: '#8b4f65',
|
||||
themeSecondaryColor: '#f2c9d4',
|
||||
@@ -19,10 +31,18 @@ assert.strictEqual(customized.backgroundImageFileId, 'bg-file')
|
||||
assert.ok(customized.styleVars.includes('--theme-primary: #8B4F65;'))
|
||||
assert.ok(customized.styleVars.includes('--theme-gradient: linear-gradient(135deg, #8B4F65 0%, #F2C9D4 100%);'))
|
||||
|
||||
/**
|
||||
* Purpose: themedPageData supports theme.test.js by holding or executing the themed page data 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 themedPageData = theme.pageThemeData(customized, 'https://static.example.test/bg.jpg')
|
||||
assert.ok(themedPageData.themeVars.includes('background-image: url("https://static.example.test/bg.jpg");'))
|
||||
assert.strictEqual(themedPageData.theme.backgroundImageUrl, 'https://static.example.test/bg.jpg')
|
||||
|
||||
/**
|
||||
* Purpose: fallback supports theme.test.js by holding or executing the fallback 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 fallback = theme.resolveShopTheme({
|
||||
themePrimaryColor: '#fff',
|
||||
themeSecondaryColor: 'blue'
|
||||
|
||||
Reference in New Issue
Block a user