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',

View File

@@ -14,8 +14,6 @@ Page({
// 切换账号(开发)
showSwitchAccountModal: false,
// 调试环境:当前 API 环境标签
apiEnvLabel: '自动',
switchAccountUserId: '',
switchAccountLoading: false,
@@ -38,30 +36,17 @@ Page({
wx.showShareMenu({ withShareTimeline: true })
const accountInfo = wx.getAccountInfoSync ? wx.getAccountInfoSync() : null
const envVersion = accountInfo?.miniProgram?.envVersion || ''
const envInfo = app.getDebugEnvInfo()
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
isLoggedIn: app.globalData.isLoggedIn,
userInfo: app.globalData.userInfo,
isDevMode: envVersion === 'develop',
apiEnvLabel: envInfo.label
isDevMode: envVersion === 'develop'
})
this.loadBindingInfo()
},
onShow() {
this.loadBindingInfo()
if (this.data.isDevMode) {
const envInfo = getApp().getDebugEnvInfo()
this.setData({ apiEnvLabel: envInfo.label })
}
},
// 一键切换 API 环境(开发版)
switchApiEnv() {
const next = getApp().switchDebugEnv()
this.setData({ apiEnvLabel: next.label })
wx.showToast({ title: `已切到 ${next.label}`, icon: 'none' })
},
// 加载绑定信息

View File

@@ -109,15 +109,6 @@
<text class="tip-text">提示:绑定微信号才能使用提现功能</text>
</view>
<!-- 开发专用:切换 API 环境(仅开发版显示) -->
<view class="dev-switch-card" wx:if="{{isDevMode}}" bindtap="switchApiEnv">
<view class="dev-switch-inner">
<text class="dev-switch-icon">🌐</text>
<text class="dev-switch-text">切换环境</text>
<text class="dev-switch-desc">当前:{{apiEnvLabel}}(点击循环:自动→本地→测试→正式)</text>
</view>
</view>
<!-- 开发专用:切换账号(仅开发版显示) -->
<view class="dev-switch-card" wx:if="{{isDevMode}}" bindtap="openSwitchAccountModal">
<view class="dev-switch-inner">