Refactor mini program environment configuration and remove deprecated debug features

- Simplified the environment configuration in app.js by removing the debug environment options and related functions.
- Set a default API base URL for production while allowing commented options for local and testing environments.
- Cleaned up settings.js by removing the debug environment label and switching functionality, streamlining the user interface.
- Updated documentation to reflect the removal of debug features and added a summary of synchronization requirements in the planning document.
This commit is contained in:
Alex-larget
2026-03-16 13:30:05 +08:00
parent 0e7b81eaa8
commit e75092eaad
15 changed files with 915 additions and 209 deletions

View File

@@ -5,42 +5,12 @@
const { parseScene } = require('./utils/scene.js')
// 调试环境配置:''=自动 | localhost | souldev | soulapi
const DEBUG_ENV_OPTIONS = [
{ key: '', label: '自动', url: null },
{ key: 'localhost', label: '本地', url: 'http://localhost:8080' },
{ key: 'souldev', label: '测试', url: 'https://souldev.quwanzhi.com' },
{ key: 'soulapi', label: '正式', url: 'https://soulapi.quwanzhi.com' }
]
const STORAGE_KEY_DEBUG_ENV = 'debug_env_override'
// 根据小程序环境版本或调试覆盖选择 API 地址
function getBaseUrlByEnv(override) {
if (override) {
const opt = DEBUG_ENV_OPTIONS.find(o => o.key === override)
if (opt && opt.url) return opt.url
}
try {
const accountInfo = wx.getAccountInfoSync()
const env = accountInfo?.miniProgram?.envVersion || 'release'
const urls = {
develop: 'http://localhost:8080', // 开发版(本地调试)
trial: 'https://souldev.quwanzhi.com', // 体验版
release: 'https://soulapi.quwanzhi.com' // 正式版
}
return urls[env] || urls.release
} catch (e) {
console.warn('[App] 获取环境失败,使用正式版:', e)
return 'https://soulapi.quwanzhi.com'
}
}
App({
globalData: {
// API基础地址 - 由 getBaseUrlByEnv() 在 onLaunch 时按环境自动设置
baseUrl: '',
// 调试环境覆盖:'' | localhost | souldev | soulapi持久化到 storage
debugEnvOverride: '',
// API 基础地址(切换环境时注释/取消注释)
baseUrl: 'https://soulapi.quwanzhi.com',
// baseUrl: 'http://localhost:8080', // 本地调试
// baseUrl: 'https://souldev.quwanzhi.com', // 测试环境
// 小程序配置 - 真实AppID
@@ -100,8 +70,8 @@ App({
},
onLaunch(options) {
this.globalData.debugEnvOverride = wx.getStorageSync(STORAGE_KEY_DEBUG_ENV) || ''
this.globalData.baseUrl = getBaseUrlByEnv(this.globalData.debugEnvOverride)
// 清理已废弃的调试环境 storage取消环境切换后不再使用
try { wx.removeStorageSync('debug_env_override') } catch (_) {}
this.globalData.readSectionIds = wx.getStorageSync('readSectionIds') || []
// 获取系统信息
this.getSystemInfo()
@@ -280,28 +250,6 @@ App({
return ''
},
// 调试:获取当前 API 环境信息
getDebugEnvInfo() {
const override = this.globalData.debugEnvOverride || ''
const opt = DEBUG_ENV_OPTIONS.find(o => o.key === override)
return {
override,
label: opt ? opt.label : '自动',
baseUrl: this.globalData.baseUrl
}
},
// 调试:一键切换 API 环境(自动→本地→测试→正式→自动),持久化到 storage
switchDebugEnv() {
const idx = DEBUG_ENV_OPTIONS.findIndex(o => o.key === this.globalData.debugEnvOverride)
const nextIdx = (idx + 1) % DEBUG_ENV_OPTIONS.length
const next = DEBUG_ENV_OPTIONS[nextIdx]
this.globalData.debugEnvOverride = next.key
this.globalData.baseUrl = getBaseUrlByEnv(next.key)
wx.setStorageSync(STORAGE_KEY_DEBUG_ENV, next.key)
return next
},
/**
* 自定义导航栏「返回」:有上一页则返回,否则跳转首页(解决从分享进入时点返回无效的问题)
*/
@@ -480,7 +428,6 @@ App({
return new Promise((resolve, reject) => {
const token = wx.getStorageSync('token')
wx.request({
url: this.globalData.baseUrl + url,
method: options.method || 'GET',