| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /**
- * 应用全局配置
- *
- * 环境自动检测(基于微信小程序官方 API):
- * uni.getAccountInfoSync().miniProgram.envVersion
- * 'develop' → 开发版(工具内预览)
- * 'trial' → 体验版(上传到体验版)
- * 'release' → 正式版(线上发布)
- *
- * 无需手动修改任何变量,发布到对应环境自动生效。
- */
- let API_BASE_URL = 'https://cfc.etotem.com.cn'
- try {
- const accountInfo = uni.getAccountInfoSync()
- const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
- if (env) {
- switch (env) {
- case 'develop':
- //API_BASE_URL = 'http://cfc.iwintrue.com'
- //API_BASE_URL = 'http://192.168.1.57:9082'
- API_BASE_URL = 'https://cfc.etotem.com.cn'
- break
- case 'trial':
- API_BASE_URL = 'https://cfc.etotem.com.cn'
- break
- case 'release':
- API_BASE_URL = 'https://cfc.etotem.com.cn'
- break
- }
- }
- } catch (e) {
- // 非小程序环境(H5/dev):使用默认地址。
- // 关键:H5 页面部署在 cfc.iwintrue.com(HTTPS 反代),若 API_BASE_URL 指向 http:// 会触发
- // Mixed Content 被浏览器拦截;故 H5 下按页面当前协议自动选择(同源,避免跨域+CSP 问题)。
- try {
- if (typeof window !== 'undefined' && window.location && window.location.protocol) {
- const proto = window.location.protocol // 'https:' | 'http:'
- API_BASE_URL = proto + '//cfc.iwintrue.com'
- }
- } catch (e2) {
- // 保底:维持模块顶部默认值
- }
- }
- export default {
- API_BASE_URL,
- api(path) {
- return API_BASE_URL + path
- }
- }
|