重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
+163
View File
@@ -0,0 +1,163 @@
/**
* 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)
} catch (error) {
return {}
}
}
/**
* 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'
}
try {
if (typeof wx.getAccountInfoSync === 'function') {
const accountInfo = wx.getAccountInfoSync()
const miniProgram = accountInfo && accountInfo.miniProgram
if (miniProgram && miniProgram.envVersion) {
return miniProgram.envVersion
}
}
} catch (error) {}
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'
}
try {
const systemInfo = wx.getSystemInfoSync()
if (systemInfo && systemInfo.platform) {
return systemInfo.platform
}
} catch (error) {}
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}`)
}
if (envVersion !== 'develop' && !value.startsWith('https://')) {
throw new Error(`${envVersion} environment must use HTTPS`)
}
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',
'dev-remote': 'https://yunail.art',
trial: 'https://yunail.art',
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'])
: normalizeDomain(DOMAIN_MAP[ENV_VERSION], DOMAIN_MAP.release),
ENV_VERSION
)
module.exports = {
ENV_VERSION,
RUNTIME_PLATFORM,
IS_DEVTOOLS,
DEVELOP_TARGET,
API_DOMAIN,
ADMIN_API_BASE_URL: `${API_DOMAIN}/admin/api`,
IS_DEV_ENV: ENV_VERSION === 'develop',
REQUEST_TIMEOUT: Number(localOverride.requestTimeout || 10000),
ENABLE_REQUEST_SIGNING: localOverride.enableRequestSigning !== false,
IDLE_TIMEOUT_MS: 30 * 60 * 1000,
IDLE_WARNING_MS: 2 * 60 * 1000,
CACHE_TTL: {
permissions: 2 * 60 * 1000,
dict: 5 * 60 * 1000,
workbench: 60 * 1000
},
TAB_PAGES: [
'/admin/pages/workbench/index',
'/admin/pages/orders/index',
'/admin/pages/manage/index',
'/admin/pages/profile/index'
]
}