功能:同步小程序流程
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,29 +1,57 @@
|
||||
const { STORAGE_KEYS, getStorage, removeStorage, setStorage } = require('./storage')
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return getStorage(STORAGE_KEYS.USER_INFO, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getStoredPermissions supports auth.js by holding or executing the get stored permissions 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 getStoredPermissions() {
|
||||
return getStorage(STORAGE_KEYS.PERMISSIONS, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCurrentShop supports auth.js by holding or executing the get current shop 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 getCurrentShop() {
|
||||
return getStorage(STORAGE_KEYS.CURRENT_SHOP, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -46,6 +74,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)
|
||||
@@ -55,14 +87,26 @@ function updateStoredUserInfo(userInfo) {
|
||||
setStorage(STORAGE_KEYS.USER_INFO, userInfo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setPermissions supports auth.js by holding or executing the set permissions 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 setPermissions(permissions) {
|
||||
setStorage(STORAGE_KEYS.PERMISSIONS, Array.isArray(permissions) ? permissions : [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearPermissions supports auth.js by holding or executing the clear permissions 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 clearPermissions() {
|
||||
removeStorage(STORAGE_KEYS.PERMISSIONS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setCurrentShop supports auth.js by holding or executing the set current shop 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 setCurrentShop(shop) {
|
||||
if (!shop || !shop.id) {
|
||||
removeStorage(STORAGE_KEYS.CURRENT_SHOP)
|
||||
@@ -75,6 +119,10 @@ function setCurrentShop(shop) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
|
||||
@@ -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 = 'adminMiniCache:'
|
||||
/**
|
||||
* 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: 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: 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: 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
|
||||
@@ -33,6 +57,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
|
||||
@@ -48,6 +76,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
|
||||
@@ -58,6 +90,10 @@ function removeCache(key) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'
|
||||
@@ -24,6 +32,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'
|
||||
@@ -39,11 +51,19 @@ 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()
|
||||
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}`)
|
||||
@@ -54,11 +74,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',
|
||||
@@ -67,13 +107,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 `admin-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,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 = 'adminMiniDraft:'
|
||||
|
||||
/**
|
||||
* 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: 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) {
|
||||
if (!key) {
|
||||
return defaultValue
|
||||
@@ -19,6 +31,10 @@ function getDraftValue(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
|
||||
@@ -31,6 +47,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
|
||||
@@ -40,6 +60,10 @@ function clearDraft(key) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -52,6 +76,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: toIdString supports format.js by holding or executing the to id string 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 toIdString(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 toIdString(left) === toIdString(right)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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: 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: 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 ''
|
||||
@@ -25,10 +45,18 @@ function formatDateTime(value) {
|
||||
return String(value).replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: formatDate supports format.js by holding or executing the format date 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 formatDate(value) {
|
||||
return formatDateTime(value).slice(0, 10)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: maskPhone supports format.js by holding or executing the mask phone 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 maskPhone(phone) {
|
||||
const value = String(phone || '')
|
||||
if (value.length !== 11) {
|
||||
@@ -37,6 +65,10 @@ function maskPhone(phone) {
|
||||
return `${value.slice(0, 3)}****${value.slice(7)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: truncateText supports format.js by holding or executing the truncate 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 truncateText(value, limit) {
|
||||
const text = String(value || '')
|
||||
if (!limit || text.length <= limit) {
|
||||
@@ -45,6 +77,10 @@ function truncateText(value, limit) {
|
||||
return `${text.slice(0, limit)}...`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildShopName supports format.js by holding or executing the build shop name 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 buildShopName(record) {
|
||||
if (!record) {
|
||||
return '未绑定店铺'
|
||||
@@ -61,10 +97,18 @@ function buildShopName(record) {
|
||||
return '未绑定店铺'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getUserStatusText supports format.js by holding or executing the get user 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 getUserStatusText(status) {
|
||||
return Number(status) === 0 ? '已停用' : '正常'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getUserTypeText supports format.js by holding or executing the get user type 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 getUserTypeText(type) {
|
||||
const value = Number(type)
|
||||
if (value === 4) {
|
||||
@@ -79,6 +123,10 @@ function getUserTypeText(type) {
|
||||
return '普通用户'
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -94,10 +142,18 @@ function getOrderStatusText(order) {
|
||||
return '已取消'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCouponTypeText supports format.js by holding or executing the get coupon type 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 getCouponTypeText(type) {
|
||||
return Number(type) === 1 ? '折扣券' : '满减券'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCouponValueText supports format.js by holding or executing the get coupon value 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 getCouponValueText(coupon) {
|
||||
if (Number(coupon && coupon.couponType) === 1) {
|
||||
return `${coupon && coupon.discountValue ? coupon.discountValue : '--'} 折`
|
||||
@@ -105,6 +161,10 @@ function getCouponValueText(coupon) {
|
||||
return `满 ${formatPrice(coupon && coupon.minAmount)} 减 ${formatPrice(coupon && coupon.reduceAmount)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: parseDateTimeToPicker supports format.js by holding or executing the parse date time to picker 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 parseDateTimeToPicker(value) {
|
||||
const text = formatDateTime(value)
|
||||
if (!text) {
|
||||
@@ -121,6 +181,10 @@ function parseDateTimeToPicker(value) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildDateTime supports format.js by holding or executing the build 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 buildDateTime(date, time) {
|
||||
if (!date || !time) {
|
||||
return ''
|
||||
|
||||
@@ -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,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,6 +1,14 @@
|
||||
/**
|
||||
* Purpose: auth supports navigation.js by holding or executing the auth page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const auth = require('./auth')
|
||||
const { TAB_PAGES } = require('./config')
|
||||
|
||||
/**
|
||||
* Purpose: buildUrl supports navigation.js by holding or executing the build url page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildUrl(path, params) {
|
||||
const query = Object.keys(params || {})
|
||||
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
|
||||
@@ -10,6 +18,10 @@ function buildUrl(path, params) {
|
||||
return query ? `${path}?${query}` : path
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCurrentPageUrl supports navigation.js by holding or executing the get current page url page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getCurrentPageUrl() {
|
||||
const pages = getCurrentPages()
|
||||
const current = pages[pages.length - 1]
|
||||
@@ -20,11 +32,19 @@ function getCurrentPageUrl() {
|
||||
return buildUrl(`/${current.route}`, current.options || {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isTabPage supports navigation.js by holding or executing the is tab page page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function isTabPage(path) {
|
||||
const purePath = String(path || '').split('?')[0]
|
||||
return TAB_PAGES.includes(purePath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: navigate supports navigation.js by holding or executing the navigate page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function navigate(path, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.navigateTo({
|
||||
@@ -35,6 +55,10 @@ function navigate(path, params) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: redirect supports navigation.js by holding or executing the redirect page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function redirect(path, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.redirectTo({
|
||||
@@ -45,6 +69,10 @@ function redirect(path, params) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: switchTab supports navigation.js by holding or executing the switch tab page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function switchTab(path) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.switchTab({
|
||||
@@ -55,6 +83,10 @@ function switchTab(path) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: goBack supports navigation.js by holding or executing the go back page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function goBack(fallbackPath) {
|
||||
const pages = getCurrentPages()
|
||||
if (pages.length > 1) {
|
||||
@@ -71,6 +103,10 @@ function goBack(fallbackPath) {
|
||||
wx.redirectTo({ url: target })
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: decodeRedirectValue supports navigation.js by holding or executing the decode redirect value page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function decodeRedirectValue(value) {
|
||||
let current = String(value || '')
|
||||
|
||||
@@ -89,6 +125,10 @@ function decodeRedirectValue(value) {
|
||||
return current
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: redirectAfterLogin supports navigation.js by holding or executing the redirect after login page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function redirectAfterLogin(redirectValue) {
|
||||
const target = redirectValue ? decodeRedirectValue(redirectValue) : ''
|
||||
if (!target) {
|
||||
@@ -109,12 +149,20 @@ function redirectAfterLogin(redirectValue) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: openLogin supports navigation.js by holding or executing the open login page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function openLogin(redirectPath) {
|
||||
return navigate('/pages/login/index', {
|
||||
redirect: redirectPath || getCurrentPageUrl()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: ensureLogin supports navigation.js by holding or executing the ensure login page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function ensureLogin(actionText) {
|
||||
if (auth.isLoggedIn()) {
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
/**
|
||||
* Purpose: ensureStore supports page-state.js by holding or executing the ensure store 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 ensureStore() {
|
||||
const app = getApp()
|
||||
app.globalData.pageDirtyFlags = app.globalData.pageDirtyFlags || {}
|
||||
return app.globalData.pageDirtyFlags
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: markDirty supports page-state.js by holding or executing the mark dirty 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 markDirty(key) {
|
||||
if (!key) {
|
||||
return
|
||||
@@ -12,6 +20,10 @@ function markDirty(key) {
|
||||
store[key] = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: consumeDirty supports page-state.js by holding or executing the consume dirty 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 consumeDirty(key) {
|
||||
if (!key) {
|
||||
return false
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Purpose: MANAGE_MODULES supports permission.js by holding or executing the manage modules 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 MANAGE_MODULES = [
|
||||
{
|
||||
key: 'users',
|
||||
@@ -62,9 +66,29 @@ const MANAGE_MODULES = [
|
||||
path: '/pages/permissions/index',
|
||||
permissionCodes: ['permission:view'],
|
||||
requiresShopContext: false
|
||||
},
|
||||
{
|
||||
key: 'systemMessages',
|
||||
title: '系统消息',
|
||||
description: '发布消息、查看弹窗配置和业务跳转信息',
|
||||
path: '/pages/system-messages/index',
|
||||
permissionCodes: ['message:view'],
|
||||
requiresShopContext: false
|
||||
},
|
||||
{
|
||||
key: 'securityAudit',
|
||||
title: '审计日志',
|
||||
description: '查看高危操作的成功、失败原因与操作者',
|
||||
path: '/pages/security-audit/index',
|
||||
permissionCodes: ['security:audit:view'],
|
||||
requiresShopContext: false
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* Purpose: getPermissionCodes supports permission.js by holding or executing the get permission codes 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 getPermissionCodes(source) {
|
||||
const list = Array.isArray(source) ? source : []
|
||||
|
||||
@@ -78,6 +102,10 @@ function getPermissionCodes(source) {
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hasPermission supports permission.js by holding or executing the has permission 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 hasPermission(source, permissionCode) {
|
||||
if (!permissionCode) {
|
||||
return true
|
||||
@@ -87,6 +115,10 @@ function hasPermission(source, permissionCode) {
|
||||
return codes.includes(permissionCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hasAnyPermission supports permission.js by holding or executing the has any permission 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 hasAnyPermission(source, permissionCodes) {
|
||||
const codes = Array.isArray(permissionCodes) ? permissionCodes : []
|
||||
if (!codes.length) {
|
||||
@@ -96,6 +128,10 @@ function hasAnyPermission(source, permissionCodes) {
|
||||
return codes.some(code => hasPermission(source, code))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: hasAllPermissions supports permission.js by holding or executing the has all permissions 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 hasAllPermissions(source, permissionCodes) {
|
||||
const codes = Array.isArray(permissionCodes) ? permissionCodes : []
|
||||
if (!codes.length) {
|
||||
@@ -105,18 +141,34 @@ function hasAllPermissions(source, permissionCodes) {
|
||||
return codes.every(code => hasPermission(source, code))
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isPlatformAdmin supports permission.js by holding or executing the is platform admin 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 isPlatformAdmin(userInfo) {
|
||||
return Number(userInfo && userInfo.type) === 4
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isShopManager supports permission.js by holding or executing the is shop manager 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 isShopManager(userInfo) {
|
||||
return Number(userInfo && userInfo.type) === 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isNailArtist supports permission.js by holding or executing the is nail artist 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 isNailArtist(userInfo) {
|
||||
return Number(userInfo && userInfo.type) === 3
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getRoleLabel supports permission.js by holding or executing the get role label 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 getRoleLabel(type) {
|
||||
const value = Number(type)
|
||||
if (value === 4) {
|
||||
@@ -131,6 +183,10 @@ function getRoleLabel(type) {
|
||||
return '用户'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: groupPermissionsByGroup supports permission.js by holding or executing the group permissions by group 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 groupPermissionsByGroup(permissions) {
|
||||
return (Array.isArray(permissions) ? permissions : []).reduce((result, item) => {
|
||||
const group = item && item.permissionGroup ? item.permissionGroup : '未分组'
|
||||
@@ -142,6 +198,10 @@ function groupPermissionsByGroup(permissions) {
|
||||
}, {})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: checkModuleAccess supports permission.js by holding or executing the check module access 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 checkModuleAccess(module, userInfo, permissionCodes, currentShop) {
|
||||
if (!hasAnyPermission(permissionCodes, module.permissionCodes)) {
|
||||
return {
|
||||
@@ -171,6 +231,10 @@ function checkModuleAccess(module, userInfo, permissionCodes, currentShop) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getManageModules supports permission.js by holding or executing the get manage modules 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 getManageModules(userInfo, permissionCodes, currentShop) {
|
||||
return MANAGE_MODULES.map(module => {
|
||||
const access = checkModuleAccess(module, userInfo, permissionCodes, currentShop)
|
||||
|
||||
@@ -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 { ADMIN_API_BASE_URL, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
|
||||
const { getDeviceId } = require('./device')
|
||||
const { sha256Hex, hmacSha256Hex, buildCanonicalParams, buildJsonPayload, randomNonce } = require('./crypto')
|
||||
|
||||
/**
|
||||
* 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: 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: 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: redirectingToLogin supports request.js by holding or executing the redirecting to login 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 redirectingToLogin = 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: extractPath supports request.js by holding or executing the extract 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 extractPath(value) {
|
||||
const target = String(value || '')
|
||||
if (!target) {
|
||||
@@ -39,6 +95,10 @@ function extractPath(value) {
|
||||
return target.split('?')[0] || ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: toBackendRequestPath supports request.js by holding or executing the to backend request 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 toBackendRequestPath(url) {
|
||||
const path = extractPath(url).replace(/\/+$/, '') || '/'
|
||||
if (path === '/admin/api') {
|
||||
@@ -59,6 +119,10 @@ function toBackendRequestPath(url) {
|
||||
return path.startsWith('/') ? `/admin${path}` : `/admin/${path}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isAuthFreePath supports request.js by holding or executing the is auth free 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 isAuthFreePath(url) {
|
||||
return [
|
||||
'/auth/login',
|
||||
@@ -67,6 +131,10 @@ function isAuthFreePath(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
|
||||
@@ -74,6 +142,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) => {
|
||||
@@ -85,6 +157,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({
|
||||
@@ -95,6 +171,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 = []
|
||||
@@ -108,6 +188,10 @@ function flushQueue(error) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: redirectToLogin supports request.js by holding or executing the redirect to 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 redirectToLogin() {
|
||||
if (redirectingToLogin) {
|
||||
return
|
||||
@@ -143,6 +227,10 @@ function redirectToLogin() {
|
||||
}, 240)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
@@ -180,6 +268,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) {
|
||||
@@ -215,6 +307,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 (options._retry || isAuthFreePath(options.url)) {
|
||||
const app = getApp()
|
||||
@@ -257,6 +353,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(response, options) {
|
||||
idleSession.markActive()
|
||||
|
||||
@@ -291,6 +391,10 @@ async function unwrapResponse(response, 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 ''
|
||||
@@ -304,10 +408,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)
|
||||
@@ -318,6 +430,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 (path.includes('/auth/login')) {
|
||||
@@ -353,6 +469,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
|
||||
@@ -365,6 +485,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: 'adminAccessToken',
|
||||
REFRESH_TOKEN: 'adminRefreshToken',
|
||||
@@ -7,8 +11,16 @@ const STORAGE_KEYS = {
|
||||
DEVICE_ID: 'adminMiniDeviceId'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: TEMP_RECORD_PREFIX supports storage.js by holding or executing the temp record 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 TEMP_RECORD_PREFIX = 'adminTempRecord:'
|
||||
|
||||
/**
|
||||
* 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)
|
||||
@@ -18,22 +30,42 @@ 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)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setTempRecord supports storage.js by holding or executing the set temp record 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 setTempRecord(name, value) {
|
||||
setStorage(`${TEMP_RECORD_PREFIX}${name}`, value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getTempRecord supports storage.js by holding or executing the get temp record 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 getTempRecord(name, defaultValue) {
|
||||
return getStorage(`${TEMP_RECORD_PREFIX}${name}`, defaultValue)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearTempRecord supports storage.js by holding or executing the clear temp record 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 clearTempRecord(name) {
|
||||
removeStorage(`${TEMP_RECORD_PREFIX}${name}`)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/**
|
||||
* Purpose: fileApi supports upload.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')
|
||||
|
||||
/**
|
||||
* Purpose: getFileSystemManager supports upload.js by holding or executing the get file system manager 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 getFileSystemManager() {
|
||||
return wx.getFileSystemManager()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getFileInfo supports upload.js by holding or executing the get file 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 getFileInfo(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.getFileInfo({
|
||||
@@ -14,6 +26,10 @@ function getFileInfo(filePath) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: readFileBuffer supports upload.js by holding or executing the read file buffer 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 readFileBuffer(filePath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getFileSystemManager().readFile({
|
||||
@@ -24,6 +40,10 @@ function readFileBuffer(filePath) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: writeChunkFile supports upload.js by holding or executing the write chunk file 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 writeChunkFile(filePath, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getFileSystemManager().writeFile({
|
||||
@@ -36,6 +56,10 @@ function writeChunkFile(filePath, data) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeFile supports upload.js by holding or executing the remove file 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 removeFile(filePath) {
|
||||
return new Promise(resolve => {
|
||||
getFileSystemManager().unlink({
|
||||
@@ -46,6 +70,10 @@ function removeFile(filePath) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: normalizeSelectedFiles supports upload.js by holding or executing the normalize selected files 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 normalizeSelectedFiles(files) {
|
||||
return (Array.isArray(files) ? files : []).map((item, index) => {
|
||||
if (typeof item === 'string') {
|
||||
@@ -62,6 +90,10 @@ function normalizeSelectedFiles(files) {
|
||||
}).filter(item => item.tempFilePath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: createFingerprint supports upload.js by holding or executing the create 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 createFingerprint(seed) {
|
||||
let hash = 0
|
||||
const text = String(seed || '')
|
||||
@@ -74,6 +106,10 @@ function createFingerprint(seed) {
|
||||
return `mini-${Math.abs(hash)}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: resolveContentType supports upload.js by holding or executing the resolve content type 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 resolveContentType(fileName) {
|
||||
const value = String(fileName || '').toLowerCase()
|
||||
if (value.endsWith('.png')) {
|
||||
@@ -88,6 +124,10 @@ function resolveContentType(fileName) {
|
||||
return 'image/jpeg'
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: uploadSingleFile supports upload.js by holding or executing the upload single file 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 uploadSingleFile(file, scene, onProgress) {
|
||||
const fileInfo = await getFileInfo(file.tempFilePath)
|
||||
const buffer = await readFileBuffer(file.tempFilePath)
|
||||
@@ -155,6 +195,10 @@ async function uploadSingleFile(file, scene, onProgress) {
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: uploadImageFiles supports upload.js by holding or executing the upload image files 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 uploadImageFiles(options) {
|
||||
const files = normalizeSelectedFiles(options && options.files)
|
||||
const scene = options && options.scene ? options.scene : 'admin-product-image'
|
||||
@@ -176,6 +220,10 @@ async function uploadImageFiles(options) {
|
||||
return results
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: chooseImageFiles supports upload.js by holding or executing the choose image files 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 chooseImageFiles(options) {
|
||||
const config = options || {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user