Pārlūkot izejas kodu

chore: restore config.js to version control

openhands 1 mēnesi atpakaļ
vecāks
revīzija
7df65620e8
2 mainītis faili ar 43 papildinājumiem un 1 dzēšanām
  1. 0 1
      .gitignore
  2. 43 0
      cfc-frontend/config.js

+ 0 - 1
.gitignore

@@ -24,7 +24,6 @@ Thumbs.db
 .env.local
 .env.*.local
 .env.production
-cfc-frontend/config.js
 
 # Test artifacts
 .playwright-mcp/

+ 43 - 0
cfc-frontend/config.js

@@ -0,0 +1,43 @@
+/**
+ * 应用全局配置
+ *
+ * 环境自动检测(基于微信小程序官方 API):
+ *   uni.getAccountInfoSync().miniProgram.envVersion
+ *     'develop'  → 开发版(工具内预览)
+ *     'trial'    → 体验版(上传到体验版)
+ *     'release'  → 正式版(线上发布)
+ *
+ * 无需手动修改任何变量,发布到对应环境自动生效。
+ */
+
+let API_BASE_URL = 'http://cfc.iwintrue.com'
+
+try {
+  const accountInfo = uni.getAccountInfoSync()
+  const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
+
+  if (env) {
+    switch (env) {
+      case 'develop':
+        API_BASE_URL = 'http://cfc.etotem.com.cn'
+        break
+      case 'trial':
+        API_BASE_URL = 'https://cfc.iwintrue.com'
+        break
+      case 'release':
+        API_BASE_URL = 'https://cfc.etotem.com.cn'
+        break
+    }
+  }
+} catch (e) {
+  // 非小程序环境(H5/dev),使用默认地址
+}
+
+export default {
+  API_BASE_URL,
+
+  /** 构建 API 完整 URL */
+  api(path) {
+    return API_BASE_URL + path
+  }
+}