Files
JayuCloud/WeChatProgram/utils/config.js
T

80 lines
2.0 KiB
JavaScript
Raw Normal View History

2026-04-01 15:18:35 +08:00
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) {}
try {
if (typeof __wxConfig !== 'undefined' && __wxConfig && __wxConfig.envVersion) {
return __wxConfig.envVersion
}
} catch (error) {}
return 'develop'
}
function getRuntimePlatform() {
if (typeof wx === 'undefined') {
return 'devtools'
}
try {
if (typeof wx.getDeviceInfo === 'function') {
const deviceInfo = wx.getDeviceInfo()
if (deviceInfo && deviceInfo.platform) {
return deviceInfo.platform
}
}
} catch (error) {}
try {
if (typeof wx.getSystemInfoSync === 'function') {
const systemInfo = wx.getSystemInfoSync()
if (systemInfo && systemInfo.platform) {
return systemInfo.platform
}
}
} catch (error) {}
return 'unknown'
}
const ENV_VERSION = getEnvVersion()
const RUNTIME_PLATFORM = getRuntimePlatform()
const IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools'
const LOCAL_API_DOMAIN = 'http://127.0.0.1:80'
const REMOTE_API_DOMAIN = 'https://yunail.art'
const USE_LOCAL_API = ENV_VERSION === 'develop' && IS_DEVTOOLS
const API_DOMAIN = USE_LOCAL_API ? LOCAL_API_DOMAIN : REMOTE_API_DOMAIN
module.exports = {
ENV_VERSION,
RUNTIME_PLATFORM,
IS_DEVTOOLS,
USE_LOCAL_API,
API_DOMAIN,
API_BASE_URL: `${API_DOMAIN}/api`,
IS_DEV_ENV: ENV_VERSION === 'develop',
REQUEST_TIMEOUT: 10000,
DEFAULT_AVATAR: 'https://api.dicebear.com/7.x/avataaars/svg?seed=default',
DEFAULT_PRODUCT_IMAGE: 'https://via.placeholder.com/200x200?text=Product',
DEFAULT_SHOP_IMAGE: 'https://via.placeholder.com/200x200?text=Shop',
NO_COUPON_KEY: 'NONE',
TAB_PAGES: [
'/pages/home/index',
'/pages/products/index',
'/pages/cart/index',
'/pages/profile/index'
]
}